use of org.apache.accumulo.core.dataImpl.thrift.TMutation in project accumulo by apache.
the class MutationTest method testThrift_Invalid.
@Test
public void testThrift_Invalid() {
Mutation m1 = new Mutation("r1");
m1.put("cf1", "cq1", "v1");
TMutation tm1 = m1.toThrift();
tm1.setRow((byte[]) null);
assertThrows(IllegalArgumentException.class, () -> new Mutation(tm1));
}
use of org.apache.accumulo.core.dataImpl.thrift.TMutation in project accumulo by apache.
the class MutationTest method testThrift.
@Test
public void testThrift() {
Mutation m1 = new Mutation("r1");
m1.put("cf1", "cq1", "v1");
TMutation tm1 = m1.toThrift();
Mutation m2 = new Mutation(tm1);
assertEquals(m1, m2);
}
use of org.apache.accumulo.core.dataImpl.thrift.TMutation 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.TMutation in project accumulo by apache.
the class Mutation method toThrift.
private TMutation toThrift(boolean serialize) {
if (serialize) {
this.serialize();
}
ByteBuffer data = serializedSnapshot();
TMutation tmutation = new TMutation(ByteBuffer.wrap(row), data, ByteBufferUtil.toByteBuffers(values), entries);
if (!this.replicationSources.isEmpty()) {
tmutation.setSources(new ArrayList<>(replicationSources));
}
return tmutation;
}
use of org.apache.accumulo.core.dataImpl.thrift.TMutation in project accumulo by apache.
the class ThriftClientHandler method update.
@Override
public void update(TInfo tinfo, TCredentials credentials, TKeyExtent tkeyExtent, TMutation tmutation, TDurability tdurability) throws NotServingTabletException, ConstraintViolationException, ThriftSecurityException {
final TableId tableId = TableId.of(new String(tkeyExtent.getTable(), UTF_8));
NamespaceId namespaceId = getNamespaceId(credentials, tableId);
if (!security.canWrite(credentials, tableId, namespaceId)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
final KeyExtent keyExtent = KeyExtent.fromThrift(tkeyExtent);
final Tablet tablet = server.getOnlineTablet(KeyExtent.copyOf(keyExtent));
if (tablet == null) {
throw new NotServingTabletException(tkeyExtent);
}
Durability tabletDurability = tablet.getDurability();
if (!keyExtent.isMeta()) {
try {
server.resourceManager.waitUntilCommitsAreEnabled();
} catch (HoldTimeoutException hte) {
// was a failure and it should retry.
throw new NotServingTabletException(tkeyExtent);
}
}
final long opid = writeTracker.startWrite(TabletType.type(keyExtent));
try {
final Mutation mutation = new ServerMutation(tmutation);
final List<Mutation> mutations = Collections.singletonList(mutation);
PreparedMutations prepared;
Span span = TraceUtil.startSpan(this.getClass(), "update::prep");
try (Scope scope = span.makeCurrent()) {
prepared = tablet.prepareMutationsForCommit(new TservConstraintEnv(server.getContext(), security, credentials), mutations);
} catch (Exception e) {
TraceUtil.setException(span, e, true);
throw e;
} finally {
span.end();
}
if (prepared.tabletClosed()) {
throw new NotServingTabletException(tkeyExtent);
} else if (!prepared.getViolators().isEmpty()) {
throw new ConstraintViolationException(prepared.getViolations().asList().stream().map(ConstraintViolationSummary::toThrift).collect(Collectors.toList()));
} else {
CommitSession session = prepared.getCommitSession();
Durability durability = DurabilityImpl.resolveDurabilty(DurabilityImpl.fromThrift(tdurability), tabletDurability);
// Instead of always looping on true, skip completely when durability is NONE.
while (durability != Durability.NONE) {
try {
Span span2 = TraceUtil.startSpan(this.getClass(), "update::wal");
try (Scope scope = span2.makeCurrent()) {
server.logger.log(session, mutation, durability);
} catch (Exception e) {
TraceUtil.setException(span2, e, true);
throw e;
} finally {
span2.end();
}
break;
} catch (IOException ex) {
log.warn("Error writing mutations to log", ex);
}
}
Span span3 = TraceUtil.startSpan(this.getClass(), "update::commit");
try (Scope scope = span3.makeCurrent()) {
session.commit(mutations);
} catch (Exception e) {
TraceUtil.setException(span3, e, true);
throw e;
} finally {
span3.end();
}
}
} finally {
writeTracker.finishWrite(opid);
}
}
Aggregations