diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-03-30 22:02:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 22:02:39 +0200 |
commit | 3bcadc974e4e6e35f43122aa0411e76abd69d19f (patch) | |
tree | 5bfcd53780034360e3f51d8861ed6265ab31f333 /filedistribution | |
parent | 3d9f2951ccba058c057fd5a4417195f407ea2d8f (diff) |
Revert "Make sure to only add to downloads when rpc call succeeds"
Diffstat (limited to 'filedistribution')
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java | 55 |
1 files changed, 32 insertions, 23 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 2c71ec04ffd..66b86866c3e 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java @@ -52,33 +52,39 @@ public class FileReferenceDownloader { new FileReceiver(connectionPool.getSupervisor(), this, downloadDirectory, tmpDirectory); } - private void startDownload(FileReferenceDownload fileReferenceDownload) { + private void startDownload(Duration timeout, FileReferenceDownload fileReferenceDownload) { FileReference fileReference = fileReferenceDownload.fileReference(); - long end = System.currentTimeMillis() + downloadTimeout.toMillis(); + long end = System.currentTimeMillis() + timeout.toMillis(); + boolean downloadStarted = false; int retryCount = 0; - - log.log(LogLevel.DEBUG, () -> "Will download file reference '" + fileReference.value() + "' with timeout " + downloadTimeout); - synchronized (downloads) { - while (System.currentTimeMillis() < end) { - try { - if (startDownloadRpc(fileReferenceDownload, retryCount)) { - downloads.put(fileReference, fileReferenceDownload); - downloadStatus.put(fileReference, 0.0); - return; - } else { - retryCount++; - Thread.sleep(sleepBetweenRetries.toMillis()); - } - } catch (InterruptedException e) { /* ignored */} + while ((System.currentTimeMillis() < end) && !downloadStarted) { + try { + if (startDownloadRpc(fileReferenceDownload, retryCount)) { + downloadStarted = true; + } else { + retryCount++; + Thread.sleep(sleepBetweenRetries.toMillis()); + } } + catch (InterruptedException e) { /* ignored */} } - fileReferenceDownload.future().setException( - new RuntimeException("Failed to start download of file reference '" + fileReference.value() + "'")); + if ( !downloadStarted) { + fileReferenceDownload.future().setException(new RuntimeException("Failed getting file reference '" + fileReference.value() + "'")); + synchronized (downloads) { + downloads.remove(fileReference); + } + } } void addToDownloadQueue(FileReferenceDownload fileReferenceDownload) { - downloadExecutor.submit(() -> startDownload(fileReferenceDownload)); + FileReference fileReference = fileReferenceDownload.fileReference(); + log.log(LogLevel.DEBUG, () -> "Will download file reference '" + fileReference.value() + "' with timeout " + downloadTimeout); + synchronized (downloads) { + downloads.put(fileReference, fileReferenceDownload); + downloadStatus.put(fileReference, 0.0); + } + downloadExecutor.submit(() -> startDownload(downloadTimeout, fileReferenceDownload)); } void completedDownloading(FileReference fileReference, File file) { @@ -108,10 +114,10 @@ public class FileReferenceDownloader { request.parameters().add(new StringValue(fileReference)); request.parameters().add(new Int32Value(fileReferenceDownload.downloadFromOtherSourceIfNotFound() ? 0 : 1)); - connection.invokeSync(request, (double) rpcTimeout.getSeconds()); + execute(request, connection); Level logLevel = (retryCount > 0 ? LogLevel.INFO : LogLevel.DEBUG); if (validateResponse(request)) { - log.log(logLevel, () -> "Request callback, OK. Req: " + request + "\nSpec: " + connection + ", retry count " + retryCount); + log.log(logLevel, () -> "Request callback, OK. Req: " + request + "\nSpec: " + connection); if (request.returnValues().get(0).asInt32() == 0) { log.log(logLevel, () -> "Found file reference '" + fileReference + "' available at " + connection.getAddress()); return true; @@ -122,8 +128,7 @@ public class FileReferenceDownloader { } } else { log.log(logLevel, "Request failed. Req: " + request + "\nSpec: " + connection.getAddress() + - ", error code: " + request.errorCode() + ", set error for spec, use another spec for next request" + - ", retry count " + retryCount); + ", error code: " + request.errorCode() + ", set error for connection and use another for next request"); connectionPool.setError(connection, request.errorCode()); return false; } @@ -146,6 +151,10 @@ public class FileReferenceDownloader { return null; } + private void execute(Request request, Connection connection) { + connection.invokeSync(request, (double) rpcTimeout.getSeconds()); + } + private boolean validateResponse(Request request) { if (request.isError()) { return false; |