hemantk-12 commented on code in PR #3784:
URL: https://github.com/apache/ozone/pull/3784#discussion_r1014517372


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1157,6 +1157,69 @@ public List<RepeatedOmKeyInfo> listTrash(String 
volumeName, String bucketName,
     return deletedKeys;
   }
 
+  @Override
+  public List<SnapshotInfo> listSnapshot(String volumeName, String bucketName)

Review Comment:
   We are not using `volumeName` and `bucketName`. Don't we have to filter out 
response based on them? 



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1125,6 +1125,69 @@ public List<RepeatedOmKeyInfo> listTrash(String 
volumeName, String bucketName,
     return deletedKeys;
   }
 
+  @Override
+  public List<SnapshotInfo> listSnapshot(String volumeName, String bucketName)
+      throws IOException {
+    if (Strings.isNullOrEmpty(volumeName)) {
+      throw new OMException("Volume name is required.",
+          ResultCodes.VOLUME_NOT_FOUND);
+    }
+
+    if (Strings.isNullOrEmpty(bucketName)) {
+      throw new OMException("Bucket name is required.",
+          ResultCodes.BUCKET_NOT_FOUND);
+    }
+
+    List<SnapshotInfo> snapshotInfos = new ArrayList<>();
+    TreeMap<String, SnapshotInfo> snapshotInfoMap = new TreeMap<>();
+
+    snapshotInfoMap.putAll(getSnapshotFromCache());
+    snapshotInfoMap.putAll(getSnapshotFromDB());
+
+    for (Map.Entry<String, SnapshotInfo> cacheKey : snapshotInfoMap
+        .entrySet()) {
+      snapshotInfos.add(cacheKey.getValue());
+    }
+
+    return snapshotInfos;
+  }
+
+  private TreeMap<String, SnapshotInfo> getSnapshotFromCache() {
+    TreeMap<String, SnapshotInfo> result = new TreeMap<>();
+    Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> iterator =
+        snapshotInfoTable.cacheIterator();
+    while (iterator.hasNext()) {
+      Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> entry =
+          iterator.next();
+      String snapshotKey = entry.getKey().getCacheKey();
+      SnapshotInfo snapshotInfo = entry.getValue().getCacheValue();
+      if (snapshotInfo != null) {
+        result.put(snapshotKey, snapshotInfo);
+      }
+    }
+    return result;
+  }
+
+  private TreeMap<String, SnapshotInfo> getSnapshotFromDB() throws IOException 
{
+    TreeMap<String, SnapshotInfo> result = new TreeMap<>();
+    try (TableIterator<String, ? extends KeyValue<String, SnapshotInfo>>
+             snapshotIter = snapshotInfoTable.iterator()) {
+      KeyValue< String, SnapshotInfo> snapshotinfo;
+      while (snapshotIter.hasNext()) {
+        snapshotinfo = snapshotIter.next();
+        if (snapshotinfo != null) {
+          CacheValue<SnapshotInfo> cacheValue =
+              snapshotInfoTable.getCacheValue(
+                  new CacheKey<>(snapshotinfo.getKey()));
+          if (cacheValue == null) {

Review Comment:
   1. Does cache get updated when new entries are added to DB?
   2. What if key got evicted in between `appendSnapshotFromCacheToMap` and 
`appendSnapshotFromDBToMap`? Why not just all the entries from the DB? Would it 
be cleaner and better approach?



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