iwasakims commented on a change in pull request #3374:
URL: https://github.com/apache/hadoop/pull/3374#discussion_r720301775



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java
##########
@@ -834,6 +844,53 @@ public static SnapshotDiffReport 
toSnapshotDiffReport(final Map<?, ?> json) {
     return new SnapshotDiffReport.DiffReportEntry(type, sourcePath, 
targetPath);
   }
 
+  public static SnapshotDiffReportListing toSnapshotDiffReportListing(
+      final Map<?, ?> json) {
+    if (json == null) {
+      return null;
+    }
+
+    Map<?, ?> m =
+        (Map<?, ?>) json.get(SnapshotDiffReportListing.class.getSimpleName());
+    byte[] lastPath = DFSUtilClient.string2Bytes(getString(m, "lastPath", ""));
+    int lastIndex = getInt(m, "lastIndex", -1);
+    boolean isFromEarlier = getBoolean(m, "isFromEarlier", false);
+    List<DiffReportListingEntry> modifyList =
+        toDiffListingList(getList(m, "modifyList"));
+    List<DiffReportListingEntry> createList =
+        toDiffListingList(getList(m, "createList"));
+    List<DiffReportListingEntry> deleteList =
+        toDiffListingList(getList(m, "deleteList"));
+
+    return new SnapshotDiffReportListing(

Review comment:
       Let me do this in follow-up JIRA. I filed 
[HDFS-16248](https://issues.apache.org/jira/browse/HDFS-16248).

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java
##########
@@ -1460,6 +1472,64 @@ SnapshotDiffReport decodeResponse(Map<?, ?> json) {
     }.run();
   }
 
+  public SnapshotDiffReport getSnapshotDiffReport(final Path snapshotDir,
+      final String fromSnapshot, final String toSnapshot) throws IOException {
+    statistics.incrementReadOps(1);
+    storageStatistics.incrementOpCounter(OpType.GET_SNAPSHOT_DIFF);
+
+    if (!isValidSnapshotName(fromSnapshot) || 
!isValidSnapshotName(toSnapshot)) {
+      // In case the diff needs to be computed between a snapshot and the 
current
+      // tree, we should not do iterative diffReport computation as the 
iterative
+      // approach might fail if in between the rpc calls the current tree
+      // changes in absence of the global fsn lock.
+      return getSnapshotDiffReportWithoutListing(snapshotDir, fromSnapshot, 
toSnapshot);
+    } else {
+      byte[] startPath = DFSUtilClient.EMPTY_BYTES;
+      int index = -1;
+      SnapshotDiffReportGenerator snapshotDiffReport;
+      List<DiffReportListingEntry> modifiedList = new TreeList();
+      List<DiffReportListingEntry> createdList = new ChunkedArrayList<>();
+      List<DiffReportListingEntry> deletedList = new ChunkedArrayList<>();
+      SnapshotDiffReportListing report;
+
+      do {
+        try {
+          report = new FsPathResponseRunner<SnapshotDiffReportListing>(
+              GetOpParam.Op.GETSNAPSHOTDIFFLISTING,
+              snapshotDir,
+              new OldSnapshotNameParam(fromSnapshot),
+              new SnapshotNameParam(toSnapshot),
+              new 
SnapshotDiffStartPathParam(DFSUtilClient.bytes2String(startPath)),
+              new SnapshotDiffIndexParam(index)) {
+            @Override
+            SnapshotDiffReportListing decodeResponse(Map<?, ?> json) {
+              return JsonUtilClient.toSnapshotDiffReportListing(json);
+            }
+          }.run();
+        } catch (UnsupportedOperationException e) {
+          // In case the server doesn't support getSnapshotDiffReportListing,

Review comment:
       Let me do this in follow-up JIRA. I filed 
[HDFS-16249](https://issues.apache.org/jira/browse/HDFS-16249).




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