[ 
https://issues.apache.org/jira/browse/HIVE-24852?focusedWorklogId=598400&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-598400
 ]

ASF GitHub Bot logged work on HIVE-24852:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/May/21 02:42
            Start Date: 18/May/21 02:42
    Worklog Time Spent: 10m 
      Work Description: aasha commented on a change in pull request #2043:
URL: https://github.com/apache/hive/pull/2043#discussion_r633997089



##########
File path: 
shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
##########
@@ -1197,6 +1241,112 @@ public boolean runDistCp(List<Path> srcPaths, Path dst, 
Configuration conf) thro
     }
   }
 
+  @Override
+  public boolean runDistCpWithSnapshots(String oldSnapshot, String 
newSnapshot, List<Path> srcPaths, Path dst, Configuration conf)
+      throws IOException {
+    DistCpOptions options =
+        new DistCpOptions.Builder(srcPaths, 
dst).withSyncFolder(true).withUseDiff(oldSnapshot, newSnapshot)
+        
.preserve(FileAttribute.BLOCKSIZE).preserve(FileAttribute.XATTR).build();
+
+    List<String> params = constructDistCpWithSnapshotParams(srcPaths, dst, 
oldSnapshot, newSnapshot, conf, "-diff");
+    try {
+      conf.setBoolean("mapred.mapper.new-api", true);
+      DistCp distcp = new DistCp(conf, options);
+      int returnCode = distcp.run(params.toArray(new String[0]));
+      if (returnCode == 0) {
+        return true;
+      } else if (returnCode == DistCpConstants.INVALID_ARGUMENT) {
+        // Handling FileNotFoundException, if source got deleted, in that case 
we don't want to copy either, So it is
+        // like a success case, we didn't had anything to copy and we copied 
nothing, so, we need not to fail.
+        LOG.warn("Copy failed with INVALID_ARGUMENT for source: {} to target: 
{} snapshot1: {} snapshot2: {} "
+            + "params: {}", srcPaths, dst, oldSnapshot, newSnapshot, params);
+        return true;
+      } else if (returnCode == DistCpConstants.UNKNOWN_ERROR && conf
+          .getBoolean("hive.repl.externaltable.snapshot.overwrite.target", 
true)) {
+        // Check if this error is due to target modified.
+        if (shouldRdiff(dst, conf, oldSnapshot)) {
+          LOG.warn("Copy failed due to target modified. Attempting to restore 
back the target. source: {} target: {} "
+              + "snapshot: {}", srcPaths, dst, oldSnapshot);
+          List<String> rParams = constructDistCpWithSnapshotParams(srcPaths, 
dst, ".", oldSnapshot, conf, "-rdiff");
+          DistCp rDistcp = new DistCp(conf, options);
+          returnCode = rDistcp.run(rParams.toArray(new String[0]));
+          if (returnCode == 0) {
+            LOG.info("Target restored to previous state.  source: {} target: 
{} snapshot: {}. Reattempting to copy.",
+                srcPaths, dst, oldSnapshot);
+            dst.getFileSystem(conf).deleteSnapshot(dst, oldSnapshot);
+            dst.getFileSystem(conf).createSnapshot(dst, oldSnapshot);
+            returnCode = distcp.run(params.toArray(new String[0]));
+            if (returnCode == 0) {
+              return true;
+            } else {
+              LOG.error("Copy failed with after target restore for source: {} 
to target: {} snapshot1: {} snapshot2: "
+                  + "{} params: {}. Return code: {}", srcPaths, dst, 
oldSnapshot, newSnapshot, params, returnCode);
+              return false;
+            }
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new IOException("Cannot execute DistCp process: ", e);
+    } finally {
+      conf.setBoolean("mapred.mapper.new-api", false);
+    }
+    return false;
+  }
+
+  /**
+   * Checks wether reverse diff on the snapshot should be performed or not.
+   * @param p path where snapshot exists.
+   * @param conf the hive configuration.
+   * @param snapshot the name of snapshot.
+   * @return true, if we need to do rdiff.
+   */
+  private static boolean shouldRdiff(Path p, Configuration conf, String 
snapshot) throws Exception {
+    // Using the configuration in string form since hive-shims doesn't have a 
dependency on hive-common.
+    boolean isOverwrite = 
conf.getBoolean("hive.repl.externaltable.snapshot.overwrite.target", true);

Review comment:
       No I meant can you not pass the value of the config to HadoopShims 
method of run distcp from whoever is calling this method




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 598400)
    Time Spent: 6h 40m  (was: 6.5h)

> Add support for Snapshots during external table replication
> -----------------------------------------------------------
>
>                 Key: HIVE-24852
>                 URL: https://issues.apache.org/jira/browse/HIVE-24852
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Ayush Saxena
>            Assignee: Ayush Saxena
>            Priority: Critical
>              Labels: pull-request-available
>         Attachments: Design Doc HDFS Snapshots for External Table 
> Replication-01.pdf
>
>          Time Spent: 6h 40m
>  Remaining Estimate: 0h
>
> Add support for use of snapshot diff for external table replication.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to