swamirishi commented on code in PR #4722:
URL: https://github.com/apache/ozone/pull/4722#discussion_r1236020233


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestRocksDbPersistentMap.java:
##########
@@ -131,4 +147,93 @@ public void testRocksDBPersistentMap() throws IOException, 
RocksDBException {
       }
     }
   }
+
+  /**
+   * Test cases for testRocksDBPersistentMapIterator.
+   */
+  private static Stream<Arguments> testRocksDBPersistentMapIteratorCases() {
+    return Stream.of(
+        Arguments.of(
+            Optional.empty(),
+            Optional.of("key202"),
+            Stream.concat(IntStream.range(0, 100).boxed(),
+                    IntStream.range(200, 300).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList()),
+            Stream.concat(IntStream.range(0, 100).boxed(),
+                    IntStream.range(200, 202).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList())),
+        Arguments.of(Optional.of("key050"),
+            Optional.empty(), Stream.concat(IntStream.range(50, 100).boxed(),
+                    IntStream.range(200, 300).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList()),
+            Stream.concat(IntStream.range(50, 100).boxed(),
+                    IntStream.range(200, 300).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList())
+            ),
+        Arguments.of(Optional.of("key050"),
+            Optional.of("key210"),
+            Stream.concat(IntStream.range(50, 100).boxed(),
+                    IntStream.range(200, 300).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList()),
+            Stream.concat(IntStream.range(50, 100).boxed(),
+                    IntStream.range(200, 210).boxed())
+                .map(i -> Pair.of(String.format("key%03d", i),
+                    String.format("value%03d", i)))
+                .collect(Collectors.toList())
+        ));
+  }
+
+  @ParameterizedTest
+  @MethodSource("testRocksDBPersistentMapIteratorCases")
+  public void testRocksDBPersistentMapIterator(Optional<String> lowerBound,
+              Optional<String> upperBound, List<Pair<String, String>> keys,
+              List<Pair<String, String>> expectedKeys)
+      throws IOException, RocksDBException {
+    ColumnFamilyHandle columnFamily = null;
+    try {
+      final CodecRegistry codecRegistry = CodecRegistry.newBuilder().build();
+      columnFamily = db.get().createColumnFamily(new ColumnFamilyDescriptor(
+          codecRegistry.asRawData("testMap" + id.incrementAndGet()),
+          columnFamilyOptions));
+
+      PersistentMap<String, String> persistentMap = new RocksDbPersistentMap<>(
+          db,
+          columnFamily,
+          codecRegistry,
+          String.class,
+          String.class
+      );
+
+      for (int i = 0; i < keys.size(); i++) {
+        String key = keys.get(i).getKey();
+        String value = keys.get(i).getValue();
+        persistentMap.put(key, value);
+      }
+      ClosableIterator<Map.Entry<String, String>> iterator =
+          persistentMap.iterator(lowerBound, upperBound);
+      int idx = 0;
+      while (iterator.hasNext()) {
+        Map.Entry<String, String> e = iterator.next();
+        Assertions.assertEquals(Pair.of(e.getKey(), e.getValue()),
+            expectedKeys.get(idx));
+        idx += 1;
+      }
+
+    } finally {
+      if (columnFamily != null) {
+        db.get().dropColumnFamily(columnFamily);

Review Comment:
   Add @Nonnull annotation in constructor.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/RocksDbPersistentMap.java:
##########
@@ -133,6 +164,15 @@ public V setValue(V value) {
       @Override
       public void close() {
         iterator.close();
+        if (readOptions != null) {
+          readOptions.close();
+        }
+        if (upperBound.isPresent()) {

Review Comment:
   done



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -367,6 +367,17 @@ private Set<String> getSSTFileListForSnapshot(OmSnapshot 
snapshot,
         .getPath(), tablesToLookUp);
   }
 
+  /**
+   * Gets the report key for a particular index of snapshot diff job.
+   * @param jobId Snapshot diff jobId
+   * @param index
+   * @return report Key of the snapshot diff job
+   */
+
+  static String getReportKeyForIndex(String jobId, long index) {
+    return String.format("%s%s%020d", jobId, DELIMITER, index);

Review Comment:
   done.



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