Search in sources :

Example 1 with TMutation

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));
}
Also used : TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) Test(org.junit.jupiter.api.Test)

Example 2 with TMutation

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);
}
Also used : TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) Test(org.junit.jupiter.api.Test)

Example 3 with TMutation

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);
    });
}
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 4 with TMutation

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;
}
Also used : TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) ByteBuffer(java.nio.ByteBuffer)

Example 5 with 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);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) CommitSession(org.apache.accumulo.tserver.tablet.CommitSession) Durability(org.apache.accumulo.core.client.Durability) TDurability(org.apache.accumulo.core.tabletserver.thrift.TDurability) ServerMutation(org.apache.accumulo.server.data.ServerMutation) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Span(io.opentelemetry.api.trace.Span) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) Scope(io.opentelemetry.context.Scope) PreparedMutations(org.apache.accumulo.tserver.tablet.PreparedMutations) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TConditionalMutation(org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation) Mutation(org.apache.accumulo.core.data.Mutation) ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation)

Aggregations

TMutation (org.apache.accumulo.core.dataImpl.thrift.TMutation)8 Mutation (org.apache.accumulo.core.data.Mutation)4 ServerMutation (org.apache.accumulo.server.data.ServerMutation)4 TConditionalMutation (org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)2 WalEdits (org.apache.accumulo.core.replication.thrift.WalEdits)2 ServerConditionalMutation (org.apache.accumulo.tserver.data.ServerConditionalMutation)2 LogFileKey (org.apache.accumulo.tserver.logger.LogFileKey)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 Span (io.opentelemetry.api.trace.Span)1 Scope (io.opentelemetry.context.Scope)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 CancellationException (java.util.concurrent.CancellationException)1