mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
fix(propagator): Lock rows also in propagateChange
Signed-off-by: Carl Schwan <carlschwan@kde.org>
(cherry picked from commit 3d031b03f3)
This commit is contained in:
parent
536c5a0d91
commit
7aaba8a931
1 changed files with 21 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ namespace OC\Files\Cache;
|
|||
|
||||
use OC\DB\Exceptions\DbalException;
|
||||
use OC\Files\Storage\Wrapper\Encryption;
|
||||
use OCP\DB\QueryBuilder\ILiteral;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Files\Cache\IPropagator;
|
||||
use OCP\Files\Storage\IReliableEtagStorage;
|
||||
|
|
@ -63,9 +64,7 @@ class Propagator implements IPropagator {
|
|||
$etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
|
||||
|
||||
$builder = $this->connection->getQueryBuilder();
|
||||
$hashParams = array_map(function ($hash) use ($builder) {
|
||||
return $builder->expr()->literal($hash);
|
||||
}, $parentHashes);
|
||||
$hashParams = array_map(static fn (string $hash): ILiteral => $builder->expr()->literal($hash), $parentHashes);
|
||||
|
||||
$builder->update('filecache')
|
||||
->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter($time, IQueryBuilder::PARAM_INT)))
|
||||
|
|
@ -106,9 +105,27 @@ class Propagator implements IPropagator {
|
|||
|
||||
for ($i = 0; $i < self::MAX_RETRIES; $i++) {
|
||||
try {
|
||||
$builder->executeStatement();
|
||||
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_SQLITE) {
|
||||
$this->connection->beginTransaction();
|
||||
// Lock all the rows first with a SELECT FOR UPDATE ordered by path_hash
|
||||
$forUpdate = $this->connection->getQueryBuilder();
|
||||
$forUpdate->select('fileid')
|
||||
->from('filecache')
|
||||
->where($forUpdate->expr()->eq('storage', $forUpdate->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($forUpdate->expr()->in('path_hash', $hashParams))
|
||||
->orderBy('path_hash')
|
||||
->forUpdate()
|
||||
->executeQuery();
|
||||
$builder->executeStatement();
|
||||
$this->connection->commit();
|
||||
} else {
|
||||
$builder->executeStatement();
|
||||
}
|
||||
break;
|
||||
} catch (DbalException $e) {
|
||||
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_SQLITE) {
|
||||
$this->connection->rollBack();
|
||||
}
|
||||
if (!$e->isRetryable()) {
|
||||
throw $e;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue