use of com.aerospike.client.cluster.Partitions in project aerospike-client-java by aerospike.
the class Command method getSequenceNode.
private final Node getSequenceNode(Cluster cluster, Partition partition) {
// Must copy hashmap reference for copy on write semantics to work.
HashMap<String, Partitions> map = cluster.partitionMap;
Partitions partitions = map.get(partition.namespace);
if (partitions == null) {
throw new AerospikeException("Invalid namespace: " + partition.namespace);
}
AtomicReferenceArray<Node>[] replicas = partitions.replicas;
for (int i = 0; i < replicas.length; i++) {
int index = Math.abs(sequence % replicas.length);
Node node = replicas[index].get(partition.partitionId);
if (node != null && node.isActive()) {
return node;
}
sequence++;
}
if (partitions.cpMode) {
throw new AerospikeException.InvalidNode();
}
return cluster.getRandomNode();
}
Aggregations