diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java index 4702d3a978..9bf6c7842e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java @@ -924,26 +924,26 @@ protected static boolean indexFieldValuesUnmatched(byte[] value, return false; } - public static final byte[] increaseOne(byte[] bytes) { + public static void increaseOne(byte[] bytes) { final byte BYTE_MAX_VALUE = (byte) 0xff; + final byte INCREASE_STEP = 0x01; assert bytes.length > 0; byte last = bytes[bytes.length - 1]; if (last != BYTE_MAX_VALUE) { - bytes[bytes.length - 1] += 0x01; + bytes[bytes.length - 1] += INCREASE_STEP; } else { // Process overflow (like [1, 255] => [2, 0]) int i = bytes.length - 1; for (; i > 0 && bytes[i] == BYTE_MAX_VALUE; --i) { - bytes[i] += 0x01; + bytes[i] += INCREASE_STEP; } if (bytes[i] == BYTE_MAX_VALUE) { assert i == 0; throw new BackendException("Unable to increase bytes: %s", Bytes.toHex(bytes)); } - bytes[i] += 0x01; + bytes[i] += INCREASE_STEP; } - return bytes; } @Override diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStdSessions.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStdSessions.java index 06652152cd..81eb76836b 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStdSessions.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStdSessions.java @@ -744,11 +744,11 @@ public static TableFormatConfig initTableConfig(HugeConfig conf) { return tableConfig; } - public static final byte[] encode(String string) { + public static byte[] encode(String string) { return StringEncoding.encode(string); } - public static final String decode(byte[] bytes) { + public static String decode(byte[] bytes) { return StringEncoding.decode(bytes); } @@ -758,7 +758,7 @@ public static final String decode(byte[] bytes) { private final class StdSession extends RocksDBSessions.Session { private WriteBatch batch; - private WriteOptions writeOptions; + private final WriteOptions writeOptions; public StdSession(HugeConfig conf) { this.batch = new WriteBatch(); @@ -955,8 +955,8 @@ public void deleteSingle(String table, byte[] key) { @Override public void deletePrefix(String table, byte[] key) { byte[] keyFrom = key; - byte[] keyTo = Arrays.copyOf(key, key.length); - keyTo = BinarySerializer.increaseOne(keyTo); + byte[] keyTo = Arrays.copyOf(keyFrom, keyFrom.length); + BinarySerializer.increaseOne(keyTo); try (CFHandle cf = cf(table)) { this.batch.deleteRange(cf.get(), keyFrom, keyTo); } catch (RocksDBException e) { diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java index c55d92e331..7b6137203a 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -182,7 +183,7 @@ protected List olapTables() { } protected List tableNames(HugeType type) { - return type != HugeType.OLAP ? Arrays.asList(this.table(type).table()) : + return type != HugeType.OLAP ? Collections.singletonList(this.table(type).table()) : this.olapTables(); } @@ -287,7 +288,7 @@ private void shutdownOpenPool(ExecutorService openPool) { "open-pool"); } - boolean terminated = false; + boolean terminated; openPool.shutdown(); try { terminated = openPool.awaitTermination(OPEN_TIMEOUT, @@ -803,24 +804,11 @@ private void useSessions() { } } - private void closeSessions() { - Iterator> iter = this.dbs.entrySet() - .iterator(); - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - RocksDBSessions sessions = entry.getValue(); - boolean closed = sessions.close(); - if (closed) { - iter.remove(); - } - } - } - private List session() { this.checkOpened(); if (this.tableDiskMapping.isEmpty()) { - return Arrays.asList(this.sessions.session()); + return Collections.singletonList(this.sessions.session()); } // Collect session of each table with optimized disk @@ -832,6 +820,19 @@ private List session() { return list; } + private void closeSessions() { + Iterator> iter = this.dbs.entrySet() + .iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + RocksDBSessions sessions = entry.getValue(); + boolean closed = sessions.close(); + if (closed) { + iter.remove(); + } + } + } + private Collection sessions() { return this.dbs.values(); } @@ -1094,7 +1095,7 @@ public void clearOlapTable(Id id) { String name = this.olapTableName(id); RocksDBTable table = this.table(name); RocksDBSessions db = this.db(HugeType.OLAP); - if (table == null || !db.existsTable(table.table())) { + if (!db.existsTable(table.table())) { throw new HugeException("Not exist table '%s''", name); } this.dropTable(db, table.table()); @@ -1106,7 +1107,7 @@ public void removeOlapTable(Id id) { String name = this.olapTableName(id); RocksDBTable table = this.table(name); RocksDBSessions db = this.db(HugeType.OLAP); - if (table == null || !db.existsTable(table.table())) { + if (!db.existsTable(table.table())) { throw new HugeException("Not exist table '%s''", name); } this.dropTable(db, table.table()); diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTable.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTable.java index e87316b8ec..c173fac70d 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTable.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTable.java @@ -291,9 +291,8 @@ public boolean isOlap() { return false; } - protected static final BackendEntryIterator newEntryIterator( - BackendColumnIterator cols, - Query query) { + protected static BackendEntryIterator newEntryIterator(BackendColumnIterator cols, + Query query) { return new BinaryEntryIterator<>(cols, query, (entry, col) -> { if (entry == null || !entry.belongToMe(col)) { HugeType type = query.resultType(); @@ -307,7 +306,7 @@ protected static final BackendEntryIterator newEntryIterator( }); } - protected static final long sizeOfBackendEntry(BackendEntry entry) { + protected static long sizeOfBackendEntry(BackendEntry entry) { return BinaryEntryIterator.sizeOfEntry(entry); } diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTables.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTables.java index c4b69d3852..7d399dff1d 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTables.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTables.java @@ -334,7 +334,7 @@ protected BackendColumnIterator queryByCond(Session session, E.checkArgumentNotNull(min, "Range index begin key is missing"); byte[] begin = min.asBytes(); if (!minEq) { - begin = BinarySerializer.increaseOne(begin); + BinarySerializer.increaseOne(begin); } if (max == null) { diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java index 69e9951dba..fc31b7e284 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java @@ -184,7 +184,7 @@ public String hardLinkSnapshot(String snapshotPath) } @Override - public void reloadRocksDB() throws RocksDBException { + public void reloadRocksDB() { throw new UnsupportedOperationException("reloadRocksDB"); } @@ -235,7 +235,7 @@ protected synchronized void doClose() { */ private final class SstSession extends Session { - private Map batch; + private final Map batch; public SstSession() { this.batch = new HashMap<>();