Skip to content

Commit 02476db

Browse files
committed
Add retry logic to cover deadlock situations
Signed-off-by: Louis Chemineau <[email protected]>
1 parent 9afcec7 commit 02476db

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
namespace OC\Files\Cache;
4242

43+
use Doctrine\DBAL\Exception\DeadlockException;
4344
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
4445
use OC\Files\Search\SearchComparison;
4546
use OC\Files\Search\SearchQuery;
@@ -692,7 +693,6 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
692693
throw new \Exception('Invalid target storage id: ' . $targetStorageId);
693694
}
694695

695-
$this->connection->beginTransaction();
696696
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
697697
//update all child entries
698698
$sourceLength = mb_strlen($sourcePath);
@@ -715,11 +715,20 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
715715
$query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT));
716716
}
717717

718-
try {
719-
$query->execute();
720-
} catch (\OC\DatabaseException $e) {
721-
$this->connection->rollBack();
722-
throw $e;
718+
// Retry transaction in case of deadlock.
719+
foreach ([1, 2, 3] as $_) {
720+
try {
721+
$this->connection->beginTransaction();
722+
$query->execute();
723+
break;
724+
} catch (\OC\DatabaseException $e) {
725+
$this->connection->rollBack();
726+
throw $e;
727+
} catch (\Throwable $e) {
728+
if (!($e instanceof DeadlockException)) {
729+
throw $e;
730+
}
731+
}
723732
}
724733
}
725734

0 commit comments

Comments
 (0)