Technoboy- commented on code in PR #15354:
URL: https://github.com/apache/pulsar/pull/15354#discussion_r860764493
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongPairSet.java:
##########
@@ -469,20 +470,35 @@ private int removeIf(LongPairPredicate filter) {
int removedItems = 0;
// Go through all the buckets for this section
- for (int bucket = 0; bucket < table.length; bucket += 2) {
- long storedItem1 = table[bucket];
- long storedItem2 = table[bucket + 1];
-
- if (storedItem1 != DeletedItem && storedItem1 != EmptyItem) {
- if (filter.test(storedItem1, storedItem2)) {
- long h = hash(storedItem1, storedItem2);
- if (remove(storedItem1, storedItem2, (int) h)) {
+ long stamp = writeLock();
+ try {
+ for (int bucket = 0; bucket < table.length; bucket += 2) {
+ long storedItem1 = table[bucket];
+ long storedItem2 = table[bucket + 1];
+ if (storedItem1 != DeletedItem && storedItem1 !=
EmptyItem) {
+ if (filter.test(storedItem1, storedItem2)) {
+ SIZE_UPDATER.decrementAndGet(this);
+ cleanBucket(bucket);
removedItems++;
}
}
}
+ } finally {
+ if (autoShrink && size < resizeThresholdBelow) {
+ try {
+ int newCapacity = alignToPowerOfTwo((int) (capacity /
shrinkFactor));
+ int newResizeThresholdUp = (int) (newCapacity *
mapFillFactor);
+ if (newCapacity < capacity && newResizeThresholdUp >
size) {
+ // shrink the hashmap
+ rehash(newCapacity);
+ }
+ } finally {
+ unlockWrite(stamp);
+ }
+ } else {
+ unlockWrite(stamp);
+ }
Review Comment:
ok, fixed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]