Search in sources :

Example 1 with PersistenceProtocol

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

the class LocalReadOnlyProxyTransaction method commonModifyTransactionRequest.

private static void commonModifyTransactionRequest(final ModifyTransactionRequest request) {
    Verify.verify(request.getModifications().isEmpty());
    final PersistenceProtocol protocol = request.getPersistenceProtocol().get();
    Verify.verify(protocol == PersistenceProtocol.ABORT);
}
Also used : PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol)

Example 2 with PersistenceProtocol

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

the class FrontendReadWriteTransaction method handleModifyTransaction.

@Nullable
private TransactionSuccess<?> handleModifyTransaction(final ModifyTransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
    // We need to examine the persistence protocol first to see if this is an idempotent request. If there is no
    // protocol, there is nothing for us to do.
    final java.util.Optional<PersistenceProtocol> maybeProto = request.getPersistenceProtocol();
    if (!maybeProto.isPresent()) {
        applyModifications(request.getModifications());
        return replyModifySuccess(request.getSequence());
    }
    switch(maybeProto.get()) {
        case ABORT:
            if (ABORTING.equals(state)) {
                LOG.debug("{}: Transaction {} already aborting", persistenceId(), getIdentifier());
                return null;
            }
            final ReadWriteShardDataTreeTransaction openTransaction = checkOpen();
            startAbort();
            openTransaction.abort(() -> {
                recordAndSendSuccess(envelope, now, new ModifyTransactionSuccess(getIdentifier(), request.getSequence()));
                finishAbort();
            });
            return null;
        case READY:
            ensureReady(request.getModifications());
            return replyModifySuccess(request.getSequence());
        case SIMPLE:
            ensureReady(request.getModifications());
            directCommit(envelope, now);
            return null;
        case THREE_PHASE:
            ensureReady(request.getModifications());
            coordinatedCommit(envelope, now);
            return null;
        default:
            LOG.warn("{}: rejecting unsupported protocol {}", persistenceId(), maybeProto.get());
            throw new UnsupportedRequestException(request);
    }
}
Also used : ModifyTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ModifyTransactionSuccess) PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) Nullable(javax.annotation.Nullable)

Aggregations

PersistenceProtocol (org.opendaylight.controller.cluster.access.commands.PersistenceProtocol)2 Nullable (javax.annotation.Nullable)1 ModifyTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ModifyTransactionSuccess)1 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)1