Search in sources :

Example 81 with AerospikeException

use of com.aerospike.client.AerospikeException 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)

Example 82 with AerospikeException

use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.

the class TestQueryPredExp method prepare.

@BeforeClass
public static void prepare() {
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, args.namespace, setName, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, setName, keyPrefix + i);
        List<Integer> list = null;
        Map<String, String> map = null;
        if (i == 1) {
            list = new ArrayList<Integer>(5);
            list.add(1);
            list.add(2);
            list.add(4);
            list.add(9);
            list.add(20);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 2) {
            list = new ArrayList<Integer>(3);
            list.add(5);
            list.add(9);
            list.add(100);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 3) {
            map = new HashMap<String, String>();
            map.put("A", "AAA");
            map.put("B", "BBB");
            map.put("C", "BBB");
        // list will be null, which means listbin will not exist in this record.
        } else {
            list = new ArrayList<Integer>(0);
            map = new HashMap<String, String>(0);
        }
        client.put(null, key, new Bin(binName, i), new Bin("bin2", i), new Bin("listbin", list), new Bin("mapbin", map));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 83 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTestUtils method cleanMetaTable.

// removes all records from set AerospikeTransactionalStore.DEFAULT_META_SET (used to store
// committed window ids) in namespace NAMESPACE
// 
static void cleanMetaTable() {
    AerospikeClient client = null;
    try {
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(AerospikeTransactionalStore.DEFAULT_META_SET);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            client.delete(null, rs.getKey());
        }
    } catch (AerospikeException e) {
        LOG.error("cleanMetaTable failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Example 84 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTestUtils method getNumOfEventsInStore.

// returns the number of records in set SET_NAME in namespace NAMESPACE
static long getNumOfEventsInStore() {
    AerospikeClient client = null;
    try {
        long count = 0;
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(SET_NAME);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            count++;
        }
        return count;
    } catch (AerospikeException e) {
        LOG.error("getNumOfEventsInStore failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Example 85 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTestUtils method cleanTable.

// removes all records from set SET_NAME in namespace NAMESPACE
static void cleanTable() {
    AerospikeClient client = null;
    try {
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(SET_NAME);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            client.delete(null, rs.getKey());
        }
    } catch (AerospikeException e) {
        LOG.error("cleanTable failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)175 Record (com.aerospike.client.Record)58 Test (org.junit.Test)58 Policy (com.aerospike.client.policy.Policy)57 Key (com.aerospike.client.Key)56 WritePolicy (com.aerospike.client.policy.WritePolicy)42 ThrowingRunnable (org.junit.function.ThrowingRunnable)41 Bin (com.aerospike.client.Bin)32 IndexTask (com.aerospike.client.task.IndexTask)29 BatchPolicy (com.aerospike.client.policy.BatchPolicy)28 BeforeClass (org.junit.BeforeClass)14 IOException (java.io.IOException)12 Node (com.aerospike.client.cluster.Node)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 RegisterTask (com.aerospike.client.task.RegisterTask)7 Expression (com.aerospike.client.exp.Expression)6 SocketTimeoutException (java.net.SocketTimeoutException)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 Value (com.aerospike.client.Value)5