Search in sources :

Example 1 with IncrementTransactionSequenceRequest

use of org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest in project controller by opendaylight.

the class RemoteProxyTransaction method handleReplayedRemoteRequest.

@Override
void handleReplayedRemoteRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
    final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> {
    };
    final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
    if (request instanceof ModifyTransactionRequest) {
        handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);
    } else if (request instanceof ReadTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof ExistsTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionPreCommitRequest) {
        ensureFlushedBuider(optTicks);
        final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
        enqueueRequest(tmp, resp -> {
            recordSuccessfulRequest(tmp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionDoCommitRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback, enqueuedTicks);
    } else if (request instanceof TransactionAbortRequest) {
        ensureFlushedBuider(optTicks);
        enqueueDoAbort(callback, enqueuedTicks);
    } else if (request instanceof TransactionPurgeRequest) {
        enqueuePurge(callback, enqueuedTicks);
    } else if (request instanceof IncrementTransactionSequenceRequest) {
        final IncrementTransactionSequenceRequest req = (IncrementTransactionSequenceRequest) request;
        ensureFlushedBuider(optTicks);
        enqueueRequest(new IncrementTransactionSequenceRequest(getIdentifier(), nextSequence(), localActor(), snapshotOnly, req.getIncrement()), callback, enqueuedTicks);
        incrementSequence(req.getIncrement());
    } else {
        throw new IllegalArgumentException("Unhandled request {}" + request);
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) MappingCheckedFuture(org.opendaylight.mdsal.common.api.MappingCheckedFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) TransactionModification(org.opendaylight.controller.cluster.access.commands.TransactionModification) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) Optional(com.google.common.base.Optional) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Logger(org.slf4j.Logger) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge) PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) TransactionSuccess(org.opendaylight.controller.cluster.access.commands.TransactionSuccess) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)

Example 2 with IncrementTransactionSequenceRequest

use of org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest in project controller by opendaylight.

the class AbstractFrontendHistory method handleTransactionRequest.

@Nullable
final TransactionSuccess<?> handleTransactionRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) throws RequestException {
    if (request instanceof TransactionPurgeRequest) {
        return handleTransactionPurgeRequest(request, envelope, now);
    }
    final TransactionIdentifier id = request.getTarget();
    final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId());
    if (purgedTransactions.contains(ul)) {
        LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions);
        throw new DeadTransactionException(purgedTransactions);
    }
    final Boolean closed = closedTransactions.get(ul);
    if (closed != null) {
        final boolean successful = closed.booleanValue();
        LOG.debug("{}: Request {} refers to a {} transaction", persistenceId, request, successful ? "successful" : "failed");
        throw new ClosedTransactionException(successful);
    }
    FrontendTransaction tx = transactions.get(id);
    if (tx == null) {
        // The transaction does not exist and we are about to create it, check sequence number
        if (request.getSequence() != 0) {
            LOG.warn("{}: no transaction state present, unexpected request {}", persistenceId(), request);
            throw new OutOfOrderRequestException(0);
        }
        tx = createTransaction(request, id);
        transactions.put(id, tx);
    } else if (!(request instanceof IncrementTransactionSequenceRequest)) {
        final Optional<TransactionSuccess<?>> maybeReplay = tx.replaySequence(request.getSequence());
        if (maybeReplay.isPresent()) {
            final TransactionSuccess<?> replay = maybeReplay.get();
            LOG.debug("{}: envelope {} replaying response {}", persistenceId(), envelope, replay);
            return replay;
        }
    }
    return tx.handleRequest(request, envelope, now);
}
Also used : TransactionSuccess(org.opendaylight.controller.cluster.access.commands.TransactionSuccess) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) UnsignedLong(com.google.common.primitives.UnsignedLong) Optional(java.util.Optional) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ClosedTransactionException(org.opendaylight.controller.cluster.access.commands.ClosedTransactionException) OutOfOrderRequestException(org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException) DeadTransactionException(org.opendaylight.controller.cluster.access.commands.DeadTransactionException) Nullable(javax.annotation.Nullable)

Example 3 with IncrementTransactionSequenceRequest

use of org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest in project controller by opendaylight.

the class FrontendTransaction method handleRequest.

