diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-12-04 10:00:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-04 10:00:52 +0100 |
commit | 0fc8970a2e11d5e2374f85e969098b114d014394 (patch) | |
tree | ba534c0343ca6b3fbbcfc7c0dfc99daa23eecf13 /filedistribution | |
parent | e00a5c830273c5b993f5eb1912c6c19eee97d6b2 (diff) | |
parent | db6e6f0db5998661de6e2f0b1ef9a89fc3812ea5 (diff) |
Merge pull request #4331 from vespa-engine/hmusum/handle-file-already-existing
Handle file already exisisting
Diffstat (limited to 'filedistribution')
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java index c7192fe0ee3..036c3157998 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java @@ -14,8 +14,8 @@ import net.jpountz.xxhash.XXHashFactory; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -41,7 +41,7 @@ public class FileReceiver { } private void registerMethods() { - receiveFileMethod(this).forEach((method) -> supervisor.addMethod(method)); + receiveFileMethod(this).forEach(supervisor::addMethod); } // Defined here so that it can be added to supervisor used by client (server will use same connection when calling @@ -112,8 +112,7 @@ public class FileReceiver { Files.write(tempFile.toPath(), content); Files.createDirectories(fileReferenceDir.toPath()); File file = new File(fileReferenceDir, filename); - Files.move(tempFile.toPath(), file.toPath()); - log.log(LogLevel.INFO, "Data written to " + file.getAbsolutePath()); + moveFileToDestination(tempFile, file); downloader.completedDownloading(fileReference, file); } catch (IOException e) { log.log(LogLevel.ERROR, "Failed writing file: " + e.getMessage(), e); @@ -121,7 +120,22 @@ public class FileReceiver { } } - @SuppressWarnings({"UnusedDeclaration"}) + private void moveFileToDestination(File tempFile, File destination) { + try { + Files.move(tempFile.toPath(), destination.toPath()); + log.log(LogLevel.INFO, "Data written to " + destination.getAbsolutePath()); + } catch (FileAlreadyExistsException e) { + // Don't fail if it already exists (we might get the file from several config servers when retrying, servers are down etc. + // so it might be written already) + log.log(LogLevel.INFO, "File '" + destination.getAbsolutePath() + "' already exists, continuing: " + e.getMessage()); + } catch (IOException e) { + String message = "Failed moving file '" + tempFile.getAbsolutePath() + "' to '" + destination.getAbsolutePath() + "'"; + log.log(LogLevel.ERROR, message, e); + throw new RuntimeException(message, e); + } + } + + @SuppressWarnings({"UnusedDeclaration"}) public final void receiveFileMeta(Request req) { log.info("Received method call '" + req.methodName() + "' with parameters : " + req.parameters()); } |