diff options
4 files changed, 19 insertions, 21 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java index ee775fa7afb..d83636d08d6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java @@ -14,7 +14,6 @@ import com.yahoo.vespa.config.server.session.SessionRepository; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.defaults.Defaults; -import com.yahoo.vespa.filedistribution.Downloads; import com.yahoo.vespa.filedistribution.FileDownloader; import com.yahoo.vespa.filedistribution.FileReferenceDownload; import com.yahoo.vespa.flags.FlagSource; @@ -94,8 +93,7 @@ public class ApplicationPackageMaintainer extends ConfigServerMaintainer { private FileDownloader createFileDownloader() { return new FileDownloader(new JRTConnectionPool(new ConfigSourceSet(getOtherConfigServersInCluster(configserverConfig)), supervisor), supervisor, - downloadDirectory, - new Downloads()); + downloadDirectory); } @Override diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java index 1cb6b2a13cd..29ec11bad26 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java @@ -7,7 +7,6 @@ import com.yahoo.io.IOUtils; import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.net.HostName; -import com.yahoo.vespa.filedistribution.Downloads; import com.yahoo.vespa.filedistribution.FileDownloader; import com.yahoo.vespa.filedistribution.FileReferenceData; import com.yahoo.vespa.filedistribution.FileReferenceDownload; @@ -142,7 +141,6 @@ public class FileServerTest { super(FileDownloader.emptyConnectionPool(), new Supervisor(new Transport("mock")).setDropEmptyBuffers(true), downloadDirectory, - new Downloads(), Duration.ofMillis(100), Duration.ofMillis(100)); } 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 1dd5059d95a..cf3fa5583f5 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java @@ -39,23 +39,25 @@ public class FileDownloader implements AutoCloseable { private final File downloadDirectory; private final Duration timeout; private final FileReferenceDownloader fileReferenceDownloader; - private final Downloads downloads; + private final Downloads downloads = new Downloads(); public FileDownloader(List<String> configServers, Supervisor supervisor) { this(getConnectionPool(configServers, supervisor), supervisor); } public FileDownloader(ConnectionPool connectionPool, Supervisor supervisor) { - this(connectionPool, supervisor, defaultDownloadDirectory, new Downloads()); + this(connectionPool, supervisor, defaultDownloadDirectory); } - public FileDownloader(ConnectionPool connectionPool, Supervisor supervisor, File downloadDirectory, Downloads downloads) { - // TODO: Reduce timeout even more, timeout is so long that we might get starvation - this(connectionPool, supervisor, downloadDirectory, downloads, Duration.ofMinutes(5), Duration.ofSeconds(10)); + public FileDownloader(ConnectionPool connectionPool, Supervisor supervisor, File downloadDirectory) { + this(connectionPool, supervisor, downloadDirectory, Duration.ofMinutes(5), Duration.ofSeconds(10)); } - public FileDownloader(ConnectionPool connectionPool, Supervisor supervisor, File downloadDirectory, Downloads downloads, - Duration timeout, Duration sleepBetweenRetries) { + public FileDownloader(ConnectionPool connectionPool, + Supervisor supervisor, + File downloadDirectory, + Duration timeout, + Duration sleepBetweenRetries) { this.connectionPool = connectionPool; this.supervisor = supervisor; this.downloadDirectory = downloadDirectory; @@ -63,7 +65,6 @@ public class FileDownloader implements AutoCloseable { // Needed to receive RPC receiveFile* calls from server after asking for files new FileReceiver(supervisor, downloads, downloadDirectory); this.fileReferenceDownloader = new FileReferenceDownloader(connectionPool, downloads, timeout, sleepBetweenRetries); - this.downloads = downloads; } public Optional<File> getFile(FileReference fileReference) { @@ -95,6 +96,8 @@ public class FileDownloader implements AutoCloseable { public ConnectionPool connectionPool() { return connectionPool; } + public Downloads downloads() { return downloads; } + File downloadDirectory() { return downloadDirectory; } 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 6855f7f818c..79530c39ad7 100644 --- a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java +++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java @@ -41,7 +41,6 @@ public class FileDownloaderTest { private static final Duration sleepBetweenRetries = Duration.ofMillis(10); private MockConnection connection; - private Downloads downloads; private FileDownloader fileDownloader; private File downloadDir; private Supervisor supervisor; @@ -51,9 +50,8 @@ public class FileDownloaderTest { try { downloadDir = Files.createTempDirectory("filedistribution").toFile(); connection = new MockConnection(); - downloads = new Downloads(); supervisor = new Supervisor(new Transport()).setDropEmptyBuffers(true); - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, downloads, Duration.ofSeconds(1), sleepBetweenRetries); + fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(1), sleepBetweenRetries); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -124,7 +122,7 @@ public class FileDownloaderTest { assertEquals("some other content", IOUtils.readFile(downloadedFile.get())); // Verify download status when downloaded - System.out.println(downloads.downloadStatuses()); + System.out.println(fileDownloader.downloads().downloadStatuses()); assertDownloadStatus(fileReference, 1.0); } @@ -166,7 +164,7 @@ public class FileDownloaderTest { @Test public void getFileWhenConnectionError() throws IOException { - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, downloads, Duration.ofSeconds(2), sleepBetweenRetries); + fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(2), sleepBetweenRetries); File downloadDir = fileDownloader.downloadDirectory(); int timesToFail = 2; @@ -200,7 +198,7 @@ public class FileDownloaderTest { public void getFileWhenDownloadInProgress() throws IOException, ExecutionException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(2); String filename = "abc.jar"; - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, downloads, Duration.ofSeconds(3), sleepBetweenRetries); + fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(3), sleepBetweenRetries); File downloadDir = fileDownloader.downloadDirectory(); // Delay response so that we can make a second request while downloading the file from the first request @@ -240,7 +238,7 @@ public class FileDownloaderTest { Duration timeout = Duration.ofMillis(200); MockConnection connectionPool = new MockConnection(); connectionPool.setResponseHandler(new MockConnection.WaitResponseHandler(timeout.plus(Duration.ofMillis(1000)))); - FileDownloader fileDownloader = new FileDownloader(connectionPool, supervisor, downloadDir, downloads, timeout, sleepBetweenRetries); + FileDownloader fileDownloader = new FileDownloader(connectionPool, supervisor, downloadDir, timeout, sleepBetweenRetries); FileReference xyzzy = new FileReference("xyzzy"); // Should download since we do not have the file on disk fileDownloader.downloadIfNeeded(new FileReferenceDownload(xyzzy)); @@ -275,6 +273,7 @@ public class FileDownloaderTest { } private void assertDownloadStatus(FileReference fileReference, double expectedDownloadStatus) { + Downloads downloads = fileDownloader.downloads(); double downloadStatus = downloads.downloadStatus(fileReference); assertEquals("Download statuses: " + downloads.downloadStatuses().toString(), expectedDownloadStatus, @@ -293,7 +292,7 @@ public class FileDownloaderTest { new FileReceiver.Session(downloadDir, 1, fileReference, type, filename, content.length); session.addPart(0, content); File file = session.close(hasher.hash(ByteBuffer.wrap(content), 0)); - downloads.completedDownloading(fileReference, file); + fileDownloader.downloads().completedDownloading(fileReference, file); } private static class MockConnection implements ConnectionPool, com.yahoo.vespa.config.Connection { |