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: [email protected]

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

Reply via email to