// Request order has already been checked by caller and replaySequence()
@SuppressWarnings("checkstyle:IllegalCatch")
@Nullable
final TransactionSuccess<?> handleRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) throws RequestException {
    if (request instanceof IncrementTransactionSequenceRequest) {
        final IncrementTransactionSequenceRequest incr = (IncrementTransactionSequenceRequest) request;
        expectedSequence += incr.getIncrement();
        return recordSuccess(incr.getSequence(), new IncrementTransactionSequenceSuccess(incr.getTarget(), incr.getSequence()));
    }
    if (previousFailure != null) {
        LOG.debug("{}: Rejecting request {} due to previous failure", persistenceId(), request, previousFailure);
        throw previousFailure;
    }
    try {
        return doHandleRequest(request, envelope, now);
    } catch (RuntimeException e) {
        /*
             * The request failed to process, we should not attempt to ever
             * apply it again. Furthermore we cannot accept any further requests
             * from this connection, simply because the transaction state is
             * undefined.
             */
        LOG.debug("{}: Request {} failed to process", persistenceId(), request, e);
        previousFailure = new RuntimeRequestException("Request " + request + " failed to process", e);
        throw previousFailure;
    }
}
Also used : IncrementTransactionSequenceSuccess(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceSuccess) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Nullable(javax.annotation.Nullable)

Example 4 with IncrementTransactionSequenceRequest

use of org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest in project controller by opendaylight.

the class AbstractProxyTransaction method replayMessages.

// Called with the connection locked
final void replayMessages(final ProxyHistory successorHistory, final Iterable<ConnectionEntry> enqueuedEntries) {
    final SuccessorState local = getSuccessorState();
    final State prevState = local.getPrevState();
    final AbstractProxyTransaction successor = successorHistory.createTransactionProxy(getIdentifier(), isSnapshotOnly(), local.isDone());
    LOG.debug("{} created successor {}", this, successor);
    local.setSuccessor(successor);
    // Replay successful requests first
    if (!successfulRequests.isEmpty()) {
        // We need to find a good timestamp to use for successful requests, as we do not want to time them out
        // nor create timing inconsistencies in the queue -- requests are expected to be ordered by their enqueue
        // time. We will pick the time of the first entry available. If there is none, we will just use current
        // time, as all other requests will get enqueued afterwards.
        final ConnectionEntry firstInQueue = Iterables.getFirst(enqueuedEntries, null);
        final long now = firstInQueue != null ? firstInQueue.getEnqueuedTicks() : parent.currentTime();
        for (Object obj : successfulRequests) {
            if (obj instanceof TransactionRequest) {
                LOG.debug("Forwarding successful request {} to successor {}", obj, successor);
                successor.doReplayRequest((TransactionRequest<?>) obj, resp -> {
                /*NOOP*/
                }, now);
            } else {
                Verify.verify(obj instanceof IncrementSequence);
                final IncrementSequence increment = (IncrementSequence) obj;
                successor.doReplayRequest(new IncrementTransactionSequenceRequest(getIdentifier(), increment.getSequence(), localActor(), isSnapshotOnly(), increment.getDelta()), resp -> {
                /*NOOP*/
                }, now);
                LOG.debug("Incrementing sequence {} to successor {}", obj, successor);
            }
        }
        LOG.debug("{} replayed {} successful requests", getIdentifier(), successfulRequests.size());
        successfulRequests.clear();
    }
    // Now replay whatever is in the connection
    final Iterator<ConnectionEntry> it = enqueuedEntries.iterator();
    while (it.hasNext()) {
        final ConnectionEntry e = it.next();
        final Request<?, ?> req = e.getRequest();
        if (getIdentifier().equals(req.getTarget())) {
            Verify.verify(req instanceof TransactionRequest, "Unhandled request %s", req);
            LOG.debug("Replaying queued request {} to successor {}", req, successor);
            successor.doReplayRequest((TransactionRequest<?>) req, e.getCallback(), e.getEnqueuedTicks());
            it.remove();
        }
    }
    /*
         * Check the state at which we have started the reconnect attempt. State transitions triggered while we were
         * reconnecting have been forced to slow paths, which will be unlocked once we unblock the state latch
         * at the end of this method.
         */
    if (SEALED.equals(prevState)) {
        LOG.debug("Proxy {} reconnected while being sealed, propagating state to successor {}", this, successor);
        final long enqueuedTicks = parent.currentTime();
        final java.util.Optional<ModifyTransactionRequest> optState = flushState();
        if (optState.isPresent()) {
            successor.handleReplayedRemoteRequest(optState.get(), null, enqueuedTicks);
        }
        if (successor.markSealed()) {
            successor.sealAndSend(Optional.of(enqueuedTicks));
        }
    }
}
Also used : TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) ConnectionEntry(org.opendaylight.controller.cluster.access.client.ConnectionEntry) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)

Aggregations

IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)4 Nullable (javax.annotation.Nullable)3 AbstractLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest)2 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)2 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)2 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)2 TransactionSuccess (org.opendaylight.controller.cluster.access.commands.TransactionSuccess)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 Optional (com.google.common.base.Optional)1 UnsignedLong (com.google.common.primitives.UnsignedLong)1 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 ConnectionEntry (org.opendaylight.controller.cluster.access.client.ConnectionEntry)1 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)1 AbstractReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest)1 ClosedTransactionException (org.opendaylight.controller.cluster.access.commands.ClosedTransactionException)1