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


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1154,10 +1155,7 @@ void addToObjectIdMap(Table<String, ? extends 
WithParentObjectId> fsTable,
             byte[] rawValue = codecRegistry.asRawData(
                 key.substring(tablePrefix.length()));
             oldObjIdToKeyMap.put(rawObjId, rawValue);
-            SnapshotDiffObject diffObject =
-                createDiffObjectWithOldName(fromObjectId.getObjectID(), key,

Review Comment:
   Please remove `createDiffObjectWithOldName` and 
`createDiffObjectWithNewName`. These are not used anymore if I'm not wrong.
   
   Same goes for class: `SnapshotDiffObject`.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1128,6 +1128,7 @@ void addToObjectIdMap(Table<String, ? extends 
WithParentObjectId> fsTable,
     String tablePrefix = getTablePrefix(tablePrefixes, fsTable.getName());
     boolean isDirectoryTable =
         fsTable.getName().equals(DIRECTORY_TABLE);
+    byte[] isDirectoryTableByteArray = {(byte) (isDirectoryTable ? 1 : 0)};

Review Comment:
   nit: may be create constant for byte[] of true and false and reuse them.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1117,7 +1117,7 @@ void addToObjectIdMap(Table<String, ? extends 
WithParentObjectId> fsTable,
       Set<String> deltaFiles, boolean nativeRocksToolsLoaded,
       PersistentMap<byte[], byte[]> oldObjIdToKeyMap,
       PersistentMap<byte[], byte[]> newObjIdToKeyMap,
-      PersistentMap<byte[], SnapshotDiffObject> objectIdToDiffObject,
+      PersistentMap<byte[], byte[]> objectIdToDiffObject,

Review Comment:
   nit: I doubt variable name: `objectIdToDiffObject` is still valid. Please 
change is accordingly if needed.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -894,9 +894,9 @@ void generateSnapshotDiffReport(final String jobKey,
           new RocksDbPersistentMap<>(db, toSnapshotColumnFamily, codecRegistry,
               byte[].class, byte[].class);
       // Set of unique objectId between fromSnapshot and toSnapshot.
-      final PersistentMap<byte[], SnapshotDiffObject> objectIdToDiffObject =
+      final PersistentMap<byte[], byte[]> objectIdToDiffObject =

Review Comment:
   nit: You can use Boolean directory here because there is not much saving on 
serialization and deserialization here. It is serialization when it is added 
`objectIdToDiffObject` and `deserialization` when reading it.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1481,7 +1485,7 @@ long generateDiffReport(
     }
   }
 
-  private boolean isObjectModified(String fromObjectName, String toObjectName,
+  boolean isObjectModified(String fromObjectName, String toObjectName,

Review Comment:
   Why is visibility changed to package level? I don't see it getting used 
anywhere else other than this class.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1397,31 +1393,39 @@ long generateDiffReport(
             DiffReportEntry entry =
                 SnapshotDiffReportOzone.getDiffReportEntry(DELETE, key);
             deleteDiffs.add(codecRegistry.asRawData(entry));
-          } else if (Arrays.equals(oldKeyName, newKeyName)) { // Key modified.
+          } else if (isDirectoryObject &&
+              Arrays.equals(oldKeyName, newKeyName)) {
             String key = resolveBucketRelativePath(isFSOBucket,
                 newParentIdPathMap, newKeyName);
             DiffReportEntry entry =
                 SnapshotDiffReportOzone.getDiffReportEntry(MODIFY, key);
             modifyDiffs.add(codecRegistry.asRawData(entry));
-          } else { // Key Renamed.
+          } else {
+            // Key Renamed.

Review Comment:
   nit: this comment is not valid anymore. Please either remove this or update 
it.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1397,31 +1393,39 @@ long generateDiffReport(
             DiffReportEntry entry =
                 SnapshotDiffReportOzone.getDiffReportEntry(DELETE, key);
             deleteDiffs.add(codecRegistry.asRawData(entry));
-          } else if (Arrays.equals(oldKeyName, newKeyName)) { // Key modified.
+          } else if (isDirectoryObject &&
+              Arrays.equals(oldKeyName, newKeyName)) {
             String key = resolveBucketRelativePath(isFSOBucket,
                 newParentIdPathMap, newKeyName);
             DiffReportEntry entry =
                 SnapshotDiffReportOzone.getDiffReportEntry(MODIFY, key);
             modifyDiffs.add(codecRegistry.asRawData(entry));
-          } else { // Key Renamed.
+          } else {
+            // Key Renamed.
+            String keyPrefix = getTablePrefix(tablePrefix,
+                (isDirectoryObject ? fsDirTable : fsTable).getName());
             String oldKey = resolveBucketRelativePath(isFSOBucket,
                 oldParentIdPathMap, oldKeyName);
-            String newKey = resolveBucketRelativePath(isFSOBucket,
-                newParentIdPathMap, newKeyName);
-            renameDiffs.add(codecRegistry.asRawData(
-                SnapshotDiffReportOzone.getDiffReportEntry(RENAME, oldKey,
-                    newKey)));
-
             // Check if block location is same or not. If it is not same,
             // key must have been overridden as well.
-            if (isObjectModified(snapshotDiffObject.getOldKeyName(),
-                snapshotDiffObject.getNewKeyName(),
-                snapshotDiffObject.isDirectory() ? fsDirTable : fsTable,
-                snapshotDiffObject.isDirectory() ? tsDirTable : tsTable)) {
+            boolean isObjectModified = false;

Review Comment:
   nit:
   1. I think it is cleaner this way.
   1. I doubt condition `!Arrays.equals(oldKeyName, newKeyName)` matters 
because the way `objectModified` is set either it will go into `if` block of 
line 1412 or 1423.
   
   ```suggestion
               boolean isObjectModified = isObjectModified(
                   keyPrefix + codecRegistry.asObject(oldKeyName, String.class),
                   keyPrefix + codecRegistry.asObject(newKeyName, String.class),
                   isDirectoryObject ? fsDirTable : fsTable,
                   isDirectoryObject ? tsDirTable : tsTable);
   
               if (isObjectModified) {
                 // Here, oldKey name is returned as modified. Modified key 
name is
                 // based on base snapshot (from snapshot).
                 modifyDiffs.add(codecRegistry.asRawData(
                     SnapshotDiffReportOzone.getDiffReportEntry(MODIFY, 
oldKey)));
               } else {
                 String newKey = resolveBucketRelativePath(isFSOBucket,
                     newParentIdPathMap, newKeyName);
                 renameDiffs.add(codecRegistry.asRawData(
                     SnapshotDiffReportOzone.getDiffReportEntry(RENAME, oldKey,
                         newKey)));
               }
             }
   ```



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