Skip to content

Commit 22764f3

Browse files
meisterTnickygerritsen
authored andcommitted
Remove transaction from fetch work API.
We have seen the transaction to fail, resulting in exceptions/500s. There is also no need to have a transaction at all. We now do check after the update whether we won instead and if not, tell the judgehost to try again. (cherry picked from commit c06ee8a)
1 parent 116e9cf commit 22764f3

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,40 +1583,42 @@ public function getJudgeTasksAction(Request $request): array
15831583
// This is case 2.a) from above: start something new.
15841584
// This runs transactional to prevent a queue task being picked up twice.
15851585
$judgetasks = null;
1586-
$this->em->wrapInTransaction(function () use ($judgehost, $max_batchsize, &$judgetasks) {
1587-
$jobid = $this->em->createQueryBuilder()
1588-
->from(QueueTask::class, 'qt')
1589-
->innerJoin('qt.judging', 'j')
1590-
->select('j.judgingid')
1586+
$jobid = $this->em->createQueryBuilder()
1587+
->from(QueueTask::class, 'qt')
1588+
->innerJoin('qt.judging', 'j')
1589+
->select('j.judgingid')
1590+
->andWhere('qt.startTime IS NULL')
1591+
->addOrderBy('qt.priority')
1592+
->addOrderBy('qt.teamPriority')
1593+
->setMaxResults(1)
1594+
->getQuery()
1595+
->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
1596+
if ($jobid !== null) {
1597+
// Mark it as being worked on.
1598+
$result = $this->em->createQueryBuilder()
1599+
->update(QueueTask::class, 'qt')
1600+
->set('qt.startTime', Utils::now())
1601+
->andWhere('qt.judging = :jobid')
15911602
->andWhere('qt.startTime IS NULL')
1592-
->addOrderBy('qt.priority')
1593-
->addOrderBy('qt.teamPriority')
1594-
->setMaxResults(1)
1603+
->setParameter('jobid', $jobid)
15951604
->getQuery()
1596-
->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
1597-
if ($jobid === null) {
1598-
return;
1599-
}
1600-
$judgetasks = $this->getJudgetasks($jobid, $max_batchsize, $judgehost);
1601-
if (empty($judgetasks)) {
1602-
// Somehow we got ourselves in a situation that there was a queue task without remaining judge tasks.
1603-
// This should not happen, but if it does, we need to clean up. Each of the fetch-work calls will clean
1604-
// up one queue task. We need to signal to the judgehost that there might be more work to do.
1605+
->execute();
1606+
1607+
if ($result == 0) {
1608+
// Another judgehost beat us to it.
16051609
$judgetasks = [['type' => 'try_again']];
16061610
} else {
1607-
// Mark it as being worked on.
1608-
$this->em->createQueryBuilder()
1609-
->update(QueueTask::class, 'qt')
1610-
->set('qt.startTime', Utils::now())
1611-
->andWhere('qt.judging = :jobid')
1612-
->andWhere('qt.startTime IS NULL')
1613-
->setParameter('jobid', $jobid)
1614-
->getQuery()
1615-
->execute();
1611+
$judgetasks = $this->getJudgetasks($jobid, $max_batchsize, $judgehost);
1612+
if (empty($judgetasks)) {
1613+
// Somehow we got ourselves in a situation that there was a queue task without remaining judge tasks.
1614+
// This should not happen, but if it does, we need to clean up. Each of the fetch-work calls will clean
1615+
// up one queue task. We need to signal to the judgehost that there might be more work to do.
1616+
$judgetasks = [['type' => 'try_again']];
1617+
}
1618+
}
1619+
if (!empty($judgetasks)) {
1620+
return $judgetasks;
16161621
}
1617-
});
1618-
if (!empty($judgetasks)) {
1619-
return $judgetasks;
16201622
}
16211623

16221624
if ($this->config->get('enable_parallel_judging')) {

0 commit comments

Comments
 (0)