bharatviswa504 commented on a change in pull request #654: HDDS-3150. Implement 
getIfExist in Table and use it in CreateKey/File
URL: https://github.com/apache/hadoop-ozone/pull/654#discussion_r390670650
 
 

 ##########
 File path: 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
 ##########
 @@ -155,6 +155,32 @@ public boolean isExist(byte[] key) throws IOException {
     }
   }
 
+  @Override
+  public byte[] getIfExist(byte[] key) throws IOException {
+    try {
+      // RocksDB#keyMayExist
+      // 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);
+      if (keyMayExist) {
+        // Not using out value from string builder, as that is causing
+        // IllegalArgumentException during protobuf parsing.
 
 Review comment:
   ```
   @Override
   public byte[] get(byte[] key) throws IOException {
     try {
       // RocksDB#keyMayExist
       // If the key definitely does not exist in the database, then this
       // method returns false, else true.
       rdbMetrics.incNumDBKeyIfExistChecks();
       StringBuilder outValue = new StringBuilder();
       boolean keyMayExist = db.keyMayExist(handle, key, outValue);
       if (keyMayExist) {
         byte[] val;
         if (outValue.length() > 0) {
           val = outValue.toString().getBytes(UTF_8);
         } else {
           val = db.get(handle, key);
         }
         if (val != null) {
           rdbMetrics.incNumDBKeyIfExistMisses();
         }
         return val;
       }
       return null;
     } catch (RocksDBException e) {
       throw toIOException(
           "Error in accessing DB. ", e);
     }
   }
   ```
   
   I tried with the above code, getting IllegalException during parsing. So, 
for now, removed not to use outVal.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to