You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2022/05/19 02:11:07 UTC

[GitHub] [hbase] sunhelly commented on a diff in pull request #4437: HBASE-27043 Let lock wait timeout to improve performance of SnapshotHFileCleaner

sunhelly commented on code in PR #4437:
URL: https://github.com/apache/hbase/pull/4437#discussion_r876522688


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java:
##########
@@ -192,39 +193,43 @@ public Iterable<FileStatus> getUnreferencedFiles(Iterable<FileStatus> files,
     if (snapshotManager != null) {
       lock = snapshotManager.getTakingSnapshotLock().writeLock();
     }
-    if (lock == null || lock.tryLock()) {
-      try {
-        if (snapshotManager != null && snapshotManager.isTakingAnySnapshot()) {
-          LOG.warn("Not checking unreferenced files since snapshot is running, it will "
-            + "skip to clean the HFiles this time");
-          return unReferencedFiles;
-        }
-        ImmutableSet<String> currentCache = cache;
-        for (FileStatus file : files) {
-          String fileName = file.getPath().getName();
-          if (!refreshed && !currentCache.contains(fileName)) {
-            synchronized (this) {
-              refreshCache();
-              currentCache = cache;
-              refreshed = true;
-            }
-          }
-          if (currentCache.contains(fileName)) {
-            continue;
+    try {
+      if (lock == null || lock.tryLock(30000, TimeUnit.MILLISECONDS)) {
+        try {
+          if (snapshotManager != null && snapshotManager.isTakingAnySnapshot()) {
+            LOG.warn("Not checking unreferenced files since snapshot is running, it will "
+              + "skip to clean the HFiles this time");
+            return unReferencedFiles;
           }
-          if (snapshotsInProgress == null) {
-            snapshotsInProgress = getSnapshotsInProgress();
+          ImmutableSet<String> currentCache = cache;
+          for (FileStatus file : files) {
+            String fileName = file.getPath().getName();
+            if (!refreshed && !currentCache.contains(fileName)) {
+              synchronized (this) {
+                refreshCache();
+                currentCache = cache;
+                refreshed = true;
+              }
+            }
+            if (currentCache.contains(fileName)) {
+              continue;
+            }
+            if (snapshotsInProgress == null) {
+              snapshotsInProgress = getSnapshotsInProgress();
+            }
+            if (snapshotsInProgress.contains(fileName)) {
+              continue;
+            }
+            unReferencedFiles.add(file);
           }
-          if (snapshotsInProgress.contains(fileName)) {
-            continue;
+        } finally {
+          if (lock != null) {
+            lock.unlock();
           }
-          unReferencedFiles.add(file);
-        }
-      } finally {
-        if (lock != null) {
-          lock.unlock();
         }
       }
+    } catch (InterruptedException e) {
+      LOG.warn("Try taking snapshot write lock interrupted");

Review Comment:
   Got it, thanks.



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

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