This is an automated email from the ASF dual-hosted git repository.

haxiaolin pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 3bc1f5975b7 HBASE-28047 Deadlock when opening mob files (#5374)
3bc1f5975b7 is described below

commit 3bc1f5975b7dedf171a32c465a760b8f8c311282
Author: Xiaolin Ha <haxiao...@apache.org>
AuthorDate: Thu Sep 28 08:58:18 2023 +0800

    HBASE-28047 Deadlock when opening mob files (#5374)
    
    Signed-off-by: Duo Zhang <zhang...@apache.org>
---
 .../java/org/apache/hadoop/hbase/mob/MobFileCache.java   | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileCache.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileCache.java
index ed1803cb38d..b353b53ffb7 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileCache.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileCache.java
@@ -38,6 +38,7 @@ import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.hbase.thirdparty.com.google.common.hash.Hashing;
 import 
org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 /**
@@ -174,7 +175,7 @@ public class MobFileCache {
       IdLock.Entry lockEntry = null;
       try {
         // obtains the lock to close the cached file.
-        lockEntry = keyLock.getLockEntry(fileName.hashCode());
+        lockEntry = keyLock.getLockEntry(hashFileName(fileName));
         CachedMobFile evictedFile = map.remove(fileName);
         if (evictedFile != null) {
           evictedFile.close();
@@ -205,7 +206,7 @@ public class MobFileCache {
     } else {
       String fileName = path.getName();
       CachedMobFile cached = map.get(fileName);
-      IdLock.Entry lockEntry = keyLock.getLockEntry(fileName.hashCode());
+      IdLock.Entry lockEntry = keyLock.getLockEntry(hashFileName(fileName));
       try {
         if (cached == null) {
           cached = map.get(fileName);
@@ -238,7 +239,7 @@ public class MobFileCache {
       if (!isCacheEnabled) {
         file.close();
       } else {
-        lockEntry = keyLock.getLockEntry(file.getFileName().hashCode());
+        lockEntry = keyLock.getLockEntry(hashFileName(file.getFileName()));
         file.close();
       }
     } catch (IOException e) {
@@ -325,4 +326,13 @@ public class MobFileCache {
     lastEvictedFileCount += evicted;
   }
 
+  /**
+   * Use murmurhash to reduce the conflicts of hashed file names. We should 
notice that the hash
+   * conflicts may bring deadlocks, when opening mob files with evicting some 
other files, as
+   * described in HBASE-28047.
+   */
+  private long hashFileName(String fileName) {
+    return Hashing.murmur3_128().hashString(fileName, 
java.nio.charset.StandardCharsets.UTF_8)
+      .asLong();
+  }
 }

Reply via email to