smengcl commented on code in PR #4436:
URL: https://github.com/apache/ozone/pull/4436#discussion_r1143866184
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotCreateRequest.java:
##########
@@ -77,6 +78,7 @@ public class TestOMSnapshotCreateRequest {
private String volumeName;
private String bucketName;
private String snapshotName;
+ private String snapshotName2;
Review Comment:
```suggestion
private String snapshotName1;
private String snapshotName2;
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java:
##########
@@ -230,14 +230,22 @@ String.class, new StringCodec(), OmKeyInfo.class,
SnapshotInfo.class,
new OmDBSnapshotInfoCodec());
- public static final DBColumnFamilyDefinition<String, OmKeyRenameInfo>
- RENAMED_KEY_TABLE =
+ /** <p> SnapshotRenamedKeyTable that complements the keyTable (or fileTable)
+ * entries of the immediately previous snapshot in the same snapshot
+ * scope. (bucket or volume) </p>
+ * <p> Key renames between the two subsequent snapshots are captured, this
+ * information is used in {@link SnapshotDeletingService} to check if the
+ * renamedKey is present in the previous snapshot's keyTable
+ * (or fileTable)</p>
+ */
+ public static final DBColumnFamilyDefinition<String, String>
Review Comment:
Reformat the javadoc a bit.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequestUtils.java:
##########
@@ -47,4 +60,42 @@ public static void checkClientRequestPrecondition(
OMException.ResultCodes.INTERNAL_ERROR);
}
}
+
+ public static boolean isSnapshotBucket(OMMetadataManager omMetadataManager,
+ OmKeyInfo keyInfo) throws IOException {
+
+ String dbSnapshotBucketKey = omMetadataManager.getBucketKey(
+ keyInfo.getVolumeName(), keyInfo.getBucketName())
+ + OM_KEY_PREFIX;
+
+ return checkInSnapshotCache(omMetadataManager, dbSnapshotBucketKey) ||
+ checkInSnapshotDB(omMetadataManager, dbSnapshotBucketKey);
+ }
+
+ private static boolean checkInSnapshotDB(OMMetadataManager omMetadataManager,
+ String dbSnapshotBucketKey) throws IOException {
+ try (TableIterator<String, ? extends Table.KeyValue<String, SnapshotInfo>>
+ iterator = omMetadataManager.getSnapshotInfoTable().iterator()) {
+ iterator.seek(dbSnapshotBucketKey);
+ return iterator.hasNext() && iterator.next().getKey()
+ .startsWith(dbSnapshotBucketKey);
+ }
+ }
+
+ private static boolean checkInSnapshotCache(
+ OMMetadataManager omMetadataManager,
+ String dbSnapshotBucketKey) {
+ Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> cacheIter =
+ omMetadataManager.getSnapshotInfoTable().cacheIterator();
+
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> cacheKeyValue =
+ cacheIter.next();
+ String key = cacheKeyValue.getKey().getCacheKey();
+ if (key.startsWith(dbSnapshotBucketKey)) {
+ return true;
+ }
Review Comment:
Not only do we need to check for cache entry existence. We also need to
check whether the entry is a tombstone entry (cache entry value is `null`) in
cache.
If it is a tombstone, should return `false`.
--
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]