Search in sources :

Example 1 with AerospikeException

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

the class AsyncMultiCommand method parseGroup.

final boolean parseGroup(int receiveSize) {
    // Parse each message response and add it to the result array
    dataOffset = 0;
    while (dataOffset < receiveSize) {
        resultCode = dataBuffer[dataOffset + 5] & 0xFF;
        if (resultCode != 0) {
            if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR) {
                if (stopOnNotFound) {
                    return true;
                }
            } else {
                throw new AerospikeException(resultCode);
            }
        }
        // If this is the end marker of the response, do not proceed further
        if ((dataBuffer[dataOffset + 3] & Command.INFO3_LAST) != 0) {
            return true;
        }
        generation = Buffer.bytesToInt(dataBuffer, dataOffset + 6);
        expiration = Buffer.bytesToInt(dataBuffer, dataOffset + 10);
        batchIndex = Buffer.bytesToInt(dataBuffer, dataOffset + 14);
        fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset + 18);
        opCount = Buffer.bytesToShort(dataBuffer, dataOffset + 20);
        dataOffset += Command.MSG_REMAINING_HEADER_SIZE;
        Key key = parseKey();
        parseRow(key);
    }
    return false;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key)

Example 2 with AerospikeException

use of com.aerospike.client.AerospikeException in project YCSB by brianfrankcooper.

the class AerospikeClient method init.

@Override
public void init() throws DBException {
    insertPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
    updatePolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
    Properties props = getProperties();
    namespace = props.getProperty("as.namespace", DEFAULT_NAMESPACE);
    String host = props.getProperty("as.host", DEFAULT_HOST);
    String user = props.getProperty("as.user");
    String password = props.getProperty("as.password");
    int port = Integer.parseInt(props.getProperty("as.port", DEFAULT_PORT));
    int timeout = Integer.parseInt(props.getProperty("as.timeout", DEFAULT_TIMEOUT));
    readPolicy.timeout = timeout;
    insertPolicy.timeout = timeout;
    updatePolicy.timeout = timeout;
    deletePolicy.timeout = timeout;
    ClientPolicy clientPolicy = new ClientPolicy();
    if (user != null && password != null) {
        clientPolicy.user = user;
        clientPolicy.password = password;
    }
    try {
        client = new com.aerospike.client.AerospikeClient(clientPolicy, host, port);
    } catch (AerospikeException e) {
        throw new DBException(String.format("Error while creating Aerospike " + "client for %s:%d.", host, port), e);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) DBException(com.yahoo.ycsb.DBException) ClientPolicy(com.aerospike.client.policy.ClientPolicy) Properties(java.util.Properties)

Example 3 with AerospikeException

use of com.aerospike.client.AerospikeException in project YCSB by brianfrankcooper.

the class AerospikeClient method write.

private Status write(String table, String key, WritePolicy writePolicy, HashMap<String, ByteIterator> values) {
    Bin[] bins = new Bin[values.size()];
    int index = 0;
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        bins[index] = new Bin(entry.getKey(), entry.getValue().toArray());
        ++index;
    }
    Key keyObj = new Key(namespace, table, key);
    try {
        client.put(writePolicy, keyObj, bins);
        return Status.OK;
    } catch (AerospikeException e) {
        System.err.println("Error while writing key " + key + ": " + e);
        return Status.ERROR;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Bin(com.aerospike.client.Bin) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key)

Example 4 with AerospikeException

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

the class QueryPredExp method createIndex.

private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) IndexTask(com.aerospike.client.task.IndexTask)

Example 5 with AerospikeException

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

the class Cluster method seedNodes.

private final boolean seedNodes(boolean failIfNotConnected) throws AerospikeException {
    // Must copy array reference for copy on write semantics to work.
    Host[] seedArray = seeds;
    Exception[] exceptions = null;
    // Add all nodes at once to avoid copying entire array multiple times.
    HashMap<String, Node> nodesToAdd = new HashMap<String, Node>(seedArray.length + 16);
    for (int i = 0; i < seedArray.length; i++) {
        Host seed = seedArray[i];
        try {
            NodeValidator nv = new NodeValidator();
            nv.seedNodes(this, seed, nodesToAdd);
        } catch (Exception e) {
            // Store exception and try next host
            if (failIfNotConnected) {
                if (exceptions == null) {
                    exceptions = new Exception[seedArray.length];
                }
                exceptions[i] = e;
            } else {
                if (Log.warnEnabled()) {
                    Log.warn("Seed " + seed + " failed: " + Util.getErrorMessage(e));
                }
            }
        }
    }
    if (nodesToAdd.size() > 0) {
        addNodes(nodesToAdd);
        return true;
    } else if (failIfNotConnected) {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Failed to connect to host(s): ");
        sb.append(Environment.Newline);
        for (int i = 0; i < seedArray.length; i++) {
            sb.append(seedArray[i]);
            sb.append(' ');
            Exception ex = exceptions == null ? null : exceptions[i];
            if (ex != null) {
                sb.append(ex.getMessage());
                sb.append(Environment.Newline);
            }
        }
        throw new AerospikeException.Connection(sb.toString());
    }
    return false;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) HashMap(java.util.HashMap) Host(com.aerospike.client.Host) AerospikeException(com.aerospike.client.AerospikeException)

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