diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-11-23 20:45:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 20:45:20 +0100 |
commit | 40f2e327fb35210401cf340757629af1e67a9588 (patch) | |
tree | dadd8762440f765e00c1fb74a7eda1ab1a01a4cb /configserver | |
parent | 81226e4673d4291e82d8119b0ddf83ca23071fa4 (diff) | |
parent | 351c1dc3d8b2122ccb5293bc27604878fec12a39 (diff) |
Merge pull request #4260 from vespa-engine/hmusum/choose-new-connection-if-file-reference-not-found
Hmusum/choose new connection if file reference not found
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java | 31 | ||||
-rw-r--r-- | configserver/src/main/resources/configserver-app/services.xml | 1 |
2 files changed, 27 insertions, 5 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 9dc94c9fe93..3561a5cba9a 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 @@ -2,24 +2,29 @@ package com.yahoo.vespa.config.server.filedistribution; import com.google.inject.Inject; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.FileReference; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.io.IOUtils; +import com.yahoo.net.HostName; import com.yahoo.vespa.config.JRTConnectionPool; +import com.yahoo.vespa.config.server.ConfigServerSpec; import com.yahoo.vespa.filedistribution.FileDownloader; import java.io.File; import java.io.IOException; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Logger; +import java.util.stream.Collectors; public class FileServer { private static final Logger log = Logger.getLogger(FileServer.class.getName()); private final FileDirectory root; private final ExecutorService executor; - private final FileDownloader downloader = new FileDownloader(new JRTConnectionPool(ConfigSourceSet.createDefault())); + private final FileDownloader downloader; public static class ReplayStatus { private final int code; @@ -38,15 +43,21 @@ public class FileServer { } @Inject - public FileServer() { - this(FileDistribution.getDefaultFileDBPath()); + public FileServer(ConfigserverConfig configserverConfig) { + this(createConnectionPool(ConfigServerSpec.fromConfig(configserverConfig)), FileDistribution.getDefaultFileDBPath()); } + // For testing only public FileServer(File rootDir) { - this(rootDir, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + this(new JRTConnectionPool(new ConfigSourceSet("tcp/localhost:19090")), rootDir); } - public FileServer(File rootDir, ExecutorService executor) { + public FileServer(JRTConnectionPool jrtConnectionPool, File rootDir) { + this(jrtConnectionPool, rootDir, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + } + + public FileServer(JRTConnectionPool jrtConnectionPool, File rootDir, ExecutorService executor) { + this.downloader = new FileDownloader(jrtConnectionPool); this.root = new FileDirectory(rootDir); this.executor = executor; } @@ -94,4 +105,14 @@ public class FileServer { public void download(FileReference fileReference) { downloader.getFile(fileReference); } + + // Connection pool with all config servers except this one + private static JRTConnectionPool createConnectionPool(List<com.yahoo.config.model.api.ConfigServerSpec> configServerSpecs) { + return new JRTConnectionPool( + new ConfigSourceSet(configServerSpecs + .stream() + .filter(spec -> !spec.getHostName().equals(HostName.getLocalhost())) + .map(spec -> "tcp/" + spec.getHostName() + ":" + spec.getConfigServerPort()) + .collect(Collectors.toList()))); + } } diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml index 635ce07e727..fbab854ae9e 100644 --- a/configserver/src/main/resources/configserver-app/services.xml +++ b/configserver/src/main/resources/configserver-app/services.xml @@ -34,6 +34,7 @@ <component id="com.yahoo.config.provision.Zone" bundle="config-provisioning" /> <component id="com.yahoo.vespa.config.server.application.ApplicationConvergenceChecker" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.application.HttpProxy" bundle="configserver" /> + <component id="com.yahoo.vespa.config.server.filedistribution.FileServer" bundle="configserver" /> <component id="com.yahoo.vespa.serviceview.ConfigServerLocation" bundle="configserver" /> |