nandakumar131 commented on a change in pull request #3176:
URL: https://github.com/apache/ozone/pull/3176#discussion_r832793846



##########
File path: 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
##########
@@ -57,6 +57,7 @@
   private final ColumnFamilyHandle handle;
   private final WriteOptions writeOptions;
   private final RDBMetrics rdbMetrics;
+  private int prefixLength;

Review comment:
       We don't need to have _prefixLength_ associated with RDBTable. Prefix is 
something which should be passed as an argument. It is not applicable at table 
level.
   
   For _getRangeKVs_ calls we can use _MetadataKeyFilters.MetadataKeyFilter_ 
for passing prefix to be matched.
   
   If we need the Iterator optimized prefix filter to be used, we can add a new 
_getSequentialRangeKVs_ method which also takes prefix as an argument. (Since 
we cannot use _MetadataKeyFilters.MetadataKeyFilter_ as prefix filter for 
Iterator creation)

##########
File path: 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/Table.java
##########
@@ -153,6 +153,20 @@ default VALUE getReadCopy(KEY key) throws IOException {
    */
   TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> iterator();
 
+  /**
+   * Returns a prefixed iterator for this metadata store.
+   * @param prefix
+   * @return
+   */
+  TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> iterator(KEY prefix)
+      throws IOException;
+
+  /**
+   * Set the fixed key prefix length.
+   * @param length
+   */
+  void setFixedPrefixLength(int length);

Review comment:
       We should not set prefix length at _Table_ level.

##########
File path: 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java
##########
@@ -69,7 +81,9 @@ private void setCurrentEntry() {
 
   @Override
   public boolean hasNext() {
-    return rocksDBIterator.isValid();
+    return rocksDBIterator.isValid() &&
+        (prefix == null || Arrays.equals(
+            Arrays.copyOf(rocksDBIterator.key(), prefix.length), prefix));

Review comment:
       Can we avoid _Arrays.copyOf_ here as the value is not modified/passed 
outside. We can implement our own comparison logic instead.
   ```suggestion
   private static boolean startsWith(byte[] prefix, byte[] value) {
       if (prefix==null)
           return true;
       if (value==null)
           return false;
   
       int length = prefix.length;
       if (value.length < length)
           return false;
   
       for (int i=0; i<length; i++)
           if (prefix[i] != value[i])
               return false;
   
       return true;
   }
   
   ```




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to