tkalkirill commented on code in PR #1506:
URL: https://github.com/apache/ignite-3/pull/1506#discussion_r1072447536


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AbstractPageMemoryMvPartitionStorage.java:
##########
@@ -987,24 +909,174 @@ public boolean hasNext() {
                     ReadResult result = findLatestRowVersion(chain);
 
                     if (result.isEmpty() && !result.isWriteIntent()) {
-                        continue;
+                        return null;
                     }
 
                     nextRead = result;
                     currentChain = chain;
 
                     return true;
-                } finally {
-                    closeBusyLock.leaveBusy();
+                });
+
+                if (hasNext != null) {
+                    return hasNext;
                 }
             }
         }
     }
 
+    private class ScanVersionsCursor implements Cursor<ReadResult> {
+        final RowId rowId;
+
+        @Nullable
+        private Boolean hasNext;
+
+        @Nullable
+        private VersionChain versionChain;
+
+        @Nullable
+        private RowVersion rowVersion;
+
+        private ScanVersionsCursor(RowId rowId) {
+            this.rowId = rowId;
+        }
+
+        @Override
+        public void close() {
+            // No-op.
+        }
+
+        @Override
+        public boolean hasNext() {
+            return busy(() -> {
+                advanceIfNeeded();
+
+                return hasNext;
+            });
+        }
+
+        @Override
+        public ReadResult next() {
+            return busy(() -> {
+                advanceIfNeeded();
+
+                if (!hasNext) {
+                    throw new NoSuchElementException();
+                }
+
+                hasNext = null;
+
+                return 
rowVersionToResultNotFillingLastCommittedTs(versionChain, rowVersion);
+            });
+        }
+
+        private void advanceIfNeeded() {
+            throwExceptionIfStorageInProgressOfRebalance(state.get(), 
AbstractPageMemoryMvPartitionStorage.this::createStorageInfo);
+
+            if (hasNext != null) {
+                return;
+            }
+
+            if (versionChain == null) {
+                try {
+                    versionChain = versionChainTree.findOne(new 
VersionChainKey(rowId));
+                } catch (IgniteInternalCheckedException e) {
+                    throw new StorageException(e);
+                }
+
+                rowVersion = versionChain == null ? null : 
readRowVersion(versionChain.headLink(), ALWAYS_LOAD_VALUE);
+            } else {
+                rowVersion = !rowVersion.hasNextLink() ? null : 
readRowVersion(rowVersion.nextLink(), ALWAYS_LOAD_VALUE);
+            }
+
+            hasNext = rowVersion != null;
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!state.compareAndSet(StorageState.RUNNABLE, StorageState.CLOSED)) {
+            StorageState state = this.state.get();
+
+            assert state == StorageState.CLOSED : state;
+
+            return;
+        }
+
+        busyLock.block();
+
+        versionChainTree.close();

Review Comment:
   Makes sense, I'll do it.



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