Search in sources :

Example 6 with CommandExp

use of com.aerospike.client.exp.CommandExp in project aerospike-client-java by aerospike.

the class Command method setBatchRead.

public final void setBatchRead(BatchPolicy policy, Key[] keys, BatchNode batch, String[] binNames, Operation[] ops, int readAttr) {
    // Estimate full row size
    final int[] offsets = batch.offsets;
    final int max = batch.offsetsSize;
    final int fieldCountRow = policy.sendSetName ? 2 : 1;
    // Estimate buffer size.
    begin();
    int fieldCount = 1;
    CommandExp exp = getCommandExp(policy);
    if (exp != null) {
        dataOffset += exp.size();
        fieldCount++;
    }
    dataOffset += FIELD_HEADER_SIZE + 5;
    Key prev = null;
    for (int i = 0; i < max; i++) {
        Key key = keys[offsets[i]];
        dataOffset += key.digest.length + 4;
        // Try reference equality in hope that namespace/set for all keys is set from fixed variables.
        if (prev != null && prev.namespace == key.namespace && (!policy.sendSetName || prev.setName == key.setName)) {
            // Can set repeat previous namespace/bin names to save space.
            dataOffset++;
        } else {
            // Must write full header and namespace/set/bin names.
            dataOffset += Buffer.estimateSizeUtf8(key.namespace) + FIELD_HEADER_SIZE + 6;
            if (policy.sendSetName) {
                dataOffset += Buffer.estimateSizeUtf8(key.setName) + FIELD_HEADER_SIZE;
            }
            if (binNames != null) {
                for (String binName : binNames) {
                    estimateOperationSize(binName);
                }
            } else if (ops != null) {
                for (Operation op : ops) {
                    estimateReadOperationSize(op);
                }
            }
            prev = key;
        }
    }
    sizeBuffer();
    if (policy.readModeAP == ReadModeAP.ALL) {
        readAttr |= Command.INFO1_READ_MODE_AP_ALL;
    }
    writeHeaderRead(policy, totalTimeout, readAttr | Command.INFO1_BATCH, fieldCount, 0);
    if (exp != null) {
        dataOffset = exp.write(this);
    }
    int fieldSizeOffset = dataOffset;
    // Need to update size at end
    writeFieldHeader(0, policy.sendSetName ? FieldType.BATCH_INDEX_WITH_SET : FieldType.BATCH_INDEX);
    Buffer.intToBytes(max, dataBuffer, dataOffset);
    dataOffset += 4;
    dataBuffer[dataOffset++] = (policy.allowInline) ? (byte) 1 : (byte) 0;
    prev = null;
    for (int i = 0; i < max; i++) {
        int index = offsets[i];
        Buffer.intToBytes(index, dataBuffer, dataOffset);
        dataOffset += 4;
        Key key = keys[index];
        byte[] digest = key.digest;
        System.arraycopy(digest, 0, dataBuffer, dataOffset, digest.length);
        dataOffset += digest.length;
        // Try reference equality in hope that namespace/set for all keys is set from fixed variables.
        if (prev != null && prev.namespace == key.namespace && (!policy.sendSetName || prev.setName == key.setName)) {
            // Can set repeat previous namespace/bin names to save space.
            // repeat
            dataBuffer[dataOffset++] = 1;
        } else {
            // Write full header, namespace and bin names.
            // do not repeat
            dataBuffer[dataOffset++] = 0;
            if (binNames != null && binNames.length != 0) {
                dataBuffer[dataOffset++] = (byte) readAttr;
                writeBatchFields(policy, key, fieldCountRow, binNames.length);
                for (String binName : binNames) {
                    writeOperation(binName, Operation.Type.READ);
                }
            } else if (ops != null) {
                int offset = dataOffset++;
                writeBatchFields(policy, key, fieldCountRow, ops.length);
                dataBuffer[offset] = (byte) writeOperations(ops, readAttr);
            } else {
                dataBuffer[dataOffset++] = (byte) readAttr;
                writeBatchFields(policy, key, fieldCountRow, 0);
            }
            prev = key;
        }
    }
    // Write real field size.
    Buffer.intToBytes(dataOffset - MSG_TOTAL_HEADER_SIZE - 4, dataBuffer, fieldSizeOffset);
    end();
    compress(policy);
}
Also used : Operation(com.aerospike.client.Operation) CommandExp(com.aerospike.client.exp.CommandExp) Key(com.aerospike.client.Key)

