Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-11-18 14:40:32 +0300
committerJulius Härtl <jus@bitgrid.net>2020-02-04 21:13:49 +0300
commit4f1d466de8e3b6be6bb74cc7b8db72cfc3bbc8fe (patch)
treeaf477b51adef8a6d1bade8d0cf91d71f4b28b3fa /lib
parent76c1157b71f9b5e597f74a91f1294e9e96cf291a (diff)
WIP: mitigate race condition when saving steps
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/DocumentService.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php
index af19f7bc0..9798143e0 100644
--- a/lib/Service/DocumentService.php
+++ b/lib/Service/DocumentService.php
@@ -189,8 +189,13 @@ class DocumentService {
* @throws VersionMismatchException
*/
public function addStep($documentId, $sessionId, $steps, $version): array {
- // TODO check cache
+ if (!$this->cache->get('document-push-lock-' . $documentId)) {
+ throw new VersionMismatchException('Version does not match');
+ }
+ $this->cache->set('document-save-lock-' . $documentId, true, 10);
+
$document = $this->documentMapper->find($documentId);
+
if ($version !== $document->getCurrentVersion()) {
throw new VersionMismatchException('Version does not match');
}
@@ -205,17 +210,20 @@ class DocumentService {
}
}
$newVersion = $document->getCurrentVersion() + count($steps);
+ $this->cache->set('document-version-'.$document->getId(), $newVersion);
$document->setCurrentVersion($newVersion);
$this->documentMapper->update($document);
+ // FIXME: DEBUG
+ // there might be a race condition here where the version is updated w
$step = new Step();
$step->setData($stepsJson);
$step->setSessionId($sessionId);
$step->setDocumentId($documentId);
$step->setVersion($version+1);
$this->stepMapper->insert($step);
- $this->cache->set('document-version-'.$document->getId(), $newVersion);
// TODO restore old version for document if adding steps has failed
// TODO write steps to cache for quicker reading
+ $this->cache->remove('document-push-lock-' . $documentId);
return $steps;
}
@@ -280,7 +288,7 @@ class DocumentService {
// Ignore lock since it might occur when multiple people save at the same time
return $document;
}
- $document->setLastSavedVersion($version);
+ $document->setLastSavedVersion($document->getCurrentVersion());
$document->setLastSavedVersionTime(time());
$document->setLastSavedVersionEtag($file->getEtag());
$this->documentMapper->update($document);