summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-04-07 22:18:40 +0200
committerGitHub <noreply@github.com>2017-04-07 22:18:40 +0200
commit6c0cafb10f401d2b1e65874a54cd9732122f083e (patch)
treefbfb537935781f1aa03783095490c7a5feb64eb1
parent8838ed4c2ea50e9205dd7b106bf6aeda9e0a1171 (diff)
parentc993c363e0d5c76793f7689a5b367f8ce7bf552e (diff)
downloadnextcloud-server-6c0cafb10f401d2b1e65874a54cd9732122f083e.tar.gz
nextcloud-server-6c0cafb10f401d2b1e65874a54cd9732122f083e.zip
Merge pull request #4253 from nextcloud/downstream-27599
make JobList::next() lock free
-rw-r--r--lib/private/BackgroundJob/JobList.php15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index b6a235e9e40..0de5dfecc8b 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -187,18 +187,24 @@ class JobList implements IJobList {
$update->update('jobs')
->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))
->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))
- ->where($update->expr()->eq('id', $update->createParameter('jobid')));
+ ->where($update->expr()->eq('id', $update->createParameter('jobid')))
+ ->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at')))
+ ->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked')));
- $this->connection->lockTable('jobs');
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
$update->setParameter('jobid', $row['id']);
- $update->execute();
- $this->connection->unlockTable();
+ $update->setParameter('reserved_at', $row['reserved_at']);
+ $update->setParameter('last_checked', $row['last_checked']);
+ $count = $update->execute();
+ if ($count === 0) {
+ // Background job already executed elsewhere, try again.
+ return $this->getNext();
+ }
$job = $this->buildJob($row);
if ($job === null) {
@@ -208,7 +214,6 @@ class JobList implements IJobList {
return $job;
} else {
- $this->connection->unlockTable();
return null;
}
}