Skip to content

Commit

Permalink
Store compiler/runner version history.
Browse files Browse the repository at this point in the history
Previously, we only stored the most recent one per language/judgehost
combination. This new format will allow us (in separate changes) to
cross-reference in judgings and warn if they have not been using the
canonical one.
  • Loading branch information
meisterT committed Nov 24, 2023
1 parent 4c1b87b commit b47a67f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 21 deletions.
36 changes: 36 additions & 0 deletions webapp/migrations/Version20231124122006.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231124122006 extends AbstractMigration
{
public function getDescription(): string
{
return 'Store a history of versions, instead of just the most recent one.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE version ADD active TINYINT(1) DEFAULT 1 NOT NULL COMMENT \'True if this version is active for this judgehost/language combination.\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE version DROP active');
}

public function isTransactional(): bool
{
return false;
}
}
48 changes: 28 additions & 20 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,36 +1286,44 @@ public function checkVersions(Request $request, string $judgetaskid): array
$reportedVersions,
$language
) {
$version = $this->em->getRepository(Version::class)
->findOneBy(['language' => $language, 'judgehost' => $judgehost]);
$activeVersion = $this->em->getRepository(Version::class)
->findOneBy(['language' => $language, 'judgehost' => $judgehost, 'active' => true]);

$newVersion = false;
if (!$version) {
if (!$activeVersion) {
$newVersion = true;
$version = new Version();
$version
->setLanguage($language)
->setJudgehost($judgehost);
$this->em->persist($version);
} else {
$reportedCompilerVersion = $reportedVersions['compiler'] ?? null;
if ($activeVersion->getCompilerVersion() !== $reportedCompilerVersion) {
$newVersion = true;
}
$reportedRunnerVersion = $reportedVersions['runner'] ?? null;
if ($activeVersion->getRunnerVersion() !== $reportedRunnerVersion) {
$newVersion = true;
}
}
if (isset($reportedVersions['compiler'])) {
if ($version->getCompilerVersion() !== $reportedVersions['compiler']) {
$version
if ($newVersion) {
if ($activeVersion) {
$activeVersion->setActive(false);
}
$activeVersion = new Version();
$activeVersion
->setLanguage($language)
->setJudgehost($judgehost)
->setActive(true)
;
if (isset($reportedVersions['compiler'])) {
$activeVersion
->setCompilerVersion($reportedVersions['compiler'])
->setCompilerVersionCommand($language->getCompilerVersionCommand());
$newVersion = true;
}
}
if (isset($reportedVersions['runner'])) {
if ($version->getRunnerVersion() !== $reportedVersions['runner']) {
$version
if (isset($reportedVersions['runner'])) {
$activeVersion
->setRunnerVersion($reportedVersions['runner'])
->setRunnerVersionCommand($language->getRunnerVersionCommand());
$newVersion = true;
}
}
if ($newVersion) {
$version->setLastChangedTime(Utils::now());
$activeVersion->setLastChangedTime(Utils::now());
$this->em->persist($activeVersion);
$this->em->flush();
}
// TODO: Optionally check version here against canonical version.
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/VersionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function indexAction(): Response
$languages = $this->em->createQueryBuilder()
->select('l', 'v', 'jh')
->from(Language::class, 'l')
->leftJoin('l.versions', 'v')
->leftJoin('l.versions', 'v', 'WITH', 'v.active = 1')
->leftJoin('v.judgehost', 'jh')
->andWhere('l.allowSubmit = 1')
->getQuery()->getResult();
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/Entity/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Version
#[Serializer\Exclude]
private string|float|null $lastChangedTime = null;

#[ORM\Column(options: [
'comment' => 'True if this version is active for this judgehost/language combination.',
'default' => 1,
])]
#[Serializer\Exclude]
private bool $active = true;

public function getVersionid(): ?int
{
return $this->versionid;
Expand Down Expand Up @@ -133,4 +140,15 @@ public function setLastChangedTime(float|string|null $lastChangedTime): Version
$this->lastChangedTime = $lastChangedTime;
return $this;
}

public function getActive(): bool
{
return $this->active;
}

public function setActive(bool $active): Version
{
$this->active = $active;
return $this;
}
}

0 comments on commit b47a67f

Please sign in to comment.