ctubbsii commented on a change in pull request #1555: Fix idempotency bug in
importtable
URL: https://github.com/apache/accumulo/pull/1555#discussion_r389421651
##########
File path:
server/master/src/main/java/org/apache/accumulo/master/tableOps/MoveExportedFiles.java
##########
@@ -48,17 +49,22 @@
Map<String,String> fileNameMappings =
PopulateMetadataTable.readMappingFile(fs, tableInfo);
+ FileStatus[] exportedFiles = fs.listStatus(new
Path(tableInfo.exportDir));
+ FileStatus[] importedFiles = fs.listStatus(new
Path(tableInfo.importDir));
+
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);
+ if (Arrays.stream(exportedFiles).filter(fstat ->
+ fstat.getPath().getName().equals(oldFileName)).count() != 1) {
+ if (Arrays.stream(importedFiles).filter(fstat ->
+
fstat.getPath().getName().equals(fileNameMappings.get(oldFileName))).count() !=
1) {
+ throw new
AcceptableThriftTableOperationException(tableInfo.tableId, tableInfo.tableName,
+ TableOperation.IMPORT, TableOperationExceptionType.OTHER,
+ "File referenced by exported table does not exist " +
oldFileName);
+ }
Review comment:
Not sure if it's worth it, but I think you could maybe reuse the lambda used
for the Predicate, as in the following.
Also, I think `.noneMatch(p)` is probably better than `.filter(p).count() !=
1`, since it's not really possible to have multiple files in the same directory
match on the same file name anyway... so the result is always binary (present
or absent).
```suggestion
// given a name, return a predicate that can check a FileStatus for a
match against that name
Function<String,Predicate<FileStatus>> nameEq = name -> fstat ->
fstat.getPath().getName().equals(name);
for (String oldFileName : fileNameMappings.keySet()) {
if
(Arrays.stream(exportedFiles).noneMatch(nameEq.apply(oldFileName))) {
String newFileName = fileNameMappings.get(oldFileName);
if
(Arrays.stream(importedFiles).noneMatch(nameEq.apply(newFileName))) {
throw new
AcceptableThriftTableOperationException(tableInfo.tableId, tableInfo.tableName,
TableOperation.IMPORT, TableOperationExceptionType.OTHER,
"File referenced by exported table does not exist " +
oldFileName);
}
```
----------------------------------------------------------------
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