azagrebin commented on a change in pull request #6638: [FLINK-10267][State] Fix arbitrary iterator access on RocksDBMapIterator URL: https://github.com/apache/flink/pull/6638#discussion_r214344987
########## File path: flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBMapState.java ########## @@ -595,6 +595,8 @@ private void loadCache() { */ if (lastEntry != null && !lastEntry.deleted) { iterator.next(); + cacheEntries.add(lastEntry); + cacheIndex = 1; Review comment: Could be also just: ``` if (lastEntry != null && !lastEntry.deleted) { cacheIndex = 1; } ``` This should work in general. I wonder if we could make it cleaner. Although, the remove operation is not supposed to be called twice for the same next, if it happens and `lastEntry.deleted` is true, the problem will stay. What if we cache always the previously returned value in `nextEntry()` as a class field: ``` previousEntry = cacheEntries.get(cacheIndex); ``` then remove could be: ``` @Override public void remove() { if (previousEntry == null) { throw new IllegalStateException("The remove operation must be called after a valid next operation."); } if (!previousEntry.deleted) { previousEntry.remove(); } } ``` What do you think? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services