Search in sources :

Example 1 with Partitions

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();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Partitions(com.aerospike.client.cluster.Partitions) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) Node(com.aerospike.client.cluster.Node)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)1 Node (com.aerospike.client.cluster.Node)1 Partitions (com.aerospike.client.cluster.Partitions)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1