summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-10-19 08:15:33 +0200
committerHarald Musum <musum@yahooinc.com>2021-10-19 08:15:33 +0200
commit3ecfc6bcaf1735f4d7fe27639dd147c26f9b1517 (patch)
tree136036eced648aaae9abae20a6fa72e9db2f8b37 /filedistribution
parentafa7d83d61c0ac1baaa0413a10166335dc51dba9 (diff)
Rename methods, add field for future use
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java16
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java6
2 files changed, 12 insertions, 10 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 018bc7e6569..0678509dc68 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
@@ -36,6 +36,7 @@ public class FileDownloader implements AutoCloseable {
private final Supervisor supervisor;
private final File downloadDirectory;
private final Duration timeout;
+ private final Duration sleepBetweenRetries;
private final FileReferenceDownloader fileReferenceDownloader;
private final Downloads downloads = new Downloads();
@@ -60,7 +61,8 @@ public class FileDownloader implements AutoCloseable {
this.supervisor = supervisor;
this.downloadDirectory = downloadDirectory;
this.timeout = timeout;
- // Needed to receive RPC receiveFile* calls from server after asking for files
+ this.sleepBetweenRetries = sleepBetweenRetries;
+ // Needed to receive RPC receiveFile* calls from server after starting download of file reference
new FileReceiver(supervisor, downloads, downloadDirectory);
this.fileReferenceDownloader = new FileReferenceDownloader(connectionPool, downloads, timeout, sleepBetweenRetries);
}
@@ -86,7 +88,7 @@ public class FileDownloader implements AutoCloseable {
Optional<File> file = getFileFromFileSystem(fileReference);
return (file.isPresent())
? CompletableFuture.completedFuture(file)
- : download(fileReferenceDownload);
+ : startDownload(fileReferenceDownload);
}
public Map<FileReference, Double> downloadStatus() { return downloads.downloadStatus(); }
@@ -125,16 +127,16 @@ public class FileDownloader implements AutoCloseable {
return downloads.get(fileReference).isPresent();
}
- /** Start a download, don't wait for result */
+ /** Start a download if needed, don't wait for result */
public void downloadIfNeeded(FileReferenceDownload fileReferenceDownload) {
if (fileReferenceExists(fileReferenceDownload.fileReference())) return;
- download(fileReferenceDownload);
+ startDownload(fileReferenceDownload);
}
- /** Download, the future returned will be complete()d by receiving method in {@link FileReceiver} */
- private synchronized Future<Optional<File>> download(FileReferenceDownload fileReferenceDownload) {
- return fileReferenceDownloader.download(fileReferenceDownload);
+ /** Start downloading, the future returned will be complete()d by receiving method in {@link FileReceiver} */
+ private synchronized Future<Optional<File>> startDownload(FileReferenceDownload fileReferenceDownload) {
+ return fileReferenceDownloader.startDownload(fileReferenceDownload);
}
public void close() {
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 952684b7b0b..c88501943ae 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java
@@ -50,7 +50,7 @@ public class FileReferenceDownloader {
this.rpcTimeout = Duration.ofSeconds(timeoutString == null ? 30 : Integer.parseInt(timeoutString));
}
- private void startDownload(FileReferenceDownload fileReferenceDownload) {
+ private void waitUntilDownloadStarted(FileReferenceDownload fileReferenceDownload) {
FileReference fileReference = fileReferenceDownload.fileReference();
Instant end = Instant.now().plus(downloadTimeout);
boolean downloadStarted = false;
@@ -75,14 +75,14 @@ public class FileReferenceDownloader {
}
}
- Future<Optional<File>> download(FileReferenceDownload fileReferenceDownload) {
+ Future<Optional<File>> startDownload(FileReferenceDownload fileReferenceDownload) {
FileReference fileReference = fileReferenceDownload.fileReference();
Optional<FileReferenceDownload> inProgress = downloads.get(fileReference);
if (inProgress.isPresent()) return inProgress.get().future();
log.log(Level.FINE, () -> "Will download file reference '" + fileReference.value() + "' with timeout " + downloadTimeout);
downloads.add(fileReferenceDownload);
- downloadExecutor.submit(() -> startDownload(fileReferenceDownload));
+ downloadExecutor.submit(() -> waitUntilDownloadStarted(fileReferenceDownload));
return fileReferenceDownload.future();
}