Search in sources :

Example 1 with TCondition

use of org.apache.accumulo.core.data.thrift.TCondition in project accumulo by apache.

the class ConditionalWriterImpl method convertMutations.

private void convertMutations(TabletServerMutations<QCMutation> mutations, Map<Long, CMK> cmidToCm, MutableLong cmid, Map<TKeyExtent, List<TConditionalMutation>> tmutations, CompressedIterators compressedIters) {
    for (Entry<KeyExtent, List<QCMutation>> entry : mutations.getMutations().entrySet()) {
        TKeyExtent tke = entry.getKey().toThrift();
        ArrayList<TConditionalMutation> tcondMutaions = new ArrayList<>();
        List<QCMutation> condMutations = entry.getValue();
        for (QCMutation cm : condMutations) {
            TMutation tm = cm.toThrift();
            List<TCondition> conditions = convertConditions(cm, compressedIters);
            cmidToCm.put(cmid.longValue(), new CMK(entry.getKey(), cm));
            TConditionalMutation tcm = new TConditionalMutation(conditions, tm, cmid.longValue());
            cmid.increment();
            tcondMutaions.add(tcm);
        }
        tmutations.put(tke, tcondMutaions);
    }
}
Also used : ArrayList(java.util.ArrayList) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) TConditionalMutation(org.apache.accumulo.core.data.thrift.TConditionalMutation) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TCondition(org.apache.accumulo.core.data.thrift.TCondition) List(java.util.List) ArrayList(java.util.ArrayList) TMutation(org.apache.accumulo.core.data.thrift.TMutation)

Example 2 with TCondition

use of org.apache.accumulo.core.data.thrift.TCondition in project accumulo by apache.

the class ConditionCheckerContext method checkConditions.

boolean checkConditions(SortedKeyValueIterator<Key, Value> systemIter, ServerConditionalMutation scm) throws IOException {
    boolean add = true;
    for (TCondition tc : scm.getConditions()) {
        Range range;
        if (tc.hasTimestamp)
            range = Range.exact(new Text(scm.getRow()), new Text(tc.getCf()), new Text(tc.getCq()), new Text(tc.getCv()), tc.getTs());
        else
            range = Range.exact(new Text(scm.getRow()), new Text(tc.getCf()), new Text(tc.getCq()), new Text(tc.getCv()));
        SortedKeyValueIterator<Key, Value> iter = buildIterator(systemIter, tc);
        ByteSequence cf = new ArrayByteSequence(tc.getCf());
        iter.seek(range, Collections.singleton(cf), true);
        Value val = null;
        if (iter.hasTop()) {
            val = iter.getTopValue();
        }
        if ((val == null ^ tc.getVal() == null) || (val != null && !Arrays.equals(tc.getVal(), val.get()))) {
            add = false;
            break;
        }
    }
    return add;
}
Also used : TCondition(org.apache.accumulo.core.data.thrift.TCondition) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 3 with TCondition

use of org.apache.accumulo.core.data.thrift.TCondition in project accumulo by apache.

the class ConditionalWriterImpl method convertConditions.

private List<TCondition> convertConditions(ConditionalMutation cm, CompressedIterators compressedIters) {
    List<TCondition> conditions = new ArrayList<>(cm.getConditions().size());
    // sort conditions inorder to get better lookup performance. Sort on client side so tserver does not have to do it.
    Condition[] ca = cm.getConditions().toArray(new Condition[cm.getConditions().size()]);
    Arrays.sort(ca, CONDITION_COMPARATOR);
    for (Condition cond : ca) {
        long ts = 0;
        boolean hasTs = false;
        if (cond.getTimestamp() != null) {
            ts = cond.getTimestamp();
            hasTs = true;
        }
        ByteBuffer iters = compressedIters.compress(cond.getIterators());
        TCondition tc = new TCondition(ByteBufferUtil.toByteBuffers(cond.getFamily()), ByteBufferUtil.toByteBuffers(cond.getQualifier()), ByteBufferUtil.toByteBuffers(cond.getVisibility()), ts, hasTs, ByteBufferUtil.toByteBuffers(cond.getValue()), iters);
        conditions.add(tc);
    }
    return conditions;
}
Also used : TCondition(org.apache.accumulo.core.data.thrift.TCondition) Condition(org.apache.accumulo.core.data.Condition) TCondition(org.apache.accumulo.core.data.thrift.TCondition) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TCondition (org.apache.accumulo.core.data.thrift.TCondition)3 ArrayList (java.util.ArrayList)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 Condition (org.apache.accumulo.core.data.Condition)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 TConditionalMutation (org.apache.accumulo.core.data.thrift.TConditionalMutation)1 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)1 TMutation (org.apache.accumulo.core.data.thrift.TMutation)1 Text (org.apache.hadoop.io.Text)1