Search in sources :

Example 61 with AerospikeException

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

the class TestAsyncQuery method asyncQuery.

@Test
public void asyncQuery() {
    WriteListener listener = new WriteListener() {

        private int count = 0;

        public void onSuccess(final Key key) {
            // in the same event loop thread.
            if (++count == size) {
                runQuery();
            }
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    };
    for (int i = 1; i <= size; i++) {
        final Key key = new Key(args.namespace, args.set, keyPrefix + i);
        Bin bin = new Bin(binName, i);
        client.put(eventLoop, listener, null, key, bin);
    }
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) WriteListener(com.aerospike.client.listener.WriteListener) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 62 with AerospikeException

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

the class QueryInteger 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 63 with AerospikeException

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

the class QuerySum 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 64 with AerospikeException

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

the class PartitionTracker method isComplete.

public boolean isComplete(Policy policy) {
    long recordCount = 0;
    int partsRequested = 0;
    int partsReceived = 0;
    for (NodePartitions np : nodePartitionsList) {
        recordCount += np.recordCount;
        partsRequested += np.partsRequested;
        partsReceived += np.partsReceived;
    // System.out.println("Node " + np.node + " partsFull=" + np.partsFull.size() + " partsPartial=" + np.partsPartial.size() +
    // " partsReceived=" + np.partsReceived + " recordsRequested=" + np.recordMax + " recordsReceived=" + np.recordCount);
    }
    if (partsReceived >= partsRequested) {
        if (partitionFilter != null && recordCount == 0) {
            partitionFilter.done = true;
        }
        return true;
    }
    if (maxRecords > 0 && recordCount >= maxRecords) {
        return true;
    }
    // Check if limits have been reached.
    if (iteration > policy.maxRetries) {
        StringBuilder sb = new StringBuilder(2048);
        sb.append("Max retries exceeded: ");
        sb.append(policy.maxRetries);
        sb.append(System.lineSeparator());
        if (exceptions != null) {
            sb.append("sub-exceptions:");
            sb.append(System.lineSeparator());
            for (AerospikeException ae : exceptions) {
                sb.append(ae.getMessage());
                sb.append(System.lineSeparator());
            }
        }
        AerospikeException ae = new AerospikeException(ResultCode.MAX_RETRIES_EXCEEDED, sb.toString());
        ae.setPolicy(policy);
        ae.setIteration(iteration);
        throw ae;
    }
    if (policy.totalTimeout > 0) {
        // Check for total timeout.
        long remaining = deadline - System.nanoTime() - TimeUnit.MILLISECONDS.toNanos(sleepBetweenRetries);
        if (remaining <= 0) {
            throw new AerospikeException.Timeout(policy, iteration);
        }
        // Convert back to milliseconds for remaining check.
        remaining = TimeUnit.NANOSECONDS.toMillis(remaining);
        if (remaining < totalTimeout) {
            totalTimeout = (int) remaining;
            if (socketTimeout > totalTimeout) {
                socketTimeout = totalTimeout;
            }
        }
    }
    // Prepare for next iteration.
    if (maxRecords > 0) {
        maxRecords -= recordCount;
    }
    iteration++;
    return false;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException)

Example 65 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 {
    while (dataOffset < receiveSize) {
        dataOffset += 3;
        info3 = dataBuffer[dataOffset] & 0xFF;
        dataOffset += 2;
        resultCode = dataBuffer[dataOffset] & 0xFF;
        // If this is the end marker of the response, do not proceed further.
        if ((info3 & Command.INFO3_LAST) != 0) {
            if (resultCode != 0) {
                // The server returned a fatal error.
                throw new AerospikeException(resultCode);
            }
            return false;
        }
        dataOffset++;
        generation = Buffer.bytesToInt(dataBuffer, dataOffset);
        dataOffset += 4;
        expiration = Buffer.bytesToInt(dataBuffer, dataOffset);
        dataOffset += 4;
        batchIndex = Buffer.bytesToInt(dataBuffer, dataOffset);
        dataOffset += 4;
        fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset);
        dataOffset += 2;
        opCount = Buffer.bytesToShort(dataBuffer, dataOffset);
        dataOffset += 2;
        if (isBatch) {
            skipKey(fieldCount);
            parseRow(null);
        } else {
            Key key = parseKey(fieldCount);
            parseRow(key);
        }
    }
    return true;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key)

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