SaketaChalamchala opened a new pull request, #12156:
URL: https://github.com/apache/ozone/pull/12156

   Found by TLA+ model checking and code review of the OM optimized snapshot 
diff paths under 
[HDDS-15926](https://issues.apache.org/jira/browse/HDDS-15926), on commit 
https://github.com/apache/ozone/commit/d3b75c75bf9ad475551202477c3a21a3f4b968b7.
   
   ## What changes were proposed in this pull request?
   
   If a directory is deleted and created/renamed at the same path in a single 
flush batch, only the create/rename is reported when using Optimized snapshot 
diff with `DagDiffSequentialReader`.
   
   This is because: 
   * When the `RDBBatchOperation` is built on 
`OzoneManagerDoubleBuffer.flushBatch` the latest put (for create or rename) 
wins for the path key and only that transaction is committed and replayed in 
RocksDB when the `memTable` is flushed i.e., `put` for the latest create/rename 
is included in the delta SST files but not the tombstone for the old delete.
   * When building the diff candidate set for the directory entries since there 
is no tombstone for the old delete, the old path is not recorded in the 
tombstone set. For the newly created/renamed path only the objectId is recorded 
in the diff candidate set but not the key.
   * So, when building the diff the delete entry is missed for the old path 
since it's key is never recorded in the diff candidate set.
   
   The proposed fix:
   * Only uses the directory table keys to capture the diff candidate set 
instead of using the objectIDs for non-tombstones. This is the same thing we do 
when scanning the file delta set.
   * This captures the path that is deleted and then replaced by a 
create/rename and that should capture all the entries related to the path on 
both sides which avoids missing the old delete.
   
   For ex., 
   * When `rm -r d` (old key with `objectID=1`) and `mkdir d` (new key with 
`objectID=2`)  are flushed in the same batch: 
       * Only the `put d` (`objectID=2`) is available in delta SST.
    **Before the fix:** 
       * On `scanDeltaDirectoryTable` only `objectID=2` is tracked in the diff 
candidate list and is populated in the `newList`. Since `objectID=2` is missing 
in the `fromSnapshot` no entry for the path is written to `oldList`. In the 
diff report only `CREATE d` is included as `objectID=2` is in `newList` and not 
in `oldList`.
    **After the fix:** 
       * On `scanDeltaDirectoryTable` the RocksDB key 
`/<volID>/<bucketID>/<parentId>/d` (`objectID=2`) is tracked in the diff 
candidate list and is populated in the `newList`. Since 
`/<volID>/<bucketID>/<parentId>/d` (`objectID=1`)  is also available in the 
`fromSnapshot` that entry is written to `oldList`. In the diff report, `DELETE 
d` is reported now because `objectID=1` is present in `oldList` but not in 
`newList` and `CREATE d` is also reported as usual.
   
   * When `rm -r d` (old key with `objectID=1`) and `mv a d` (new key with 
`objectID=2`)  are flushed in the same batch: 
       * Tombstone for `delete a` is available in delta SST and 
       * Only the `put d` is available in delta SST for path `d`.
    **Before the fix:** 
       * On `scanDeltaDirectoryTable` path `/<volID>/<bucketID>/<parentId>/a` 
(because path `a` has a tombstone in the delta SST files) and `objectID=2` are 
tracked in the diff candidate list and are populated in the `newList`. Both 
`/<volID>/<bucketID>/<parentId>/a` and `objectID=2` are present in the 
`fromSnapshot`. They belong to the same entry and that entry is written to 
`oldList`. In the diff report only `RENAME a d` is included as `objectID=2` is 
in `newList` and in `oldList` with a key name change.
    **After the fix:** 
       * On `scanDeltaDirectoryTable` the RocksDB key 
`/<volID>/<bucketID>/<parentId>/d` (`objectID=2`) and the tombstone key 
`/<volID>/<bucketID>/<parentId>/a` is tracked in the diff candidate list and is 
populated in the `newList`. Since `/<volID>/<bucketID>/<parentId>/d` 
(`objectID=1`)  is also available in the `fromSnapshot` that entry is written 
to `oldList` along with `/<volID>/<bucketID>/<parentId>/a` (`objectID=2`). In 
the diff report, `DELETE d` is reported now because `objectID=1` is present in 
`oldList` but not in `newList` and `RENAME a d` is also reported as usual.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-17747
   
   ## How was this patch tested?
   
   Added coverage in `TestDagDiffSequentialReader. testKeyDiffShapes` and 
`TestDagDiffSequentialReader. testDirectoryDiffShapes`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to