This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-3 by this push:
new 5f41d04a6a7 HBASE-28047 Deadlock when opening mob files (#5374)
5f41d04a6a7 is described below
commit 5f41d04a6a7ef41890eede4ffbdf85adbe4431fb
Author: Xiaolin Ha <[email protected]>
AuthorDate: Thu Sep 28 08:58:18 2023 +0800
HBASE-28047 Deadlock when opening mob files (#5374)
Signed-off-by: Duo Zhang <[email protected]>
(cherry picked from commit ea0a356330e1e6a2bcd0a3e2b86ccb9075f4fa9e)
---
.../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 0b527d936ed..45ec006f97f 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
@@ -41,6 +41,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;
/**
@@ -177,7 +178,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();
@@ -210,7 +211,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);
@@ -243,7 +244,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) {
@@ -330,4 +331,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();
+ }
}