Search in sources :

Example 1 with TCondition

use of org.apache.accumulo.core.dataImpl.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) {
    mutations.getMutations().forEach((keyExtent, mutationList) -> {
        var tcondMutaions = new ArrayList<TConditionalMutation>();
        for (var cm : mutationList) {
            TMutation tm = cm.toThrift();
            List<TCondition> conditions = convertConditions(cm, compressedIters);
            cmidToCm.put(cmid.longValue(), new CMK(keyExtent, cm));
            TConditionalMutation tcm = new TConditionalMutation(conditions, tm, cmid.longValue());
            cmid.increment();
            tcondMutaions.add(tcm);
        }
        tmutations.put(keyExtent.toThrift(), tcondMutaions);
    });
}
Also used : TCondition(org.apache.accumulo.core.dataImpl.thrift.TCondition) ArrayList(java.util.ArrayList) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) TConditionalMutation(org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation)

Example 2 with TCondition

use of org.apache.accumulo.core.dataImpl.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.dataImpl.thrift.TCondition) Condition(org.apache.accumulo.core.data.Condition) TCondition(org.apache.accumulo.core.dataImpl.thrift.TCondition) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 3 with TCondition

use of org.apache.accumulo.core.dataImpl.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.dataImpl.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)

Aggregations

TCondition (org.apache.accumulo.core.dataImpl.thrift.TCondition)3 ArrayList (java.util.ArrayList)2 ByteBuffer (java.nio.ByteBuffer)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 TConditionalMutation (org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation)1 TMutation (org.apache.accumulo.core.dataImpl.thrift.TMutation)1 Text (org.apache.hadoop.io.Text)1