Skip to content

Implement high level file locking #11804

Closed

Description

@PVince81

Currently the files_locking app only works on storage level, which is not enough to guarantee atomicity of operations. This is because we have hooks and proxies and apps are able to perform additional filesystem operations.

A high-level file locking mechanism should be implemented to guarantee atomicity of file operations on a higher level.

For example, this is what happens when renaming an encrypted file:

  1. User renames file
  2. System calls $view->rename()
  3. File is renamed on the storage
  4. Encryption keys are renamed
  5. Version files are renamed

Since files_locking only operates on storage level, only step 3) is locked.

If after step 3) someone renamed the new file to yet another name, they will get a "share key not found" error.

The high-level locking mechanism would work as follows:

  1. User renames files
  2. System calls $view->rename()
  3. A lock is set on source and target file names
  4. File is renamed on the storage
  5. Encryption keys are renamed
  6. Versions are renamed
  7. Lock is released

Also note that files_locking does not lock folders.

There's also the open question whether parent folders should be locked and whether folder locking is feasible at all.

Here is an example of what kind of race conditions happen due to lack of high-level locking: #11795
(rename a folder while the sync client is uploading files into it)

@craigpg @karlitschek @MTRichards @DeepDiver1975 @icewind1991 @schiesbn @bantu

Activity

  1. PVince81 commented on Oct 28, 2014

    @PVince81
    ContributorAuthor

    To discuss:

    • how to lock (DB, zookeeper, temporary files, etc)
    • what to lock: files, target files
    • whether to lock folders when doing an operation directly on them
    • whether to lock parent folders when doing an operation on the children
  2. DeepDiver1975 commented on Oct 28, 2014

    @DeepDiver1975
    Contributor
    • expose these high level locks via webdav - has impact on sync client
    • visualize locks on web ui ?
  3. PVince81 commented on Oct 28, 2014

    @PVince81
    ContributorAuthor
    • proper timeout handling: locks should not stay forever
  4. DeepDiver1975 commented on Oct 28, 2014

    @DeepDiver1975
    Contributor

    note regarding timeout: webdav lock support timeouts as well - we need to keep these values in sync

  5. PVince81 commented on Oct 28, 2014

    @PVince81
    ContributorAuthor

    The locking also needs to be multi-level, which means that an operation on level 1 (user renames folder) could also cause additional locks to be created.

    One example is that whenever the user accesses the storage, sometimes we need to adjust the mount points in case of conflicts. Adjusting the mount points would itself be a sub-transaction.

    Maybe we should rather talk about transactions and provide methods "beginTransaction($files)" with a list of files to lock. Then "endTransaction($files)" to end it (or use a $handle).

    Let's say renaming a file consists of calling "file_exists($target)" then "rename($source, $target)".
    The rename.php from the ajax call would then call:

    $handle = $view->beginTransaction(array($source, $target));
    if (!$view->file_exists($target)) { // for the sake of the example
       $view->rename($source, $target);
    }
    $view->endTransaction($handle);

    Inside of $view->rename() there will be another call to $view->beginTransaction(array($source, $target)) that increments the lock count for these files. This is in case $view->rename() is called alone.

  6. PVince81 commented on Nov 2, 2014

    @PVince81
    ContributorAuthor

    Another case appeared on my own server today: double deletion over WebDAV: #11910

  7. added this to the milestone on Mar 23, 2015
  8. PVince81 commented on Mar 24, 2015

    @PVince81
    ContributorAuthor

    Some ideas:

    • implement file locking on view level using file paths from the user's point of view (with mount points)
    • for shared folders, always lock the paths of the owner
    • save locks in a DB table or memcache (interchangeable by abstracting the "lock provider")
    • lock provider can be instantiated by Storage classes (in case we could even use flock on some
      storages)
    • no difference between read/write locks
  9. karlitschek commented on Mar 26, 2015

    @karlitschek
    Contributor

    related #11734

  10. PVince81 commented on Apr 28, 2015

    @PVince81
    ContributorAuthor
    • locking provider
    • plug it into the code (View)
    • return proper locking codes to the client (through exceptions ?)
      • Sabre exception (return HTTP code 423)
    • special cases for direct storage access (file PUT)
  11. PVince81 commented on Apr 28, 2015

    @PVince81
    ContributorAuthor
    • scanner needs to lock too
  12. PVince81 commented on Apr 28, 2015

    @PVince81
    ContributorAuthor
    • unit test: acquire lock directly, then call $view->operation to ensure that it also acquires the lock
  13. 52 remaining items

  14. icewind1991 commented on May 26, 2015

    @icewind1991
    Contributor

    redis coming later

    Redis already works if you configure redis as your memcache backend

  15. PVince81 commented on May 26, 2015

    @PVince81
    ContributorAuthor

    Raised owncloud/smashbox#94 about writing a special app that could help recreate the race conditions more consistently.

  16. PVince81 commented on May 27, 2015

    @PVince81
    ContributorAuthor
  17. PVince81 commented on May 27, 2015

    @PVince81
    ContributorAuthor
    • more user friendly error messages in the web UI when a file is locked
  18. PVince81 commented on May 29, 2015

    @PVince81
    ContributorAuthor
    • also lock properly for system-wide external storage mount points (to be discussed)
      This is once again an opportunity to mention my idea of getting rid of "applicable" for external storages but using the "sharing" approach instead (admin mounts ext storage locally, shares with applicable users/groups), to avoid requiring custom code specific to ext storage and simply reuse the sharing one: System external storage mounts as shares instead #11182
  19. PVince81 commented on May 29, 2015

    @PVince81
    ContributorAuthor
  20. PVince81 commented on Jun 1, 2015

    @PVince81
    ContributorAuthor

    More issues and test steps documented here: #16664

  21. carlaschroder commented on Jun 2, 2015

    @carlaschroder
  22. PVince81 commented on Jun 18, 2015

    @PVince81
    ContributorAuthor

    @icewind1991 @DeepDiver1975 what about "short waiting time when acquiring before abort" ?
    Currently it seems to directly acquire a lock or fail directly.

    In the files_locking app we had a usleep().
    But anyway, this is more about tweaking locking performance.

  23. PVince81 commented on Jun 18, 2015

    @PVince81
    ContributorAuthor

    raised wait-retry as #17016

  24. PVince81 commented on Jun 23, 2015

    @PVince81
    ContributorAuthor

    Most of this has either been implemented already or raised as separate tickets.

    We can either close it or keep it to keep an overview (but then remove the severity tags?)

  25. PVince81 commented on Jun 29, 2015

    @PVince81
    ContributorAuthor

    There are tickets for the remaining issues, tasks => closing

  26. locked as resolved and limited conversation to collaborators on Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions