Github user bowenli86 commented on a diff in the pull request: https://github.com/apache/flink/pull/4722#discussion_r140908693 --- Diff: flink-contrib/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBKeyedStateBackend.java --- @@ -252,6 +257,43 @@ public RocksDBKeyedStateBackend( LOG.debug("Setting initial keyed backend uid for operator {} to {}.", this.operatorIdentifier, this.backendUID); } + @Override + public <N> Stream<K> getKeys(String field, N namespace) { + Tuple2<ColumnFamilyHandle, ?> columnInfo = kvStateInformation.get(field); + if (columnInfo == null) { + return Stream.empty(); + } + + RocksIterator iterator = db.newIterator(columnInfo.f0); + iterator.seekToFirst(); + + Iterator<K> sourceIterator = new Iterator<K>() { + @Override + public boolean hasNext() { + return iterator.isValid(); + } + + @Override + public K next() { + try { + byte[] key = iterator.key(); + + DataInputViewStreamWrapper dataInput = new DataInputViewStreamWrapper( + new ByteArrayInputStreamWithPos(key, keyGroupPrefixBytes, key.length - keyGroupPrefixBytes)); + K value = keySerializer.deserialize(dataInput); + iterator.next(); --- End diff -- This will throw exceptions implicitly if `iterator` doesn't have any more elements. I'd rather have it fail early and faster by checking `iterator.hasNext()` first and throwing exceptions explicitly.
---