yandrey321 commented on code in PR #12106:
URL: https://github.com/apache/ozone/pull/12106#discussion_r4736298946


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OmKeysDeleteRequestWithFSO.java:
##########
@@ -135,9 +140,22 @@ protected Pair<Long, Integer> markKeysAsDeletedInCache(
       }
     }
 
+    // A non-recursive request deletes a directory only if the rest of the 
request leaves it empty. The files are
+    // marked above; check each subdirectory before its parent, so that the 
parent sees it deleted as well.
+    // An older leader does not reject the flag before finalization, so ignore 
it here as an older OM does.
+    final boolean recursive = 
getOmRequest().getDeleteKeysRequest().getRecursive()
+        || 
!ozoneManager.getVersionManager().isAllowed(OzoneManagerVersion.NON_RECURSIVE_DELETE_KEYS);
+    if (!recursive) {
+      dirList.sort(Comparator.comparingInt((OmKeyInfo dir) -> 
OzoneFSUtils.getFileCount(dir.getKeyName())).reversed());
+    }
     // Mark directory keys.
-    for (int i = 0; i < dirList.size(); i++) {
-      final OmKeyInfo dirInfo = dirList.get(i);
+    for (ListIterator<OmKeyInfo> dirs = dirList.listIterator(); 
dirs.hasNext();) {
+      final OmKeyInfo dirInfo = dirs.next();
+      if (!recursive && OMFileRequest.hasChildren(dirInfo, omMetadataManager)) 
{

Review Comment:
   Each directory in a non-recursive request runs OMFileRequest#hasChildren, 
which iterates the entire directoryTable and fileTable caches before seeking 
RocksDB. This runs inside validateAndUpdateCache, under the bucket write lock, 
on every OM.
   Scenario: `aws s3 rm --recursive` or a similar tool sends DeleteObjects 
batches of 1000 keys that include directory markers ("a/", "a/b/", ...). Both 
tables are PARTIAL_CACHE (OmMetadataManagerImpl), so each cache holds the 
directories and files that are written but not yet flushed and evicted. With D 
directory markers and C cached entries, one request does about 2 x D x C 
iterations, plus 2 x D RocksDB iterator seeks, while holding the bucket lock. 
With D = 500 and C = 100k under write load that is about 10^8 iterations, which 
blocks every other write to the bucket. The recursive path did none of this.
   Introduced by this PR (hasChildren is existing, but this is a new caller 
that runs it per directory).
   
   Fix option(-s): scan the two caches once per request and build a Set<Long> 
of parentObjectIDs of live cache entries. Then check each directory against the 
set plus a RocksDB seek (isExist still filters entries deleted in the cache).
   
   Alternatively, add a hasChildren overload that takes that precomputed set.



-- 
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