Github user shixiaogang commented on a diff in the pull request: https://github.com/apache/flink/pull/3652#discussion_r108869236 --- Diff: flink-contrib/flink-statebackend-rocksdb/src/test/java/org/apache/flink/contrib/streaming/state/benchmark/ListViaRangeSpeedMiniBenchmark.java --- @@ -54,59 +54,62 @@ public static void main(String[] args) throws Exception { final RocksDB rocksDB = RocksDB.open(options, rocksDir.getAbsolutePath()); - final String key = "key"; - final String value = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ7890654321"; + try { + final String key = "key"; + final String value = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ7890654321"; - final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); - final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8); + final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); + final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8); - final byte[] keyTemplate = Arrays.copyOf(keyBytes, keyBytes.length + 4); + final byte[] keyTemplate = Arrays.copyOf(keyBytes, keyBytes.length + 4); - final Unsafe unsafe = MemoryUtils.UNSAFE; - final long offset = unsafe.arrayBaseOffset(byte[].class) + keyTemplate.length - 4; + final Unsafe unsafe = MemoryUtils.UNSAFE; + final long offset = unsafe.arrayBaseOffset(byte[].class) + keyTemplate.length - 4; - final int num = 50000; - System.out.println("begin insert"); + final int num = 50000; + System.out.println("begin insert"); - final long beginInsert = System.nanoTime(); - for (int i = 0; i < num; i++) { - unsafe.putInt(keyTemplate, offset, i); - rocksDB.put(write_options, keyTemplate, valueBytes); - } - final long endInsert = System.nanoTime(); - System.out.println("end insert - duration: " + ((endInsert - beginInsert) / 1_000_000) + " ms"); - - final byte[] resultHolder = new byte[num * valueBytes.length]; - - final long beginGet = System.nanoTime(); - - final RocksIterator iterator = rocksDB.newIterator(); - int pos = 0; - - // seek to start - unsafe.putInt(keyTemplate, offset, 0); - iterator.seek(keyTemplate); - - // mark end - unsafe.putInt(keyTemplate, offset, -1); - - // iterate - while (iterator.isValid()) { - byte[] currKey = iterator.key(); - if (samePrefix(keyBytes, currKey)) { - byte[] currValue = iterator.value(); - System.arraycopy(currValue, 0, resultHolder, pos, currValue.length); - pos += currValue.length; - iterator.next(); + final long beginInsert = System.nanoTime(); + for (int i = 0; i < num; i++) { + unsafe.putInt(keyTemplate, offset, i); + rocksDB.put(write_options, keyTemplate, valueBytes); } - else { - break; + final long endInsert = System.nanoTime(); + System.out.println("end insert - duration: " + ((endInsert - beginInsert) / 1_000_000) + " ms"); + + final byte[] resultHolder = new byte[num * valueBytes.length]; + + final long beginGet = System.nanoTime(); + + final RocksIterator iterator = rocksDB.newIterator(); --- End diff -- The iterator should be closed once it's not used. So it's better to use try-with-resources here.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---