You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/07/26 18:41:41 UTC

[GitHub] [kafka] agavra commented on a change in pull request #11120: Add support for infinite endpoints for range queries

agavra commented on a change in pull request #11120:
URL: https://github.com/apache/kafka/pull/11120#discussion_r676851943



##########
File path: streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
##########
@@ -281,11 +280,27 @@ public boolean isEmpty() {
     }
 
     synchronized Iterator<Bytes> keyRange(final Bytes from, final Bytes to, final boolean toInclusive) {
-        return keySetIterator(cache.navigableKeySet().subSet(from, true, to, toInclusive), true);
+        final Set<Bytes> rangeSet = computeSubSet(from, to, toInclusive);
+        return keySetIterator(rangeSet, true);
     }
 
     synchronized Iterator<Bytes> reverseKeyRange(final Bytes from, final Bytes to) {
-        return keySetIterator(cache.navigableKeySet().subSet(from, true, to, true), false);
+        final Set<Bytes> rangeSet = computeSubSet(from, to, true);
+        return keySetIterator(rangeSet, false);
+    }
+
+    private Set<Bytes> computeSubSet(final Bytes from, final Bytes to, final boolean toInclusive) {
+        if (from == null && to == null) {
+            return cache.navigableKeySet();
+        } else if (from == null) {
+            return cache.headMap(to, toInclusive).keySet();
+        } else if (to == null) {
+            return cache.tailMap(from, true).keySet();
+        } else if (from.compareTo(to) > 0) {
+            return new TreeSet<>();

Review comment:
       instead of creating a new set, thoughts on just returning an empty collection? (`Collections.emptyNavigableSet()`)

##########
File path: streams/src/main/java/org/apache/kafka/streams/state/internals/RocksDBRangeIterator.java
##########
@@ -63,17 +65,20 @@
         final KeyValue<Bytes, byte[]> next = super.makeNext();
         if (next == null) {
             return allDone();
+        } else if (rawLastKey == null) {
+            return next;
+
         } else {
             if (forward) {
-                if (comparator.compare(next.key.get(), rawLastKey) < 0) {
+                if (rawLastKey != null && comparator.compare(next.key.get(), rawLastKey) < 0) {

Review comment:
       how can `rawLastKey` be null here (c.f. branch above)?




-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org