Skip to content

Commit

Permalink
[improve][broker] Optimize ConcurrentOpenLongPairRangeSet by Roarin…
Browse files Browse the repository at this point in the history
…gBitmap (apache#22908)

(cherry picked from commit 5b1f653)
(cherry picked from commit f99040d)
  • Loading branch information
dao-jun authored and nikhil-ctds committed Jun 25, 2024
1 parent 3b9f5b4 commit a25c6cd
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 11 deletions.
3 changes: 1 addition & 2 deletions distribution/server/src/assemble/LICENSE.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ The Apache Software License, Version 2.0
* RxJava
- io.reactivex.rxjava3-rxjava-3.0.1.jar
* RoaringBitmap
- org.roaringbitmap-RoaringBitmap-0.9.44.jar
- org.roaringbitmap-shims-0.9.44.jar
- org.roaringbitmap-RoaringBitmap-1.1.0.jar

BSD 3-clause "New" or "Revised" License
* Google auth library
Expand Down
2 changes: 2 additions & 0 deletions distribution/shell/src/assemble/LICENSE.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ The Apache Software License, Version 2.0
- simpleclient_tracer_common-0.16.0.jar
- simpleclient_tracer_otel-0.16.0.jar
- simpleclient_tracer_otel_agent-0.16.0.jar
* RoaringBitmap
- RoaringBitmap-1.1.0.jar
* Log4J
- log4j-api-2.18.0.jar
- log4j-core-2.18.0.jar
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ flexible messaging model and an intuitive client API.</description>
<j2objc-annotations.version>1.3</j2objc-annotations.version>
<lightproto-maven-plugin.version>0.4</lightproto-maven-plugin.version>
<dependency-check-maven.version>9.1.0</dependency-check-maven.version>
<roaringbitmap.version>0.9.44</roaringbitmap.version>
<roaringbitmap.version>1.1.0</roaringbitmap.version>
<extra-enforcer-rules.version>1.6.1</extra-enforcer-rules.version>
<oshi.version>6.4.0</oshi.version>

Expand Down
5 changes: 5 additions & 0 deletions pulsar-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.roaringbitmap</groupId>
<artifactId>RoaringBitmap</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang.mutable.MutableInt;
import org.roaringbitmap.RoaringBitSet;

/**
* A Concurrent set comprising zero or more ranges of type {@link LongPair}. This can be alternative of
Expand All @@ -44,7 +45,7 @@
public class ConcurrentOpenLongPairRangeSet<T extends Comparable<T>> implements LongPairRangeSet<T> {

protected final NavigableMap<Long, BitSet> rangeBitSetMap = new ConcurrentSkipListMap<>();
private boolean threadSafe = true;
private final boolean threadSafe;
private final int bitSetSize;
private final LongPairConsumer<T> consumer;

Expand Down Expand Up @@ -95,9 +96,7 @@ public void addOpenClosed(long lowerKey, long lowerValueOpen, long upperKey, lon
// (2) set 0th-index to upper-index in upperRange.getKey()
if (isValid(upperKey, upperValue)) {
BitSet rangeBitSet = rangeBitSetMap.computeIfAbsent(upperKey, (key) -> createNewBitSet());
if (rangeBitSet != null) {
rangeBitSet.set(0, (int) upperValue + 1);
}
rangeBitSet.set(0, (int) upperValue + 1);
}
// No-op if values are not valid eg: if lower == LongPair.earliest or upper == LongPair.latest then nothing
// to set
Expand Down Expand Up @@ -414,7 +413,6 @@ private int getSafeEntry(long value) {
}

private BitSet createNewBitSet() {
return this.threadSafe ? new ConcurrentBitSet(bitSetSize) : new BitSet(bitSetSize);
return this.threadSafe ? new ConcurrentRoaringBitSet() : new RoaringBitSet();
}

}
}
Loading

0 comments on commit a25c6cd

Please sign in to comment.