summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-11-16 08:20:57 +0100
committerHarald Musum <musum@yahooinc.com>2021-11-16 08:20:57 +0100
commitb6fea176befc91d85d708a26a5ab320ff8db52b0 (patch)
tree4ff8f58cfc6a1babfcfafba7e8718e938cba3bd0 /filedistribution
parent7e39d82e3b71d1957fb40edb6958dee4f2751d24 (diff)
Add FileDistributionConnectionPool
FileDistributionConnectionPool is better suited for connections getting files, since each file migh be available on different connections and switching connection for all file downloads if one fails does not make sense, instead one should switch per file download if necessary.
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDistributionConnectionPool.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDistributionConnectionPool.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDistributionConnectionPool.java
new file mode 100644
index 00000000000..3a03e6a87d5
--- /dev/null
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDistributionConnectionPool.java
@@ -0,0 +1,43 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.filedistribution;
+
+import com.yahoo.config.subscription.ConfigSourceSet;
+import com.yahoo.jrt.Supervisor;
+import com.yahoo.vespa.config.Connection;
+import com.yahoo.vespa.config.JRTConnection;
+import com.yahoo.vespa.config.JRTConnectionPool;
+
+import java.util.List;
+
+
+/**
+ * A pool of JRT connections to a set of file distribution source (one or more config servers).
+ * Used by file distribution clients, where the source that can serve a file reference might be
+ * different for each file reference (unlike config requests, where all requests should be served by the same source).
+ * A new connection is chosen randomly when calling {#link {@link #switchConnection(Connection failingConnection)}}.
+ * Unlike JRTConnectionPool there is no state that holds the 'current' connection, a new connection is picked
+ * randomly if {@link #getCurrent()} is called.
+ *
+ * @author hmusum
+ */
+public class FileDistributionConnectionPool extends JRTConnectionPool {
+
+ public FileDistributionConnectionPool(ConfigSourceSet sourceSet, Supervisor supervisor) {
+ super(sourceSet, supervisor);
+ }
+
+ @Override
+ public synchronized JRTConnection getCurrent() {
+ return pickNewConnectionRandomly(getSources());
+ }
+
+ @Override
+ public synchronized JRTConnection switchConnection(Connection failingConnection) {
+ if (getSources().size() <= 1) return getCurrent();
+
+ List<JRTConnection> sourceCandidates = getSources();
+ sourceCandidates.remove(failingConnection);
+ return pickNewConnectionRandomly(sourceCandidates);
+ }
+
+}