klsince commented on code in PR #13632:
URL: https://github.com/apache/pinot/pull/13632#discussion_r1680227655


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentLocks.java:
##########
@@ -18,30 +18,25 @@
  */
 package org.apache.pinot.segment.local.utils;
 
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import org.apache.commons.lang3.tuple.Pair;
 
 
 public class SegmentLocks {
-  private static final int DEFAULT_NUM_LOCKS = 10000;
-
-  private final Lock[] _locks;
-  private final int _numLocks;
-
-  public SegmentLocks(int numLocks) {
-    _numLocks = numLocks;
-    _locks = new Lock[numLocks];
-    for (int i = 0; i < numLocks; i++) {
-      _locks[i] = new ReentrantLock();
-    }
-  }
-
-  public SegmentLocks() {
-    this(DEFAULT_NUM_LOCKS);
-  }
+  private final LoadingCache<Pair<String, String>, Lock> _locks =
+      CacheBuilder.newBuilder().weakValues().build(new CacheLoader<>() {
+        @Override
+        public Lock load(Pair<String, String> key) {
+          return new ReentrantLock();
+        }
+      });
 
   public Lock getLock(String tableNameWithType, String segmentName) {
-    return _locks[Math.abs((31 * tableNameWithType.hashCode() + 
segmentName.hashCode()) % _numLocks)];
+    return _locks.getUnchecked(Pair.of(tableNameWithType, segmentName));

Review Comment:
   What’s special about getUnchecked? 



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to