use of org.apache.accumulo.tserver.RowLocks.RowLock in project accumulo by apache.
the class ThriftClientHandler method conditionalUpdate.
private Map<KeyExtent, List<ServerConditionalMutation>> conditionalUpdate(ConditionalSession cs, Map<KeyExtent, List<ServerConditionalMutation>> updates, ArrayList<TCMResult> results, List<String> symbols) throws IOException {
// sort each list of mutations, this is done to avoid deadlock and doing seeks in order is
// more efficient and detect duplicate rows.
ConditionalMutationSet.sortConditionalMutations(updates);
Map<KeyExtent, List<ServerConditionalMutation>> deferred = new HashMap<>();
// can not process two mutations for the same row, because one will not see what the other
// writes
ConditionalMutationSet.deferDuplicatesRows(updates, deferred);
// get as many locks as possible w/o blocking... defer any rows that are locked
List<RowLock> locks = rowLocks.acquireRowlocks(updates, deferred);
try {
Span span = TraceUtil.startSpan(this.getClass(), "conditionalUpdate::Check conditions");
try (Scope scope = span.makeCurrent()) {
checkConditions(updates, results, cs, symbols);
} catch (Exception e) {
TraceUtil.setException(span, e, true);
throw e;
} finally {
span.end();
}
Span span2 = TraceUtil.startSpan(this.getClass(), "conditionalUpdate::apply conditional mutations");
try (Scope scope = span2.makeCurrent()) {
writeConditionalMutations(updates, results, cs);
} catch (Exception e) {
TraceUtil.setException(span2, e, true);
throw e;
} finally {
span2.end();
}
} finally {
rowLocks.releaseRowLocks(locks);
}
return deferred;
}
Aggregations