diff options
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java | 26 | ||||
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java | 23 |
2 files changed, 26 insertions, 23 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java index 5d9a9c7b836..f34beae9c46 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java @@ -5,11 +5,14 @@ import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.concurrent.DaemonThreadFactory; import com.yahoo.config.FileReference; +import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.jrt.Int32Value; import com.yahoo.jrt.Request; import com.yahoo.jrt.StringValue; import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; +import com.yahoo.vespa.config.ConnectionPool; +import com.yahoo.vespa.config.JRTConnectionPool; import com.yahoo.vespa.defaults.Defaults; import com.yahoo.vespa.filedistribution.CompressedFileReference; import com.yahoo.vespa.filedistribution.EmptyFileReferenceData; @@ -24,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; @@ -71,16 +75,12 @@ public class FileServer { @Inject public FileServer(ConfigserverConfig configserverConfig) { this(new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir())), - new FileDownloader(getOtherConfigServersInCluster(configserverConfig), - new Supervisor(new Transport("filedistribution-pool")) - .setDropEmptyBuffers(true))); + createFileDownloader(getOtherConfigServersInCluster(configserverConfig))); } // For testing only public FileServer(File rootDir) { - this(rootDir, new FileDownloader(FileDownloader.emptyConnectionPool(), - new Supervisor(new Transport("fileserver-for-testing")) - .setDropEmptyBuffers(true))); + this(rootDir, createFileDownloader(List.of())); } public FileServer(File rootDir, FileDownloader fileDownloader) { @@ -205,4 +205,18 @@ public class FileServer { executor.shutdown(); } + private static FileDownloader createFileDownloader(List<String> configServers) { + Supervisor supervisor = new Supervisor(new Transport("filedistribution-pool")).setDropEmptyBuffers(true); + return new FileDownloader(configServers.isEmpty() + ? FileDownloader.emptyConnectionPool() + : getConnectionPool(configServers, supervisor), + supervisor); + } + + private static ConnectionPool getConnectionPool(List<String> configServers, Supervisor supervisor) { + return configServers.size() > 0 + ? new JRTConnectionPool(new ConfigSourceSet(configServers), supervisor) + : FileDownloader.emptyConnectionPool(); + } + } 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 cf3fa5583f5..a7678771f19 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java @@ -2,17 +2,14 @@ package com.yahoo.vespa.filedistribution; import com.yahoo.config.FileReference; -import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.jrt.Supervisor; import com.yahoo.vespa.config.Connection; import com.yahoo.vespa.config.ConnectionPool; -import com.yahoo.vespa.config.JRTConnectionPool; import com.yahoo.vespa.defaults.Defaults; import com.yahoo.yolean.Exceptions; import java.io.File; import java.time.Duration; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -31,8 +28,10 @@ import java.util.logging.Logger; */ public class FileDownloader implements AutoCloseable { - private final static Logger log = Logger.getLogger(FileDownloader.class.getName()); - public static File defaultDownloadDirectory = new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution")); + private static final Logger log = Logger.getLogger(FileDownloader.class.getName()); + private static final Duration defaultTimeout = Duration.ofMinutes(5); + private static final Duration defaultSleepBetweenRetries = Duration.ofSeconds(10); + public static final File defaultDownloadDirectory = new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution")); private final ConnectionPool connectionPool; private final Supervisor supervisor; @@ -41,16 +40,12 @@ public class FileDownloader implements AutoCloseable { private final FileReferenceDownloader fileReferenceDownloader; 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); + this(connectionPool, supervisor, defaultDownloadDirectory, defaultTimeout, defaultSleepBetweenRetries); } public FileDownloader(ConnectionPool connectionPool, Supervisor supervisor, File downloadDirectory) { - this(connectionPool, supervisor, downloadDirectory, Duration.ofMinutes(5), Duration.ofSeconds(10)); + this(connectionPool, supervisor, downloadDirectory, defaultTimeout, defaultSleepBetweenRetries); } public FileDownloader(ConnectionPool connectionPool, @@ -139,12 +134,6 @@ public class FileDownloader implements AutoCloseable { supervisor.transport().shutdown().join(); } - private static ConnectionPool getConnectionPool(List<String> configServers, Supervisor supervisor) { - return configServers.size() > 0 - ? new JRTConnectionPool(new ConfigSourceSet(configServers), supervisor) - : emptyConnectionPool(); - } - public static ConnectionPool emptyConnectionPool() { return new EmptyConnectionPool(); } |