Example 7 with CommandExp

use of com.aerospike.client.exp.CommandExp in project aerospike-client-java by aerospike.

the class Command method setWrite.

public final void setWrite(WritePolicy policy, Operation.Type operation, Key key, Bin[] bins) {
    begin();
    int fieldCount = estimateKeySize(policy, key);
    CommandExp exp = getCommandExp(policy);
    if (exp != null) {
        dataOffset += exp.size();
        fieldCount++;
    }
    for (Bin bin : bins) {
        estimateOperationSize(bin);
    }
    sizeBuffer();
    writeHeaderWrite(policy, Command.INFO2_WRITE, fieldCount, bins.length);
    writeKey(policy, key);
    if (exp != null) {
        dataOffset = exp.write(this);
    }
    for (Bin bin : bins) {
        writeOperation(bin, operation);
    }
    end();
    compress(policy);
}
Also used : Bin(com.aerospike.client.Bin) CommandExp(com.aerospike.client.exp.CommandExp)

Example 8 with CommandExp

use of com.aerospike.client.exp.CommandExp in project aerospike-client-java by aerospike.

the class Command method setRead.

public final void setRead(Policy policy, Key key, String[] binNames) {
    if (binNames != null) {
        begin();
        int fieldCount = estimateKeySize(policy, key);
        CommandExp exp = getCommandExp(policy);
        if (exp != null) {
            dataOffset += exp.size();
            fieldCount++;
        }
        for (String binName : binNames) {
            estimateOperationSize(binName);
        }
        sizeBuffer();
        writeHeaderRead(policy, serverTimeout, Command.INFO1_READ, fieldCount, binNames.length);
        writeKey(policy, key);
        if (exp != null) {
            dataOffset = exp.write(this);
        }
        for (String binName : binNames) {
            writeOperation(binName, Operation.Type.READ);
        }
        end();
    } else {
        setRead(policy, key);
    }
}
Also used : CommandExp(com.aerospike.client.exp.CommandExp)

Example 9 with CommandExp

use of com.aerospike.client.exp.CommandExp in project aerospike-client-java by aerospike.

the class Command method setDelete.

public void setDelete(WritePolicy policy, Key key) {
    begin();
    int fieldCount = estimateKeySize(policy, key);
    CommandExp exp = getCommandExp(policy);
    if (exp != null) {
        dataOffset += exp.size();
        fieldCount++;
    }
    sizeBuffer();
    writeHeaderWrite(policy, Command.INFO2_WRITE | Command.INFO2_DELETE, fieldCount, 0);
    writeKey(policy, key);
    if (exp != null) {
        dataOffset = exp.write(this);
    }
    end();
}
Also used : CommandExp(com.aerospike.client.exp.CommandExp)

Example 10 with CommandExp

use of com.aerospike.client.exp.CommandExp in project aerospike-client-java by aerospike.

the class Command method setReadHeader.

public final void setReadHeader(Policy policy, Key key) {
    begin();
    int fieldCount = estimateKeySize(policy, key);
    CommandExp exp = getCommandExp(policy);
    if (exp != null) {
        dataOffset += exp.size();
        fieldCount++;
    }
    estimateOperationSize((String) null);
    sizeBuffer();
    writeHeaderReadHeader(policy, Command.INFO1_READ | Command.INFO1_NOBINDATA, fieldCount, 0);
    writeKey(policy, key);
    if (exp != null) {
        dataOffset = exp.write(this);
    }
    end();
}
Also used : CommandExp(com.aerospike.client.exp.CommandExp)

Aggregations

CommandExp (com.aerospike.client.exp.CommandExp)13 Operation (com.aerospike.client.Operation)4 Key (com.aerospike.client.Key)2 PartitionStatus (com.aerospike.client.query.PartitionStatus)2 BatchRead (com.aerospike.client.BatchRead)1 Bin (com.aerospike.client.Bin)1 QueryPolicy (com.aerospike.client.policy.QueryPolicy)1 Filter (com.aerospike.client.query.Filter)1 IndexCollectionType (com.aerospike.client.query.IndexCollectionType)1 PredExp (com.aerospike.client.query.PredExp)1