ctubbsii commented on code in PR #4910:
URL: https://github.com/apache/accumulo/pull/4910#discussion_r1767660709


##########
server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMapCleanerUtil.java:
##########
@@ -43,14 +44,37 @@ public static Cleanable deleteNM(Object obj, Logger log, 
AtomicLong nmPtr) {
     });
   }
 
+  // Chose 7 cleaners because each cleaner creates a thread, so do not want 
too many threads. This
+  // should reduce lock contention for scans by a 7th vs a single cleaner, so 
that is good
+  // reduction and 7 does not seem like too many threads to add. This array is 
indexed using
+  // pointers addresses from native code, so there is a good chance those are 
memory aligned on
+  // a multiple of 4, 8, 16, etc. So if changing the array size avoid 
multiples of 2.
+  private static final Cleaner[] NMI_CLEANERS = new Cleaner[7];
+
+  static {
+    for (int i = 0; i < NMI_CLEANERS.length; i++) {
+      NMI_CLEANERS[i] = Cleaner.create();
+    }
+  }
+
   public static Cleanable deleteNMIterator(Object obj, AtomicLong nmiPtr) {
     requireNonNull(nmiPtr);
-    return CleanerUtil.CLEANER.register(obj, () -> {
+
+    long ptr = Math.abs(nmiPtr.get());
+    if (ptr == Long.MIN_VALUE) {
+      ptr = 0;
+    }
+    int cleanerIndex = (int) (ptr % NMI_CLEANERS.length);

Review Comment:
   You can avoid the absolute value and handling of the `Long.MIN_VALUE` by 
just fixing Java's negative answer for modulus:
   
   ```suggestion
       int cleanerIndex = (int) (nmiPtr.get() % NMI_CLEANERS.length);
       if (cleanerIndex < 0) {
         cleanerIndex += NMI_CLEANERS.length;
       }
   ```
   



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