doc/developer-guide/dirops-transactions-in-dht.md
Need for transactions during operations on directories arise from two basic design elements of DHT:
So, entire operations like mkdir, renamedir, rmdir and creation of directories during self-heal need to be atomic in dht. In other words, any of these operations shouldn't begin on an inode if one of them is already in progress on the same inode, till it completes on all subvolumes of dht. If not, more than one of these operations happening in parallel can break any or all of the two requirements listed above. This is referred in the rest of the document by the name Atomicity during namespace operations.
Rest of the document explains how atomicity is achieved for each of the case above.
Atomicity during layout modification and reading File operations a.k.a fops can be classified into two categories based on how they consume layout.
Algorithm Atomicity is achieved by locking on the inode of directory whose layout is being modified or read. The fop used is inodelk.
Reasons why writer has to lock on all subvols:
Atomicity during namespace operations
With the above details, algorithms for mkdir, rmdir, renamedir, self-heal of directory are explicitly detailed below.
Self-heal of a directory
creation of directories on subvolumes is done only during named-lookup of a directory as we need < parent-inode, "basename" >.
If a directory is missing on one or more subvolumes,
If layout of a directory needs healing
mkdir (parent-inode, "basename")
Before any of other readers like create, link etc that operate on this directory to happen, gfid of this directory has to be resolved. But gfid is only available only if either of following conditions are true:
But, on completion of any of the above two operations, layout will be healed. So, none of the readers will happen on a directory with partial layout.
rmdir (parent-inode, "basename", directory-inode)
renamedir (src-parent-inode, "src-basename", src-directory-inode, dst-parent-inode, "dst-basename", dst-directory-inode)
Some examples of races This section gives concrete examples of races that can result in inconsistencies explained in the beginning of the document.
Some assumptions are:
And the examples are: