Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -19,6 +19,7 @@
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
@@ -88,8 +89,10 @@
protected FailureDetector failureDetector;
private final int maxBootstrapRetries;
private final StoreStats stats;
+ private final ClientConfig config;
public AbstractStoreClientFactory(ClientConfig config) {
+ this.config = config;
this.threadPool = new ClientThreadPool(config.getMaxThreads(),
config.getThreadIdleTime(TimeUnit.MILLISECONDS),
config.getMaxQueuedRequests());
@@ -156,7 +159,7 @@ public AbstractStoreClientFactory(ClientConfig config) {
repairReads,
threadPool,
routingTimeoutMs,
- failureDetector,
+ getFailureDetector(),
SystemTime.INSTANCE);
if(isJmxEnabled) {
@@ -188,7 +191,16 @@ public AbstractStoreClientFactory(ClientConfig config) {
return serializedStore;
}
- public FailureDetector getFailureDetector() {
+ protected abstract FailureDetector initFailureDetector(final ClientConfig config,
+ final Collection<Node> nodes);
+
+ public synchronized FailureDetector getFailureDetector() {
+ if (failureDetector == null) {
+ String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY, bootstrapUrls);
+ Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
+ failureDetector = initFailureDetector(config, cluster.getNodes());
+ }
+
return failureDetector;
}
6 src/java/voldemort/client/HttpStoreClientFactory.java
View
@@ -86,11 +86,6 @@ public HttpStoreClientFactory(ClientConfig config) {
config.getMaxConnectionsPerNode());
this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
this.requestFormatFactory = new RequestFormatFactory();
-
- String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
- Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
-
- failureDetector = initFailureDetector(config, cluster.getNodes());
}
@Override
@@ -106,6 +101,7 @@ public HttpStoreClientFactory(ClientConfig config) {
reroute);
}
+ @Override
protected FailureDetector initFailureDetector(final ClientConfig config,
final Collection<Node> nodes) {
ClientStoreVerifier<ByteArray, byte[]> storeVerifier = new ClientStoreVerifier<ByteArray, byte[]>() {
9 src/java/voldemort/client/SocketStoreClientFactory.java
View
@@ -65,11 +65,6 @@ public SocketStoreClientFactory(ClientConfig config) {
config.getSocketBufferSize());
if(config.isJmxEnabled())
JmxUtils.registerMbean(socketPool, JmxUtils.createObjectName(SocketPool.class));
-
- String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
- Cluster cluster = clusterMapper.readCluster(new StringReader(clusterXml));
-
- failureDetector = initFailureDetector(config, cluster.getNodes());
}
@Override
@@ -83,6 +78,7 @@ public SocketStoreClientFactory(ClientConfig config) {
RoutingTier.SERVER.equals(routingTier));
}
+ @Override
protected FailureDetector initFailureDetector(final ClientConfig config,
final Collection<Node> nodes) {
failureDetectorListener = new FailureDetectorListener() {
@@ -145,7 +141,8 @@ protected void validateUrl(URI url) {
@Override
public void close() {
this.socketPool.close();
- this.failureDetector.removeFailureDetectorListener(failureDetectorListener);
+ if (failureDetector != null)
+ this.failureDetector.removeFailureDetectorListener(failureDetectorListener);
this.getThreadPool().shutdown();
super.close();
Please sign in to comment.
Something went wrong with that request. Please try again.