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


##########
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:
   If you are only logging a warning here, don't we need to set the Thread 
interrupted status back after catching the exception? (It may be fine here for 
now, but not restoring the interrupt flag like this is an antipattern.)
   
       +    Thread.getCurrent().interrupt(); // restore the interrupt flag



##########
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();
         }
       }

Review Comment:
   Is it worth putting a log line here that the `tryLock` failed to acquire the 
lock? 



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