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


##########
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:
   Initially integration tests were failing so I added that.  I removed the 
redundant null checks from here and change it to exception because we should 
not be in the situation.



##########
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:
   The current scenario is not wrong because if it is coming to [if 
(!isBlockLocationSame(snapshotDiffObject.getOldKeyName(),
                 snapshotDiffObject.getNewKeyName(), fsTable, 
tsTable))](https://github.com/apache/ozone/pull/4944/files#diff-46f82d5fbac5dc7aae1fc363811fb88e6bc6c89a2aefafddad90de2f1ff3cfbdR1081)
 which is means it is not just override, it is also rename. If it is just 
override that it will fall into the previous [if (Arrays.equals(oldKeyName, 
newKeyName))](https://github.com/apache/ozone/pull/4944/files#diff-46f82d5fbac5dc7aae1fc363811fb88e6bc6c89a2aefafddad90de2f1ff3cfbdR1075).
 
                 
   Anyways, I changed it to following:
   ``` 
             } else {
               String oldKey = codecRegistry.asObject(oldKeyName, String.class);
               String newKey = codecRegistry.asObject(newKeyName, String.class);
               renameDiffs.add(codecRegistry.asRawData(
                   SnapshotDiffReportOzone.getDiffReportEntry(DiffType.RENAME,
                       oldKey, newKey)));
               if (!isBlockLocationSame(snapshotDiffObject.getOldKeyName(),
                   snapshotDiffObject.getNewKeyName(), fsTable, tsTable)) {
                 // Here, oldKey name is returned as modified. Modified key 
name is
                 // based on base snapshot (from snapshot).
                 renameDiffs.add(codecRegistry.asRawData(
                     SnapshotDiffReportOzone.getDiffReportEntry(DiffType.MODIFY,
                         oldKey)));
               }
             }
   ```



##########
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:
   Same as https://github.com/apache/ozone/pull/4944/files#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:
   `oldObjIDToKeyMap` and `newObjIdtoKeyMap` only contains the [key name or dir 
name](https://github.com/apache/ozone/blob/master/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java#L967-L968)
 not full with prefix. To get the object to compare block information, full key 
name with prefix is need to get it form the table: 
https://github.com/apache/ozone/pull/4944/files#diff-46f82d5fbac5dc7aae1fc363811fb88e6bc6c89a2aefafddad90de2f1ff3cfbdR1173-R1174
   



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

Review Comment:
   Change it to, because `if (!Arrays.equals(oldKeyName, newKeyName))` is not 
need. It is checked 
[here](https://github.com/apache/ozone/pull/4944/files#diff-46f82d5fbac5dc7aae1fc363811fb88e6bc6c89a2aefafddad90de2f1ff3cfbdR1075)
 if names are equal or not. It came to this point because they are not.
   
   ```
               String oldKey = codecRegistry.asObject(oldKeyName, String.class);
               String newKey = codecRegistry.asObject(newKeyName, String.class);
               renameDiffs.add(codecRegistry.asRawData(
                   SnapshotDiffReportOzone.getDiffReportEntry(DiffType.RENAME,
                       oldKey, newKey)));
               if (!isBlockLocationSame(snapshotDiffObject.getOldKeyName(),
                   snapshotDiffObject.getNewKeyName(), fsTable, tsTable)) {
                 // Here, oldKey name is returned as modified. Modified key 
name is
                 // based on base snapshot (from snapshot).
                 renameDiffs.add(codecRegistry.asRawData(
                     SnapshotDiffReportOzone.getDiffReportEntry(DiffType.MODIFY,
                         oldKey)));
               }
   ```



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