anishek commented on a change in pull request #549: HIVE-21314 : Hive Replication not retaining the owner in the replicated table URL: https://github.com/apache/hive/pull/549#discussion_r259810994
########## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ExternalTableCopyTaskBuilder.java ########## @@ -54,14 +59,53 @@ List<Task<? extends Serializable>> tasks(TaskTracker tracker) { List<Task<? extends Serializable>> tasks = new ArrayList<>(); Iterator<DirCopyWork> itr = work.getPathsToCopyIterator(); - while (tracker.canAddMoreTasks() && itr.hasNext()) { + int numTaskCanBeAdded = tracker.numTaskCanBeAdded(); + Task<? extends Serializable> barrierTask = TaskFactory.get(new DependencyCollectionWork(), conf); + while (numTaskCanBeAdded-- > 0 && itr.hasNext()) { DirCopyWork dirCopyWork = itr.next(); Task<DirCopyWork> task = TaskFactory.get(dirCopyWork, conf); tasks.add(task); - tracker.addTask(task); + barrierTask.addDependentTask(task); LOG.debug("added task for {}", dirCopyWork); } - return tasks; + + if (!tasks.isEmpty()) { + tracker.addDependentTask(barrierTask); + tracker.addTaskList(tasks); + return Collections.singletonList(barrierTask); + } else { + return tasks; + } + } + + private static Integer setTargetPathOwnerInt(Path targetPath, Path sourcePath, HiveConf conf) throws IOException { + FileSystem targetFs = targetPath.getFileSystem(conf); + if (!targetFs.exists(targetPath)) { + targetFs.create(targetPath); + } + FileStatus status = sourcePath.getFileSystem(conf).getFileStatus(sourcePath); + if (status == null) { + throw new IOException("source path missing " + sourcePath); + } + targetPath.getFileSystem(conf).setOwner(targetPath, status.getOwner(), status.getGroup()); + return null; + } + + private static Integer setTargetPathOwner(Path targetPath, Path sourcePath, HiveConf conf, String distCpDoAsUser) + throws IOException { + if (distCpDoAsUser == null) { + return setTargetPathOwnerInt(targetPath, sourcePath, conf); + } + UserGroupInformation proxyUser = UserGroupInformation.createProxyUser( + distCpDoAsUser, UserGroupInformation.getLoginUser()); + try { + Path finalTargetPath = targetPath; + Path finalSourcePath = sourcePath; + return proxyUser.doAs((PrivilegedExceptionAction<Integer>) () -> + setTargetPathOwnerInt(finalTargetPath, finalSourcePath, conf)); Review comment: may be a better method name here? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 With regards, Apache Git Services