Savonitar commented on code in PR #30190:
URL: https://github.com/apache/flink/pull/30190#discussion_r4768857445


##########
flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/state/rocksdb/RocksDBOperationUtils.java:
##########
@@ -143,8 +147,26 @@ static RocksIteratorWrapper 
getRocksIteratorBoundedByPrefix(
         final Slice upperBound = new Slice(prefixEnd);
         ReadOptions boundedReadOptions = null;
         try {
-            boundedReadOptions = new ReadOptions(readOptions);
-            boundedReadOptions.setIterateUpperBound(upperBound);
+            boundedReadOptions = copyForPrefixBoundedIterators(readOptions, 
upperBound);
+            return new RocksIteratorWrapper(
+                    db.newIterator(columnFamilyHandle, boundedReadOptions),
+                    boundedReadOptions,
+                    upperBound);
+        } catch (RuntimeException | Error e) {
+            IOUtils.closeQuietly(boundedReadOptions);
+            IOUtils.closeQuietly(upperBound);
+            throw e;
+        }
+    }
+
+    /**
+     * Copies {@code readOptions} for an iterator bounded by a key prefix. The 
caller owns both the
+     * copy and the upper bound.
+     */
+    static ReadOptions copyForPrefixBoundedIterators(

Review Comment:
   Agree. Usually I do that, but missed in this case.  I will split out 
extractions like this in future PRs



##########
flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/state/rocksdb/RocksDBOperationUtils.java:
##########
@@ -182,14 +201,25 @@ static RocksIteratorWrapper 
getRocksIteratorBoundedByPrefix(
     @Nullable
     @VisibleForTesting
     static byte[] getPrefixEnd(byte[] prefix) {
-        for (int i = prefix.length - 1; i >= 0; --i) {
-            if (prefix[i] != (byte) 0xFF) {
-                final byte[] prefixEnd = Arrays.copyOf(prefix, i + 1);
-                ++prefixEnd[i];
-                return prefixEnd;
-            }
+        final int length = getPrefixEndLength(prefix);
+        if (length == 0) {
+            return null;
+        }
+        final byte[] prefixEnd = Arrays.copyOf(prefix, length);
+        ++prefixEnd[length - 1];
+        return prefixEnd;
+    }
+
+    /**
+     * Returns the length of the key that {@link #getPrefixEnd} returns, or 
zero if there is none.
+     * That key is the prefix cut to this length, with its last byte 
incremented.
+     */

Review Comment:
   done



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