swamirishi commented on code in PR #4944:
URL: https://github.com/apache/ozone/pull/4944#discussion_r1236151802
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -854,26 +860,33 @@ void addToObjectIdMap(Table<String, ? extends
WithObjectID> fsTable,
: sstFileReader.getKeyStream()) {
keysToCheck.forEach(key -> {
try {
- final WithObjectID oldKey = fsTable.get(key);
- final WithObjectID newKey = tsTable.get(key);
- if (areKeysEqual(oldKey, newKey) || !isKeyInBucket(key,
tablePrefixes,
- fsTable.getName())) {
+ final WithObjectID fromObjectId = fsTable.get(key);
+ final WithObjectID toObjectId = tsTable.get(key);
+ if (areKeysEqual(fromObjectId, toObjectId) || !isKeyInBucket(key,
+ tablePrefixes, fsTable.getName())) {
// We don't have to do anything.
return;
}
- if (oldKey != null) {
- byte[] rawObjId = codecRegistry.asRawData(oldKey.getObjectID());
+ if (fromObjectId != null) {
+ byte[] rawObjId = codecRegistry.asRawData(
+ fromObjectId.getObjectID());
byte[] rawValue = codecRegistry.asRawData(
- getKeyOrDirectoryName(isDirectoryTable, oldKey));
+ getKeyOrDirectoryName(isDirectoryTable, fromObjectId));
oldObjIdToKeyMap.put(rawObjId, rawValue);
- objectIDsToCheck.add(rawObjId);
+ SnapshotDiffObject diffObject =
Review Comment:
why do we need this map? Why not keep it as a set we already have the key
name in oldObjIdToKeyMap & newObjIdToKeyMap, instead of getting & updating it.
BTW oldObjIDToKeyMap & newObjIdtoKeyMap will have the key name without the
prefix as part of the absolute path resolution PR.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1040,7 +1078,19 @@ long generateDiffReport(final String jobId,
SnapshotDiffReportOzone.getDiffReportEntry(DiffType.MODIFY,
key);
modifyDiffs.add(codecRegistry.asRawData(entry));
- } else { // Key Renamed.
+ } else if (!isBlockLocationSame(snapshotDiffObject.getOldKeyName(),
+ snapshotDiffObject.getNewKeyName(), fsTable, tsTable)) {
+ String oldKey = codecRegistry.asObject(oldKeyName, String.class);
+ String newKey = codecRegistry.asObject(newKeyName, String.class);
+ renameDiffs.add(codecRegistry.asRawData(
Review Comment:
it need not be rename every time. We need to check if oldKey != newKeyName
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1102,6 +1152,50 @@ long generateDiffReport(final String jobId,
}
}
+ private boolean isBlockLocationSame(
+ String fromObjectName,
+ String toObjectName,
+ final Table<String, ? extends WithObjectID> fromSnapshotTable,
+ final Table<String, ? extends WithObjectID> toSnapshotTable
+ ) throws IOException {
+
+ if (fromObjectName == null && toObjectName == null) {
+ LOG.debug("fromObjectName and toObjectName are null.");
+ return true;
+ }
+
+ if (fromObjectName == null || toObjectName == null) {
+ LOG.debug("fromObjectName: '{}' or toObjectName: '{}' is null.",
+ fromObjectName, toObjectName);
+ return false;
+ }
+
+ final WithObjectID fromObject = fromSnapshotTable.get(fromObjectName);
+ final WithObjectID toObject = toSnapshotTable.get(toObjectName);
+
+ if (fromObject == null && toObject == null) {
+ LOG.debug("fromObject and toObject both are null.");
+ return true;
+ }
+
+ if (fromObject == null || toObject == null) {
+ LOG.debug("fromObject: '{}' or toObject: '{}' is null.",
+ fromObject, toObject);
+ return false;
+ }
+
+ if (!(fromObject instanceof OmKeyInfo) ||
+ !(toObject instanceof OmKeyInfo)) {
+ LOG.debug("fromObject is instance of '{}' and toObject is of '{}'.",
+ fromObject.getClass().getSimpleName(),
+ toObject.getClass().getSimpleName());
+ return false;
+ }
+
+ return SnapshotDeletingService.isBlockLocationInfoSame(
Review Comment:
We can directly call this function for fromObject & toObject. We need not
check the above if cases.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffObject.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.snapshot;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hadoop.hdds.utils.db.Codec;
+
+import java.io.IOException;
+
+/**
+ * SnapshotDiffObject to keep objectId, key's oldName and newName.
+ */
+public class SnapshotDiffObject {
Review Comment:
I guess this is not required because of the above comments
--
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]