swamirishi commented on code in PR #8203:
URL: https://github.com/apache/ozone/pull/8203#discussion_r2094700453


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreAbstractIterator.java:
##########
@@ -78,32 +84,52 @@ final RAW getPrefix() {
 
   @Override
   public final void forEachRemaining(
-      Consumer<? super Table.KeyValue<RAW, RAW>> action) {
+      Consumer<? super AutoCloseableRawKeyValue<RAW>> action) {
     while (hasNext()) {
-      action.accept(next());
+      AutoCloseableRawKeyValue<RAW> entry = next();
+      action.accept(entry);
+    }
+  }
+
+  private void releaseEntry() {
+    if (currentEntry != null) {
+      currentEntry.release();
     }
+    currentEntry = null;
+    hasNext = null;
   }
 
   private void setCurrentEntry() {
-    if (rocksDBIterator.get().isValid()) {
+    boolean isValid = !closed && rocksDBIterator.get().isValid();
+    if (isValid) {
       currentEntry = getKeyValue();
+      currentEntry.retain();
     } else {
       currentEntry = null;
     }
+    setHasNext(isValid, currentEntry);
+  }
+
+  public void setHasNext(boolean isValid, 
ReferenceCountedObject<RawKeyValue<RAW>> entry) {
+    this.hasNext = isValid && (prefix == null || 
startsWithPrefix(entry.get().getKey()));
   }
 
   @Override
   public final boolean hasNext() {
-    return rocksDBIterator.get().isValid() &&
-        (prefix == null || startsWithPrefix(key()));
+    if (hasNext == null) {
+      setCurrentEntry();
+    }
+    return hasNext;
   }
 
   @Override
-  public final Table.KeyValue<RAW, RAW> next() {
-    setCurrentEntry();
-    if (currentEntry != null) {
+  public final AutoCloseableRawKeyValue<RAW> next() {
+    if (hasNext()) {
+      AutoCloseableRawKeyValue<RAW> entry = new 
AutoCloseableRawKeyValue<>(currentEntry);
+      this.previousKeyValue = currentEntry.get();
       rocksDBIterator.get().next();

Review Comment:
   no we cannot do that. What about for the first entry. You shouldn't call 
next for the first entry in the iterator



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to