Search in sources :

Example 11 with AerospikeException

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

the class NioCommand method onServerTimeout.

protected final void onServerTimeout() {
    conn.unregister();
    command.node.putAsyncConnection(conn, eventLoop.index);
    if (command.isRead) {
        // Read commands shift to prole node on timeout.
        command.sequence++;
    }
    AerospikeException ae = new AerospikeException.Timeout(command.node, command.policy.socketTimeout, iteration, false);
    retry(ae);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) HashedWheelTimeout(com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)

Example 12 with AerospikeException

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

the class NioCommand method totalTimeout.

private final void totalTimeout() {
    AerospikeException ae = new AerospikeException.Timeout(command.node, command.policy.socketTimeout, iteration, true);
    // Attempt timeout delay.
    if (command.policy.timeoutDelay > 0) {
        // Notify user of timeout, but allow transaction to continue in hope of reusing the socket.
        timeoutDelay = true;
        notifyFailure(ae);
        deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(command.policy.timeoutDelay);
        timeoutTask = eventLoop.timer.addTimeout(this, deadline);
        return;
    }
    // Perform timeout.
    timeoutTask = null;
    fail();
    notifyFailure(ae);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) HashedWheelTimeout(com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)

Example 13 with AerospikeException

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

the class MultiCommand method parseGroup.

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

Example 14 with AerospikeException

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

the class Util method readResource.

public static byte[] readResource(ClassLoader resourceLoader, String resourcePath) {
    try {
        URL url = resourceLoader.getResource(resourcePath);
        InputStream is = url.openStream();
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
            byte[] bytes = new byte[8192];
            int length;
            while ((length = is.read(bytes)) > 0) {
                bos.write(bytes, 0, length);
            }
            return bos.toByteArray();
        } finally {
            is.close();
        }
    } catch (Exception e) {
        throw new AerospikeException("Failed to read resource " + resourcePath, e);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) EOFException(java.io.EOFException) AerospikeException(com.aerospike.client.AerospikeException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ParseException(java.text.ParseException)

Example 15 with AerospikeException

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

the class IndexTask method queryStatus.

/**
	 * Query all nodes for task completion status.
	 */
@Override
public int queryStatus() throws AerospikeException {
    // All nodes must respond with load_pct of 100 to be considered done.
    Node[] nodes = cluster.getNodes();
    if (nodes.length == 0) {
        throw new AerospikeException("Cluster is empty");
    }
    String command = "sindex/" + namespace + '/' + indexName;
    for (Node node : nodes) {
        String response = Info.request(policy, node, command);
        String find = "load_pct=";
        int index = response.indexOf(find);
        if (index < 0) {
            if (response.indexOf("FAIL:201") >= 0 || response.indexOf("FAIL:203") >= 0) {
                // Index not found or not readable.
                return Task.NOT_FOUND;
            } else {
                // Throw exception immediately.
                throw new AerospikeException(command + " failed: " + response);
            }
        }
        int begin = index + find.length();
        int end = response.indexOf(';', begin);
        String str = response.substring(begin, end);
        int pct = Integer.parseInt(str);
        if (pct != 100) {
            return Task.IN_PROGRESS;
        }
    }
    return Task.COMPLETE;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Node(com.aerospike.client.cluster.Node)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)71 Key (com.aerospike.client.Key)33 Record (com.aerospike.client.Record)18 Test (org.junit.Test)16 Bin (com.aerospike.client.Bin)13 Node (com.aerospike.client.cluster.Node)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 Value (com.aerospike.client.Value)5 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)5 WritePolicy (com.aerospike.client.policy.WritePolicy)5 HashMap (java.util.HashMap)5 HashedWheelTimeout (com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)4 Connection (com.aerospike.client.cluster.Connection)4 WriteListener (com.aerospike.client.listener.WriteListener)4 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 Partition (com.aerospike.client.cluster.Partition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3