prashantpogde commented on code in PR #4065:
URL: https://github.com/apache/ozone/pull/4065#discussion_r1109081015
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1197,39 +1198,69 @@ public List<SnapshotInfo> listSnapshot(String
volumeName, String bucketName)
BUCKET_NOT_FOUND);
}
- String prefix = getBucketKey(volumeName, bucketName + OM_KEY_PREFIX);
+ String prefix;
+ if (StringUtil.isNotBlank(snapshotPrefix)) {
+ prefix = getOzoneKey(volumeName, bucketName, snapshotPrefix);
+ } else {
+ prefix = getBucketKey(volumeName, bucketName + OM_KEY_PREFIX);
+ }
+
+ String seek;
+ if (StringUtil.isNotBlank(prevSnapshot)) {
+ // Seek to the specified snapshot.
+ seek = getOzoneKey(volumeName, bucketName, prevSnapshot);
+ } 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);
+ }
+
TreeMap<String, SnapshotInfo> snapshotInfoMap = new TreeMap<>();
- appendSnapshotFromCacheToMap(snapshotInfoMap, prefix);
- appendSnapshotFromDBToMap(snapshotInfoMap, prefix);
+ int count = appendSnapshotFromCacheToMap(
+ snapshotInfoMap, prefix, seek, maxListResult);
+ appendSnapshotFromDBToMap(
+ snapshotInfoMap, prefix, seek, count, maxListResult);
return new ArrayList<>(snapshotInfoMap.values());
}
- private void appendSnapshotFromCacheToMap(
- TreeMap snapshotInfoMap, String prefix) {
+ private int appendSnapshotFromCacheToMap(
+ TreeMap snapshotInfoMap, String prefix,
+ String previous, int maxListResult) {
+ int count = 0;
Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> iterator =
snapshotInfoTable.cacheIterator();
- while (iterator.hasNext()) {
+ while (iterator.hasNext() && count < maxListResult) {
Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> entry =
iterator.next();
String snapshotKey = entry.getKey().getCacheKey();
SnapshotInfo snapshotInfo = entry.getValue().getCacheValue();
- if (snapshotInfo != null && snapshotKey.startsWith(prefix)) {
+ if (snapshotInfo != null && snapshotKey.startsWith(prefix) &&
+ snapshotKey.compareTo(previous) > 0) {
snapshotInfoMap.put(snapshotKey, snapshotInfo);
+ count++;
}
}
+ return count;
}
- private void appendSnapshotFromDBToMap(TreeMap snapshotInfoMap, String
prefix)
+ private void appendSnapshotFromDBToMap(TreeMap snapshotInfoMap,
+ String prefix, String previous,
+ int count, int maxListResult)
Review Comment:
We are just reading from the SnapshotInfo Table here. This may not
necessarily be Snapshot creation order/. Can you please check this ?
--
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]