[
https://issues.apache.org/jira/browse/FLINK-6210?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15948672#comment-15948672
]
ASF GitHub Bot commented on FLINK-6210:
---------------------------------------
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.
> RocksDB instance should be closed in ListViaMergeSpeedMiniBenchmark
> -------------------------------------------------------------------
>
> Key: FLINK-6210
> URL: https://issues.apache.org/jira/browse/FLINK-6210
> Project: Flink
> Issue Type: Bug
> Components: State Backends, Checkpointing
> Reporter: Ted Yu
> Assignee: fang yong
> Priority: Minor
>
> rocksDB instance should be closed upon returning from main().
> ListViaRangeSpeedMiniBenchmark has similar issue.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)