Skip to content
Permalink
Browse files

Bind clients to a single node

  • Loading branch information
aphyr committed Nov 14, 2017
1 parent 74785b5 commit 672977a82cc4f2113e1f633ad06885b278673997
@@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aerospike</groupId>
<groupId>io.jepsen</groupId>
<artifactId>aerospike-client</artifactId>
<version>4.1.0</version>
<packaging>jar</packaging>
@@ -224,10 +224,18 @@ public AerospikeClient(ClientPolicy policy, Host... hosts) throws AerospikeExcep
this.queryPolicyDefault = policy.queryPolicyDefault;
this.batchPolicyDefault = policy.batchPolicyDefault;
this.infoPolicyDefault = policy.infoPolicyDefault;

cluster = new Cluster(policy, hosts);
cluster.initTendThread(policy.failIfNotConnected);
}

cluster = new Cluster(policy, hosts);

// We want to bind to a single node
// cluster.initTendThread(policy.failIfNotConnected);
try {
cluster.forceSingleNode();
} catch (Exception e) {
close();
throw e;
}
}

//-------------------------------------------------------
// Protected Initialization
@@ -204,7 +204,44 @@ public Cluster(ClientPolicy policy, Host[] hosts) throws AerospikeException {
eventState = null;
}
}


public void forceSingleNode() {
// Initialize tendThread, but do not start it.
tendValid = true;
tendThread = new Thread(this);

// Validate first seed.
Host seed = seeds[0];
NodeValidator nv = new NodeValidator();
HashMap<String,Node> nodesToAdd = new HashMap<String,Node>();

try {
nv.seedNodes(this, seed, nodesToAdd);
}
catch (Exception e) {
throw new AerospikeException(e.getMessage(), e);
}

// Add seed node to nodes.
addNodes(nodesToAdd);
Node node = nodes[0];

// Initialize partitionMaps.
Peers peers = new Peers(nodes.length + 16, 16);
node.refreshPartitions(peers);

// Set partition maps for all namespaces to point to same node.
for (Partitions partitions : partitionMap.values()) {
for (AtomicReferenceArray<Node> nodeArray : partitions.replicas) {
int max = nodeArray.length();

for (int i = 0; i < max; i++) {
nodeArray.set(i, node);
}
}
}
}

public void initTendThread(boolean failIfNotConnected) throws AerospikeException {
// Tend cluster until all nodes identified.
waitTillStabilized(failIfNotConnected);
@@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aerospike</groupId>
<groupId>io.jepsen</groupId>
<artifactId>aerospike-parent</artifactId>
<name>aerospike-parent</name>
<version>4.1.0</version>
@@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aerospike</groupId>
<groupId>io.jepsen</groupId>
<artifactId>aerospike</artifactId>
<packaging>war</packaging>
<version>4.1.0</version>
@@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aerospike</groupId>
<groupId>io.jepsen</groupId>
<artifactId>aerospike-client-test</artifactId>
<version>4.1.0</version>
<packaging>jar</packaging>

0 comments on commit 672977a

Please sign in to comment.