swamirishi commented on code in PR #4861:
URL: https://github.com/apache/ozone/pull/4861#discussion_r1223513527
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1293,39 +1294,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) {
Review Comment:
previous wouldn't be required in the case we seek to the value after
previous.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1293,39 +1294,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);
Review Comment:
Something like if previous snapshot is snap1 then we can append '\0' to
snap1 to make it 'snap1\0' which would be the next string in lexicographical
ordering.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1293,39 +1294,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)
throws IOException {
try (TableIterator<String, ? extends KeyValue<String, SnapshotInfo>>
snapshotIter = snapshotInfoTable.iterator()) {
KeyValue< String, SnapshotInfo> snapshotinfo;
- snapshotIter.seek(prefix);
- while (snapshotIter.hasNext()) {
+ snapshotIter.seek(previous);
+ while (snapshotIter.hasNext() && count < maxListResult) {
snapshotinfo = snapshotIter.next();
- if (snapshotinfo != null && snapshotinfo.getKey().startsWith(prefix)) {
+ if (snapshotinfo != null &&
+ snapshotinfo.getKey().compareTo(previous) == 0) {
Review Comment:
this check can be removed
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1293,39 +1294,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);
Review Comment:
We can probably append the '\0' (char with ascii value 0 to ignore the
previous value. So we wouldn't really have to check the previous it would be
ignored automatically
--
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]