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();
}
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));
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
Aggregations