merlimat commented on code in PR #25644:
URL: https://github.com/apache/pulsar/pull/25644#discussion_r3174050744


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongHashMap.java:
##########
@@ -288,11 +289,27 @@ public interface EntryProcessor<V> {
         void accept(long key, V value);
     }
 
-    // A section is a portion of the hash map that is covered by a single
+    // A section is a portion of the hash map that is covered by a single 
lock. The keys, values
+    // and capacity arrays are bundled into an immutable Table snapshot so 
that readers always see
+    // a consistent (key, value, length) triple, eliminating the 
partial-publish race that the
+    // previous design had to paper over with Math.min(keys.length, 
values.length).
     @SuppressWarnings("serial")
     private static final class Section<V> extends StampedLock {
-        private volatile long[] keys;
-        private volatile V[] values;
+        private static final class Table<V> {

Review Comment:
   This could be converted to a Java record



##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongHashMap.java:
##########
@@ -288,11 +289,27 @@ public interface EntryProcessor<V> {
         void accept(long key, V value);
     }
 
-    // A section is a portion of the hash map that is covered by a single
+    // A section is a portion of the hash map that is covered by a single 
lock. The keys, values
+    // and capacity arrays are bundled into an immutable Table snapshot so 
that readers always see
+    // a consistent (key, value, length) triple, eliminating the 
partial-publish race that the
+    // previous design had to paper over with Math.min(keys.length, 
values.length).
     @SuppressWarnings("serial")
     private static final class Section<V> extends StampedLock {
-        private volatile long[] keys;
-        private volatile V[] values;
+        private static final class Table<V> {
+            final long[] keys;
+            final V[] values;
+            final int capacity;
+
+            Table(long[] keys, V[] values, int capacity) {
+                this.keys = keys;
+                this.values = values;
+                this.capacity = capacity;
+            }
+        }
+
+        // Section is Serializable only by inheritance from StampedLock; never 
actually serialized.
+        @SuppressFBWarnings("SE_BAD_FIELD")
+        private volatile Table<V> table;
 
         private volatile int capacity;

Review Comment:
   shouldn't this get removed now?



-- 
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]

Reply via email to