summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2024-01-22 10:33:42 +0100
committerjonmv <venstad@gmail.com>2024-01-22 10:33:42 +0100
commit527dbbbd76489ee7dc3520a1ac9cdef2646543c6 (patch)
tree426ed689351b61084770b633e7ff6a5a4b3089d9 /filedistribution
parente3db51d6c6d40be54495ed121c64be43978d1120 (diff)
Improve file downloader give-up criterion
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java12
1 files changed, 7 insertions, 5 deletions
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 450801ce530..e26936cd5cf 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java
@@ -67,7 +67,7 @@ public class FileReferenceDownloader {
int retryCount = 0;
Connection connection = connectionPool.getCurrent();
do {
- backoff(retryCount);
+ backoff(retryCount, end);
if (FileDownloader.fileReferenceExists(fileReference, downloadDirectory))
return;
@@ -79,17 +79,19 @@ public class FileReferenceDownloader {
// exist on just one config server, and which one could be different for each file reference), so
// switch to a new connection for every retry
connection = connectionPool.switchConnection(connection);
- } while (retryCount < 5 || Instant.now().isAfter(end));
+ } while (Instant.now().isBefore(end));
fileReferenceDownload.future().completeExceptionally(new RuntimeException("Failed getting " + fileReference));
downloads.remove(fileReference);
}
- private void backoff(int retryCount) {
+ private void backoff(int retryCount, Instant end) {
if (retryCount > 0) {
try {
- long sleepTime = Math.min(120_000, (long) (Math.pow(2, retryCount)) * sleepBetweenRetries.toMillis());
- Thread.sleep(sleepTime);
+ long sleepTime = Math.min(120_000,
+ Math.min((long) (Math.pow(2, retryCount)) * sleepBetweenRetries.toMillis(),
+ Duration.between(Instant.now(), end).toMillis()));
+ if (sleepTime > 0) Thread.sleep(sleepTime);
} catch (InterruptedException e) {
/* ignored */
}