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


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1345,30 +1345,30 @@ public List<SnapshotInfo> listSnapshot(
     } else {
       // This allows us to seek directly to the first key with the right 
prefix.
       seek = getOzoneKey(volumeName, bucketName,
-          StringUtil.isNotBlank(
-              snapshotPrefix) ? snapshotPrefix : OM_KEY_PREFIX);
+          StringUtil.isNotBlank(snapshotPrefix) ? snapshotPrefix : 
OM_KEY_PREFIX);
     }
 
     List<SnapshotInfo> snapshotInfos =  Lists.newArrayList();
+    String lastSnapshot = null;
     try (ListIterator.MinHeapIterator snapshotIterator =
-        new ListIterator.MinHeapIterator(this, prefix, seek, volumeName,
-            bucketName, snapshotInfoTable)) {
-      try {
-        while (snapshotIterator.hasNext() && maxListResult > 0) {
-          SnapshotInfo snapshotInfo =
-              (SnapshotInfo) snapshotIterator.next().getValue();
-          if (!snapshotInfo.getName().equals(prevSnapshot)) {
-            snapshotInfos.add(snapshotInfo);
-            maxListResult--;
-          }
+             new ListIterator.MinHeapIterator(this, prefix, seek, volumeName, 
bucketName, snapshotInfoTable)) {
+      SnapshotInfo snapshotInfo = null;
+      while (snapshotIterator.hasNext() && maxListResult > 0) {
+        snapshotInfo = (SnapshotInfo) snapshotIterator.next().getValue();
+        if (!Objects.equals(snapshotInfo.getName(), prevSnapshot)) {
+          snapshotInfos.add(snapshotInfo);
+          maxListResult--;
         }
-      } catch (NoSuchElementException e) {
-        throw new IOException(e);
-      } catch (UncheckedIOException e) {
-        throw e.getCause();
       }
+      if (snapshotIterator.hasNext() && maxListResult == 0 && snapshotInfo != 
null) {
+        lastSnapshot = snapshotInfo.getName();
+      }
+    } catch (NoSuchElementException e) {
+      throw new IOException(e);
+    } catch (UncheckedIOException e) {
+      throw e.getCause();
     }
-    return snapshotInfos;
+    return new ListSnapshotResponse(snapshotInfos, lastSnapshot);

Review Comment:
   You are right as of now.
   
   One benefit, I see with passing `lastSnapshot` rather than boolean, is if we 
change the key for the table (tho you can argue it is unlikely). Returning the 
continuation token decouples the logic and can be changed at any time.
   
   Returning the continuation is similar to standard pagination API e.g. 
[DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.Pagination.html)
 or 
[api-pagination-best-practices-and-strategies](https://dev.to/pragativerma18/unlocking-the-power-of-api-pagination-best-practices-and-strategies-4b49)



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