You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/03/08 08:40:14 UTC

[GitHub] [hadoop] zhuxiangyi commented on a change in pull request #3885: HDFS-16214. Asynchronously collect blocks and update quota when deleting

zhuxiangyi commented on a change in pull request #3885:
URL: https://github.com/apache/hadoop/pull/3885#discussion_r821437088



##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java
##########
@@ -112,10 +110,76 @@ static BlocksMapUpdateInfo delete(
       }
       DFSUtil.checkProtectedDescendants(fsd, iip);
     }
-
     return deleteInternal(fsn, iip, logRetryCache);
   }
 
+  /**
+   * Clean files and update Quota after collecting blcoks.
+   * <p>
+   * When it takes a long time to collect blocks when encountering
+   * a large directory, the collection block here adopts no lock。
+   * <p>
+   *
+   * @param fsn namespace
+   * @param iip inodes of a path to be deleted
+   * @return blocks collected from the deleted path
+   * @throws IOException
+   */
+  static BlocksMapUpdateInfo clearFileAndUpdateQuota(FSNamesystem fsn, INodesInPath iip)
+      throws QuotaExceededException {
+    long filesRemoved = -1;
+    if (iip == null) {
+      return null;
+    }
+    // collect blocks no lock
+    INode.ReclaimContext context = FSDirDeleteOp.collectBlocks(fsn, iip);
+    filesRemoved = context.quotaDelta().getNsDelta();
+    if (filesRemoved < 0) {
+      return context.collectedBlocks;
+    }
+    // update Quota and clear UCFiles lease
+    fsn.writeLock();
+    try {
+      FSDirectory fsd = fsn.getFSDirectory();
+      fsd.removeInodeFromDeletingInodes(iip.getLastINode());
+      fsn.removeLeasesAndINodes(context.removedUCFiles,
+          context.removedINodes, true);
+      fsd.updateCount(iip, context.quotaDelta(), false);
+      incrDeletedFileCount(filesRemoved);
+      fsd.updateReplicationFactor(context.collectedBlocks().toUpdateReplicationInfo());
+    } finally {
+      fsn.writeUnlock();
+    }
+    return context.collectedBlocks;
+  }
+
+  /**
+   * Collect blocks from the deleted path.
+   *
+   * @param fsn namespace
+   * @param iip inodes of a path to be deleted
+   * @return blocks collected from the deleted path
+   */
+  static ReclaimContext collectBlocks(FSNamesystem fsn, INodesInPath iip) {

Review comment:
       There may be problems in deleting the snapshot file without locking. I reconstructed the logic of this part, put the deletion of the snapshot file into the lock, and use asynchronous collection block and update quota.




-- 
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: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org