You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2024/11/21 23:16:26 UTC
(pinot) branch release-1.2.0-segment-lock-fix created (now 6747a668f4)
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a change to branch release-1.2.0-segment-lock-fix
in repository https://gitbox.apache.org/repos/asf/pinot.git
at 6747a668f4 Avoid collision in SegmentLocks (#13632)
This branch includes the following new commits:
new 6747a668f4 Avoid collision in SegmentLocks (#13632)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
(pinot) 01/01: Avoid collision in SegmentLocks (#13632)
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch release-1.2.0-segment-lock-fix
in repository https://gitbox.apache.org/repos/asf/pinot.git
commit 6747a668f46c2defee4947952c76d3673079a663
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Tue Jul 16 21:29:29 2024 -0700
Avoid collision in SegmentLocks (#13632)
---
.../pinot/segment/local/utils/SegmentLocks.java | 33 +++++++++-------------
1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentLocks.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentLocks.java
index 1a2cbbd230..37124fddee 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentLocks.java
+++ b/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));
}
// DO NOT use global lock because that can break tests with multiple server instances
@@ -56,11 +51,11 @@ public class SegmentLocks {
@Deprecated
public static SegmentLocks create() {
- return new SegmentLocks(DEFAULT_NUM_LOCKS);
+ return new SegmentLocks();
}
@Deprecated
public static SegmentLocks create(int numLocks) {
- return new SegmentLocks(numLocks);
+ return new SegmentLocks();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org