ctubbsii commented on a change in pull request #1555: Fix idempotency bug in 
importtable
URL: https://github.com/apache/accumulo/pull/1555#discussion_r390715190
 
 

 ##########
 File path: 
server/master/src/main/java/org/apache/accumulo/master/tableOps/MoveExportedFiles.java
 ##########
 @@ -48,21 +55,35 @@
 
       Map<String,String> fileNameMappings = 
PopulateMetadataTable.readMappingFile(fs, tableInfo);
 
-      for (String oldFileName : fileNameMappings.keySet()) {
-        if (!fs.exists(new Path(tableInfo.exportDir, oldFileName))) {
-          throw new AcceptableThriftTableOperationException(tableInfo.tableId, 
tableInfo.tableName,
-              TableOperation.IMPORT, TableOperationExceptionType.OTHER,
-              "File referenced by exported table does not exists " + 
oldFileName);
-        }
-      }
+      FileStatus[] exportedFiles = fs.listStatus(new 
Path(tableInfo.exportDir));
+      FileStatus[] importedFiles = fs.listStatus(new 
Path(tableInfo.importDir));
+
+      Set<String> importing = Arrays.stream(exportedFiles).map(fstat -> 
fstat.getPath().getName())
+        .map(fileNameMappings::get).collect(Collectors.toSet());
 
-      FileStatus[] files = fs.listStatus(new Path(tableInfo.exportDir));
+      Set<String> imported = Arrays.stream(importedFiles).map(fstat -> 
fstat.getPath().getName())
+        .collect(Collectors.toSet());
+      log.debug("Files already present in imported (target) directory: {}",
+        StringUtils.join(imported.toArray(), ","));
 
-      for (FileStatus fileStatus : files) {
+      Set<String> missingFiles = Sets.difference(new 
HashSet<String>(fileNameMappings.values()),
+        new HashSet<String>(Sets.union(importing, imported)));
+
+      if (!missingFiles.isEmpty())
+      {
 
 Review comment:
   That's fine, too. I typically do it locally, since it doesn't take that 
long, and it results in fewer round trips to resolve all the issues. Also, we 
have limited executors on Travis that we share with the rest of the ASF, so it 
can take awhile before it runs in Travis.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to