diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java index eb181bf0a022..2e390e2362d1 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java @@ -26,6 +26,7 @@ import org.apache.hadoop.hdds.StringUtils; import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.Holder; import org.rocksdb.ReadOptions; import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; @@ -128,11 +129,12 @@ public boolean isExist(byte[] key) throws IOException { // If the key definitely does not exist in the database, then this // method returns false, else true. rdbMetrics.incNumDBKeyMayExistChecks(); - StringBuilder outValue = new StringBuilder(); + Holder outValue = new Holder<>(); boolean keyMayExist = db.keyMayExist(handle, key, outValue); if (keyMayExist) { - boolean keyExists = (outValue.length() > 0) || - (db.get(handle, key) != null); + boolean keyExists = + (outValue.getValue() != null && outValue.getValue().length > 0) || + (db.get(handle, key) != null); if (!keyExists) { rdbMetrics.incNumDBKeyMayExistMisses(); } @@ -162,8 +164,7 @@ public byte[] getIfExist(byte[] key) throws IOException { // If the key definitely does not exist in the database, then this // method returns false, else true. rdbMetrics.incNumDBKeyGetIfExistChecks(); - StringBuilder outValue = new StringBuilder(); - boolean keyMayExist = db.keyMayExist(handle, key, outValue); + boolean keyMayExist = db.keyMayExist(handle, key, null); if (keyMayExist) { // Not using out value from string builder, as that is causing // IllegalArgumentException during protobuf parsing. diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java index d640c4a97ac8..600c48f3e8a9 100644 --- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java +++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java @@ -315,7 +315,7 @@ public void testRocksDBKeyMayExistApi() throws Exception { for (int i = 0; i < 50; i++) { Assert.assertFalse(db.keyMayExist( org.apache.commons.codec.binary.StringUtils - .getBytesUtf16("key" + i), new StringBuilder())); + .getBytesUtf16("key" + i), null)); } end = System.nanoTime(); long keyMayExistLatency = end - start; diff --git a/pom.xml b/pom.xml index a676996ddf8a..766342662f30 100644 --- a/pom.xml +++ b/pom.xml @@ -1586,7 +1586,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs org.rocksdb rocksdbjni - 6.6.4 + 6.8.1 org.xerial