tkalkirill commented on code in PR #1407:
URL: https://github.com/apache/ignite-3/pull/1407#discussion_r1044315297
##########
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java:
##########
@@ -167,24 +167,71 @@ private Cursor<ByteBuffer> createScanCursor(byte
@Nullable [] lowerBound, byte @
RocksIterator it = indexCf.newIterator(options);
- if (lowerBound == null) {
- it.seek(partitionStorage.partitionStartPrefix());
- } else {
- it.seek(lowerBound);
- }
+ return new Cursor<>() {
+ @Nullable
+ private Boolean hasNext;
- return new RocksIteratorAdapter<>(it) {
- @Override
- protected ByteBuffer decodeEntry(byte[] key, byte[] value) {
- return ByteBuffer.wrap(key).order(ORDER);
- }
+ @Nullable
+ private byte[] key;
@Override
public void close() {
- super.close();
+ it.close();
RocksUtils.closeAll(options, upperBoundSlice);
}
+
+ @Override
+ public boolean hasNext() {
+ advanceIfNeeded();
+
+ return hasNext;
+ }
+
+ @Override
+ public ByteBuffer next() {
+ advanceIfNeeded();
+
+ boolean hasNext = this.hasNext;
+
+ this.hasNext = null;
+
+ if (!hasNext) {
+ throw new NoSuchElementException();
+ }
+
+ return ByteBuffer.wrap(key).order(ORDER);
+ }
+
+ private void advanceIfNeeded() throws StorageException {
+ if (hasNext == null) {
+ try {
+ it.refresh();
+ } catch (RocksDBException e) {
+ throw new StorageException("Error refreshing an
iterator", e);
+ }
+
+ if (key == null) {
+ it.seek(lowerBound == null ?
partitionStorage.partitionStartPrefix() : lowerBound);
+ } else {
+ it.seekForPrev(key);
+
+ it.next();
Review Comment:
Tried to test in
`org.apache.ignite.internal.storage.index.AbstractSortedIndexStorageTest#testScanContractRemoveCachedRow`
--
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]