You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ms...@apache.org on 2026/02/23 21:35:33 UTC
(lucene) branch atomic_stringhelper_randomid updated (9dbebd9444c -> a946e65fd25)
This is an automated email from the ASF dual-hosted git repository.
msfroh pushed a change to branch atomic_stringhelper_randomid
in repository https://gitbox.apache.org/repos/asf/lucene.git
discard 9dbebd9444c Remove lock in StringHelper, using atomic getAndUpdate instead
new a946e65fd25 Remove lock in StringHelper, using atomic getAndUpdate instead
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (9dbebd9444c)
\
N -- N -- N refs/heads/atomic_stringhelper_randomid (a946e65fd25)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
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.
Summary of changes:
lucene/core/src/java/org/apache/lucene/util/StringHelper.java | 1 -
1 file changed, 1 deletion(-)
(lucene) 01/01: Remove lock in StringHelper, using atomic getAndUpdate instead
Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
msfroh pushed a commit to branch atomic_stringhelper_randomid
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit a946e65fd25fc53d2c848015e80049dcf5ed0447
Author: Michael Froh <ms...@apache.org>
AuthorDate: Mon Feb 23 13:30:13 2026 -0800
Remove lock in StringHelper, using atomic getAndUpdate instead
Signed-off-by: Michael Froh <ms...@apache.org>
---
.../src/java/org/apache/lucene/util/StringHelper.java | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
index 2b75e2dd662..14923bcca8b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
+++ b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
@@ -22,6 +22,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Methods for manipulating strings.
@@ -360,11 +361,9 @@ public abstract class StringHelper {
}
// Holds 128 bit unsigned value:
- @SuppressWarnings("NonFinalStaticField")
- private static BigInteger nextId;
+ private static final AtomicReference<BigInteger> nextId;
private static final BigInteger mask128;
- private static final Object idLock = new Object();
static {
// 128 bit unsigned mask
@@ -435,7 +434,7 @@ public abstract class StringHelper {
BigInteger unsignedX1 = BigInteger.valueOf(x1).and(mask64);
// Concatentate bits of x0 and x1, as unsigned 128 bit integer:
- nextId = unsignedX0.shiftLeft(64).or(unsignedX1);
+ nextId = new AtomicReference<>(unsignedX0.shiftLeft(64).or(unsignedX1));
}
/** length in bytes of an ID */
@@ -458,11 +457,9 @@ public abstract class StringHelper {
// what impact that has on the period, whereas the simple ++ (mod 2^128)
// we use here is guaranteed to have the full period.
- byte[] bits;
- synchronized (idLock) {
- bits = nextId.toByteArray();
- nextId = nextId.add(BigInteger.ONE).and(mask128);
- }
+
+ BigInteger next = nextId.getAndUpdate(n -> n.add(BigInteger.ONE).and(mask128));
+ byte[] bits = next.toByteArray();
// toByteArray() always returns a sign bit, so it may require an extra byte (always zero)
if (bits.length > ID_LENGTH) {