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);
});
}
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;
}
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;
}
Aggregations