This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new d0cc35f87f only registers cleaner in native map when needed (#4909)
d0cc35f87f is described below

commit d0cc35f87fb057b889077b9aedfdfd3ce6561a3b
Author: Keith Turner <ktur...@apache.org>
AuthorDate: Fri Sep 20 16:34:43 2024 -0400

    only registers cleaner in native map when needed (#4909)
    
    Registering cleaners takes up resources and currently bumps into a
    global lock. The native map code is registering a cleaner for iterators,
    even in the case where the native code did not allocate an iterator.
    This code is called very frequently by scan threads.
    
    This change does not register the cleaner in the case where the native
    code did not allocate a native iterator.
    
    
    Co-authored-by: Christopher Tubbs <ctubb...@apache.org>
---
 .../src/main/java/org/apache/accumulo/tserver/NativeMap.java      | 3 ++-
 .../java/org/apache/accumulo/test/functional/NativeMapIT.java     | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java 
b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
index 04c16f7ccd..54fad1d7d4 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
@@ -304,7 +304,8 @@ public class NativeMap implements 
Iterable<Map.Entry<Key,Value>> {
       hasNext = nmiPointer != 0;
 
       nmiPtr.set(nmiPointer);
-      cleanableNMI = NativeMapCleanerUtil.deleteNMIterator(this, nmiPtr);
+      // avoid registering a cleanable if there's nothing to delete
+      cleanableNMI = hasNext ? NativeMapCleanerUtil.deleteNMIterator(this, 
nmiPtr) : null;
     }
 
     // delete is synchronized on a per iterator basis want to ensure only one
diff --git 
a/test/src/main/java/org/apache/accumulo/test/functional/NativeMapIT.java 
b/test/src/main/java/org/apache/accumulo/test/functional/NativeMapIT.java
index 95fef1696c..1eb457a78f 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/NativeMapIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/NativeMapIT.java
@@ -548,6 +548,14 @@ public class NativeMapIT {
     assertEquals(0, nm.size());
     assertEquals(0, nm.getMemoryUsed());
 
+    var iter1 = nm.iterator();
+    assertFalse(iter1.hasNext());
+    assertThrows(NoSuchElementException.class, () -> iter1.next());
+
+    var iter2 = nm.iterator(new Key("abc"));
+    assertFalse(iter2.hasNext());
+    assertThrows(NoSuchElementException.class, () -> iter2.next());
+
     nm.delete();
   }
 

Reply via email to