Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved failure detector initialization out of constructor for classes …

…extended AbstractStoreClientFactory

	- Fixes an issue where if a Voldemort server is not started, an
      exception will be thrown at SocketStoreClientFactory's
      construction time (e.g. if we're dependency injecting the
      factory).
  • Loading branch information...
commit 7d9fa3d2be8deb17207891bcda9097cf2f850404 1 parent d7153c9
Alex Feinberg afeinberg authored
16 src/java/voldemort/client/AbstractStoreClientFactory.java
@@ -19,6 +19,7 @@
19 19 import java.io.StringReader;
20 20 import java.net.URI;
21 21 import java.net.URISyntaxException;
  22 +import java.util.Collection;
22 23 import java.util.List;
23 24 import java.util.Map;
24 25 import java.util.concurrent.ExecutorService;
@@ -88,8 +89,10 @@
88 89 protected FailureDetector failureDetector;
89 90 private final int maxBootstrapRetries;
90 91 private final StoreStats stats;
  92 + private final ClientConfig config;
91 93
92 94 public AbstractStoreClientFactory(ClientConfig config) {
  95 + this.config = config;
93 96 this.threadPool = new ClientThreadPool(config.getMaxThreads(),
94 97 config.getThreadIdleTime(TimeUnit.MILLISECONDS),
95 98 config.getMaxQueuedRequests());
@@ -156,7 +159,7 @@ public AbstractStoreClientFactory(ClientConfig config) {
156 159 repairReads,
157 160 threadPool,
158 161 routingTimeoutMs,
159   - failureDetector,
  162 + getFailureDetector(),
160 163 SystemTime.INSTANCE);
161 164
162 165 if(isJmxEnabled) {
@@ -188,7 +191,16 @@ public AbstractStoreClientFactory(ClientConfig config) {
188 191 return serializedStore;
189 192 }
190 193
191   - public FailureDetector getFailureDetector() {
  194 + protected abstract FailureDetector initFailureDetector(final ClientConfig config,
  195 + final Collection<Node> nodes);
  196 +
  197 + public synchronized FailureDetector getFailureDetector() {
  198 + if (failureDetector == null) {
  199 + String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY, bootstrapUrls);
  200 + Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
  201 + failureDetector = initFailureDetector(config, cluster.getNodes());
  202 + }
  203 +
192 204 return failureDetector;
193 205 }
194 206
6 src/java/voldemort/client/HttpStoreClientFactory.java
@@ -86,11 +86,6 @@ public HttpStoreClientFactory(ClientConfig config) {
86 86 config.getMaxConnectionsPerNode());
87 87 this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
88 88 this.requestFormatFactory = new RequestFormatFactory();
89   -
90   - String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
91   - Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
92   -
93   - failureDetector = initFailureDetector(config, cluster.getNodes());
94 89 }
95 90
96 91 @Override
@@ -106,6 +101,7 @@ public HttpStoreClientFactory(ClientConfig config) {
106 101 reroute);
107 102 }
108 103
  104 + @Override
109 105 protected FailureDetector initFailureDetector(final ClientConfig config,
110 106 final Collection<Node> nodes) {
111 107 ClientStoreVerifier<ByteArray, byte[]> storeVerifier = new ClientStoreVerifier<ByteArray, byte[]>() {
9 src/java/voldemort/client/SocketStoreClientFactory.java
@@ -65,11 +65,6 @@ public SocketStoreClientFactory(ClientConfig config) {
65 65 config.getSocketBufferSize());
66 66 if(config.isJmxEnabled())
67 67 JmxUtils.registerMbean(socketPool, JmxUtils.createObjectName(SocketPool.class));
68   -
69   - String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
70   - Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
71   -
72   - failureDetector = initFailureDetector(config, cluster.getNodes());
73 68 }
74 69
75 70 @Override
@@ -83,6 +78,7 @@ public SocketStoreClientFactory(ClientConfig config) {
83 78 RoutingTier.SERVER.equals(routingTier));
84 79 }
85 80
  81 + @Override
86 82 protected FailureDetector initFailureDetector(final ClientConfig config,
87 83 final Collection<Node> nodes) {
88 84 failureDetectorListener = new FailureDetectorListener() {
@@ -145,7 +141,8 @@ protected void validateUrl(URI url) {
145 141 @Override
146 142 public void close() {
147 143 this.socketPool.close();
148   - this.failureDetector.removeFailureDetectorListener(failureDetectorListener);
  144 + if (failureDetector != null)
  145 + this.failureDetector.removeFailureDetectorListener(failureDetectorListener);
149 146 this.getThreadPool().shutdown();
150 147
151 148 super.close();

0 comments on commit 7d9fa3d

Please sign in to comment.
Something went wrong with that request. Please try again.