sashapolo commented on code in PR #1887:
URL: https://github.com/apache/ignite-3/pull/1887#discussion_r1159444911
##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/RocksDbKeyValueStorage.java:
##########
@@ -758,23 +757,95 @@ private void applyOperations(Collection<Operation> ops)
throws RocksDBException
}
@Override
- public Cursor<Entry> range(byte[] keyFrom, byte[] keyTo, boolean
includeTombstones) {
- return new RangeCursor(this, keyFrom, keyTo, rev, includeTombstones);
- }
+ public Cursor<Entry> range(byte[] keyFrom, byte @Nullable [] keyTo) {
+ rwLock.readLock().lock();
- @Override
- public Cursor<Entry> range(byte[] keyFrom, byte[] keyTo, long
revUpperBound, boolean includeTombstones) {
- return new RangeCursor(this, keyFrom, keyTo, revUpperBound,
includeTombstones);
+ try {
+ return range(keyFrom, keyTo, rev);
+ } finally {
+ rwLock.readLock().unlock();
+ }
}
@Override
- public Cursor<Entry> prefix(byte[] prefix, boolean includeTombstones) {
- return prefix(prefix, rev, includeTombstones);
- }
+ public Cursor<Entry> range(byte[] keyFrom, byte @Nullable [] keyTo, long
revUpperBound) {
+ rwLock.readLock().lock();
- @Override
- public Cursor<Entry> prefix(byte[] prefix, long revUpperBound, boolean
includeTombstones) {
- return new RangeCursor(this, prefix, incrementPrefix(prefix),
revUpperBound, includeTombstones);
+ try {
+ var readOpts = new ReadOptions();
+
+ var upperBound = keyTo == null ? null : new Slice(keyTo);
+
+ readOpts.setIterateUpperBound(upperBound);
+
+ RocksIterator iterator = index.newIterator(readOpts);
+
+ iterator.seek(keyFrom);
+
+ return new RocksIteratorAdapter<>(iterator) {
+ /** Cached entry used to filter "empty" values. */
+ @Nullable
+ private Entry next;
+
+ @Override
+ public boolean hasNext() {
+ if (next != null) {
+ return true;
+ }
+
+ while (next == null && super.hasNext()) {
+ Entry nextCandidate = decodeEntry(it.key(),
it.value());
+
+ it.next();
+
+ if (!nextCandidate.empty()) {
+ next = nextCandidate;
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public Entry next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ Entry result = next;
+
+ assert result != null;
+
+ next = null;
+
+ return result;
+ }
+
+ @Override
+ protected Entry decodeEntry(byte[] key, byte[] value) {
+ long[] revisions = getAsLongs(value);
+
+ long targetRevision = maxRevision(revisions,
revUpperBound);
+
+ if (targetRevision == -1) {
+ return EntryImpl.empty(key);
+ }
+
+ return doGetValue(key, targetRevision);
Review Comment:
I agree with you. I didn't add a lock here because, as I said above,
compation is not implemented properly yet and the lock is not needed right now
(I didn't remove the locks from other places because it's kind of out of scope
of this PR). I'm going to add it here just for consistency.
--
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]