Skip to content

Removes unneeded transactions. #2909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,37 +910,22 @@ public function internalErrorAction(Request $request): ?int
*/
protected function giveBackJudging(int $judgingId, ?Judgehost $judgehost): void
{
// Reset the judgings without using Doctrine, it has no support for update queries containing a join.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctrine 🤯

// Both databases supported by DOMjudge (MariaDB, MySQL) support these types of queries.
$judging = $this->em->getRepository(Judging::class)->find($judgingId);
if ($judging) {
$this->em->wrapInTransaction(function () use ($judging, $judgehost) {
/** @var JudgingRun $run */
foreach ($judging->getRuns() as $run) {
if ($judgehost === null) {
// This is coming from internal errors, reset the whole judging.
$run->getJudgetask()
->setValid(false);
continue;
}

// We do not have to touch any finished runs
if ($run->getRunresult() !== null) {
continue;
}

// For the other runs, we need to reset the judge task if it belongs to the current judgehost.
if ($run->getJudgetask()->getJudgehost() && $run->getJudgetask()->getJudgehost()->getHostname() === $judgehost->getHostname()) {
$run->getJudgetask()
->setJudgehost(null)
->setStarttime(null);
}
}

$this->em->flush();
});

if ($judgehost === null) {
// Invalidate old judging and create a new one - but without judgetasks yet since this was triggered by
// an internal error.
$this->em->getConnection()->executeStatement(
'UPDATE judging_run jr ' .
'JOIN judgetask jt ON jt.judgetaskid = jr.judgetaskid ' .
'SET jt.valid = 0 ' .
'WHERE jr.judgingid = :judgingid',
[
'judgingid' => $judgingId,
]);

$judging->setValid(false);
$newJudging = new Judging();
$newJudging
Expand All @@ -950,6 +935,19 @@ protected function giveBackJudging(int $judgingId, ?Judgehost $judgehost): void
->setOriginalJudging($judging);
$this->em->persist($newJudging);
$this->em->flush();
} else {
// Hand back the non-completed work of this judgehost within this judgetask.
$this->em->getConnection()->executeStatement(
'UPDATE judging_run jr ' .
'JOIN judgetask jt ON jt.judgetaskid = jr.judgetaskid ' .
'SET jt.judgehostid = null, jt.starttime = null ' .
'WHERE jr.judgingid = :judgingid ' .
' AND jr.runresult IS NOT NULL ' .
' AND jt.judgehostid = :judgehost',
[
'judgingid' => $judgingId,
'judgehost' => $judgehost->getJudgehostid(),
]);
}

$this->dj->auditlog('judging', $judgingId, 'given back'
Expand Down
Loading