diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-08-14 10:32:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 10:32:45 +0200 |
commit | 1fa9d3987bec22620a534d42d2f1991cbccec351 (patch) | |
tree | f1292ec2f208f38fec239f636c160e3fa8c1f527 /apps | |
parent | dbc2e9cdba54720568d5787299aa41e2c565d0b0 (diff) | |
parent | 30a2e8f9b863ae5434a085ac00947c42ac849036 (diff) | |
download | nextcloud-server-1fa9d3987bec22620a534d42d2f1991cbccec351.tar.gz nextcloud-server-1fa9d3987bec22620a534d42d2f1991cbccec351.zip |
Merge pull request #46887 from nextcloud/fix/versions-catch-insertion-error
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_versions/lib/Versions/LegacyVersionsBackend.php | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php index b5b948dda5b..90e521abfb4 100644 --- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php +++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php @@ -227,7 +227,27 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend $versionEntity->setSize($file->getSize()); $versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype())); $versionEntity->setMetadata([]); - $this->versionsMapper->insert($versionEntity); + + $tries = 1; + while ($tries < 5) { + try { + $this->versionsMapper->insert($versionEntity); + /* No errors, get out of the method */ + return; + } catch (\OCP\DB\Exception $e) { + if (!in_array($e->getReason(), [ + \OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION, + \OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION, + ]) + ) { + throw $e; + } + /* Conflict with another version, increase mtime and try again */ + $versionEntity->setTimestamp($versionEntity->getTimestamp() + 1); + $tries++; + $this->logger->warning('Constraint violation while inserting version, retrying with increased timestamp', ['exception' => $e]); + } + } } public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void { |