[ https://issues.apache.org/jira/browse/HIVE-24852?focusedWorklogId=597689&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-597689 ]
ASF GitHub Bot logged work on HIVE-24852: ----------------------------------------- Author: ASF GitHub Bot Created on: 17/May/21 14:28 Start Date: 17/May/21 14:28 Worklog Time Spent: 10m Work Description: aasha commented on a change in pull request #2043: URL: https://github.com/apache/hive/pull/2043#discussion_r633581183 ########## 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: have to be careful to not modify this constant.can you not pass the value of the conf -- 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: 597689) Time Spent: 5.5h (was: 5h 20m) > 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: 5.5h > 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)