diff options
author | Harald Musum <musum@oath.com> | 2018-03-16 11:41:41 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-03-16 11:41:41 +0100 |
commit | 6aa444993921395ea75d80f2779b5147e3441c44 (patch) | |
tree | 6a6e6bbe83d046d893765b194055167441786c44 /filedistribution | |
parent | 16cbe9c84b77d0419ac7e184fb99959d8b3d0e34 (diff) |
Sleep longer between retries of RPC calls
Diffstat (limited to 'filedistribution')
3 files changed, 17 insertions, 8 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java index b855c667960..02d6e1ad022 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java @@ -37,13 +37,14 @@ public class FileDownloader { this(connectionPool, new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution")), new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution")), - Duration.ofMinutes(15)); + Duration.ofMinutes(15), + Duration.ofSeconds(10)); } - FileDownloader(ConnectionPool connectionPool, File downloadDirectory, File tmpDirectory, Duration timeout) { + FileDownloader(ConnectionPool connectionPool, File downloadDirectory, File tmpDirectory, Duration timeout, Duration sleepBetweenRetries) { this.downloadDirectory = downloadDirectory; this.timeout = timeout; - this.fileReferenceDownloader = new FileReferenceDownloader(downloadDirectory, tmpDirectory, connectionPool, timeout); + this.fileReferenceDownloader = new FileReferenceDownloader(downloadDirectory, tmpDirectory, connectionPool, timeout, sleepBetweenRetries); } public Optional<File> getFile(FileReference fileReference) { diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java index 5f6db8afd1f..2084c00d31b 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java @@ -41,11 +41,14 @@ public class FileReferenceDownloader { private final Map<FileReference, FileReferenceDownload> downloads = new LinkedHashMap<>(); private final Map<FileReference, Double> downloadStatus = new HashMap<>(); // between 0 and 1 private final Duration downloadTimeout; + private final Duration sleepBetweenRetries; private final FileReceiver fileReceiver; - FileReferenceDownloader(File downloadDirectory, File tmpDirectory, ConnectionPool connectionPool, Duration timeout) { + FileReferenceDownloader(File downloadDirectory, File tmpDirectory, ConnectionPool connectionPool, + Duration timeout, Duration sleepBetweenRetries) { this.connectionPool = connectionPool; this.downloadTimeout = timeout; + this.sleepBetweenRetries = sleepBetweenRetries; this.fileReceiver = new FileReceiver(connectionPool.getSupervisor(), this, downloadDirectory, tmpDirectory); } @@ -58,7 +61,7 @@ public class FileReferenceDownloader { if (startDownloadRpc(fileReference)) { downloadStarted = true; } else { - Thread.sleep(10); + Thread.sleep(sleepBetweenRetries.toMillis()); } } catch (InterruptedException e) { /* ignored */} @@ -192,4 +195,8 @@ public class FileReferenceDownloader { public ConnectionPool connectionPool() { return connectionPool; } + + public Duration getDownloadTimeout() { + return downloadTimeout; + } } diff --git a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java index 960a18aaa4c..d433dc25105 100644 --- a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java +++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java @@ -44,7 +44,7 @@ public class FileDownloaderTest { downloadDir = Files.createTempDirectory("filedistribution").toFile(); tempDir = Files.createTempDirectory("download").toFile(); connection = new MockConnection(); - fileDownloader = new FileDownloader(connection, downloadDir, tempDir, Duration.ofMillis(2000)); + fileDownloader = new FileDownloader(connection, downloadDir, tempDir, Duration.ofSeconds(2), Duration.ofMillis(100)); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -150,7 +150,7 @@ public class FileDownloaderTest { @Test public void getFileWhenConnectionError() throws IOException { - fileDownloader = new FileDownloader(connection, downloadDir, tempDir, Duration.ofMillis(3000)); + fileDownloader = new FileDownloader(connection, downloadDir, tempDir, Duration.ofSeconds(3), Duration.ofMillis(100)); File downloadDir = fileDownloader.downloadDirectory(); int timesToFail = 2; @@ -183,10 +183,11 @@ public class FileDownloaderTest { @Test public void setFilesToDownload() throws IOException { Duration timeout = Duration.ofMillis(200); + Duration sleepBetweenRetries = Duration.ofMillis(200); File downloadDir = Files.createTempDirectory("filedistribution").toFile(); MockConnection connectionPool = new MockConnection(); connectionPool.setResponseHandler(new MockConnection.WaitResponseHandler(timeout.plus(Duration.ofMillis(1000)))); - FileDownloader fileDownloader = new FileDownloader(connectionPool, downloadDir, tempDir, timeout); + FileDownloader fileDownloader = new FileDownloader(connectionPool, downloadDir, tempDir, timeout, sleepBetweenRetries); FileReference foo = new FileReference("foo"); FileReference bar = new FileReference("bar"); List<FileReference> fileReferences = Arrays.asList(foo, bar); |