summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2017-12-01 15:06:18 +0100
committerHarald Musum <musum@oath.com>2017-12-01 15:06:18 +0100
commitdb6e6f0db5998661de6e2f0b1ef9a89fc3812ea5 (patch)
tree09142dc76e4a29762dbbd3b0f920bb47fb30b811 /filedistribution
parentf996e2b07c041b41c3ad79fc1602a0d9b655981c (diff)
Handle file already exisisting
When we ask several config servers for a file we might get several callbacks which all try to move a file to the destination. Do not fail if we cannot move the file because it already exists
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java24
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());
}