Search in sources :

Example 1 with OutOfOrderRequestException

use of org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException 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)

Aggregations

UnsignedLong (com.google.common.primitives.UnsignedLong)1 Optional (java.util.Optional)1 Nullable (javax.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 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1