This is an automated email from the ASF dual-hosted git repository. haxiaolin pushed a commit to branch branch-2.5 in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.5 by this push: new 0d867889eac HBASE-28047 Deadlock when opening mob files (#5374) 0d867889eac is described below commit 0d867889eac13b4a5a3cca1136dd57d2b465fd15 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(); + } }