Search in sources :

Example 1 with SkipTransactionsRequest

use of org.opendaylight.controller.cluster.access.commands.SkipTransactionsRequest 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((TransactionPurgeRequest) request, envelope, now);
    } else if (request instanceof SkipTransactionsRequest) {
        return handleSkipTransactionsRequest((SkipTransactionsRequest) request, envelope, now);
    }
    final TransactionIdentifier id = request.getTarget();
    final long txidBits = id.getTransactionId();
    if (purgedTransactions.contains(txidBits)) {
        LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions);
        throw new DeadTransactionException(purgedTransactions.toRangeSet());
    }
    final Boolean closed = closedTransactions.get(UnsignedLong.fromLongBits(txidBits));
    if (closed != null) {
        final boolean successful = closed;
        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) Optional(java.util.Optional) ClosedTransactionException(org.opendaylight.controller.cluster.access.commands.ClosedTransactionException) OutOfOrderRequestException(org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) SkipTransactionsRequest(org.opendaylight.controller.cluster.access.commands.SkipTransactionsRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) DeadTransactionException(org.opendaylight.controller.cluster.access.commands.DeadTransactionException) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with SkipTransactionsRequest

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

the class ProxyHistory method doSkipTransactions.

@Holding("lock")
private void doSkipTransactions(final List<TransactionIdentifier> toSkip) {
    final var txIds = toSkip.stream().mapToLong(TransactionIdentifier::getTransactionId).distinct().sorted().mapToObj(UnsignedLong::fromLongBits).collect(ImmutableList.toImmutableList());
    LOG.debug("Proxy {} skipping transactions {}", this, txIds);
    connection.enqueueRequest(new SkipTransactionsRequest(new TransactionIdentifier(identifier, txIds.get(0).longValue()), 0, localActor(), txIds.subList(1, txIds.size())), resp -> {
        LOG.debug("Proxy {} confirmed transaction skip", this);
    }, connection.currentTime());
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) SkipTransactionsRequest(org.opendaylight.controller.cluster.access.commands.SkipTransactionsRequest) Holding(org.checkerframework.checker.lock.qual.Holding)

Aggregations

SkipTransactionsRequest (org.opendaylight.controller.cluster.access.commands.SkipTransactionsRequest)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 Optional (java.util.Optional)1 Holding (org.checkerframework.checker.lock.qual.Holding)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ClosedTransactionException (org.opendaylight.controller.cluster.access.commands.ClosedTransactionException)1 DeadTransactionException (org.opendaylight.controller.cluster.access.commands.DeadTransactionException)1 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)1 OutOfOrderRequestException (org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException)1 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)1 TransactionSuccess (org.opendaylight.controller.cluster.access.commands.TransactionSuccess)1