Search in sources :

Example 21 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class Shard method handleNonRaftCommand.

@Override
protected void handleNonRaftCommand(final Object message) {
    try (MessageTracker.Context context = appendEntriesReplyTracker.received(message)) {
        final Optional<Error> maybeError = context.error();
        if (maybeError.isPresent()) {
            LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(), maybeError.get());
        }
        store.resetTransactionBatch();
        if (message instanceof RequestEnvelope) {
            handleRequestEnvelope((RequestEnvelope) message);
        } else if (MessageAssembler.isHandledMessage(message)) {
            handleRequestAssemblerMessage(message);
        } else if (message instanceof ConnectClientRequest) {
            handleConnectClient((ConnectClientRequest) message);
        } else if (CreateTransaction.isSerializedType(message)) {
            handleCreateTransaction(message);
        } else if (message instanceof BatchedModifications) {
            handleBatchedModifications((BatchedModifications) message);
        } else if (message instanceof ForwardedReadyTransaction) {
            handleForwardedReadyTransaction((ForwardedReadyTransaction) message);
        } else if (message instanceof ReadyLocalTransaction) {
            handleReadyLocalTransaction((ReadyLocalTransaction) message);
        } else if (CanCommitTransaction.isSerializedType(message)) {
            handleCanCommitTransaction(CanCommitTransaction.fromSerializable(message));
        } else if (CommitTransaction.isSerializedType(message)) {
            handleCommitTransaction(CommitTransaction.fromSerializable(message));
        } else if (AbortTransaction.isSerializedType(message)) {
            handleAbortTransaction(AbortTransaction.fromSerializable(message));
        } else if (CloseTransactionChain.isSerializedType(message)) {
            closeTransactionChain(CloseTransactionChain.fromSerializable(message));
        } else if (message instanceof RegisterChangeListener) {
            changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader());
        } else if (message instanceof RegisterDataTreeChangeListener) {
            treeChangeSupport.onMessage((RegisterDataTreeChangeListener) message, isLeader(), hasLeader());
        } else if (message instanceof UpdateSchemaContext) {
            updateSchemaContext((UpdateSchemaContext) message);
        } else if (message instanceof PeerAddressResolved) {
            PeerAddressResolved resolved = (PeerAddressResolved) message;
            setPeerAddress(resolved.getPeerId(), resolved.getPeerAddress());
        } else if (TX_COMMIT_TIMEOUT_CHECK_MESSAGE.equals(message)) {
            commitTimeoutCheck();
        } else if (message instanceof DatastoreContext) {
            onDatastoreContext((DatastoreContext) message);
        } else if (message instanceof RegisterRoleChangeListener) {
            roleChangeNotifier.get().forward(message, context());
        } else if (message instanceof FollowerInitialSyncUpStatus) {
            shardMBean.setFollowerInitialSyncStatus(((FollowerInitialSyncUpStatus) message).isInitialSyncDone());
            context().parent().tell(message, self());
        } else if (GET_SHARD_MBEAN_MESSAGE.equals(message)) {
            sender().tell(getShardMBean(), self());
        } else if (message instanceof GetShardDataTree) {
            sender().tell(store.getDataTree(), self());
        } else if (message instanceof ServerRemoved) {
            context().parent().forward(message, context());
        } else if (ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
            messageRetrySupport.onTimerMessage(message);
        } else if (message instanceof DataTreeCohortActorRegistry.CohortRegistryCommand) {
            store.processCohortRegistryCommand(getSender(), (DataTreeCohortActorRegistry.CohortRegistryCommand) message);
        } else if (message instanceof PersistAbortTransactionPayload) {
            final TransactionIdentifier txId = ((PersistAbortTransactionPayload) message).getTransactionId();
            persistPayload(txId, AbortTransactionPayload.create(txId), true);
        } else if (message instanceof MakeLeaderLocal) {
            onMakeLeaderLocal();
        } else if (RESUME_NEXT_PENDING_TRANSACTION.equals(message)) {
            store.resumeNextPendingTransaction();
        } else if (!responseMessageSlicer.handleMessage(message)) {
            super.handleNonRaftCommand(message);
        }
    }
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) ServerRemoved(org.opendaylight.controller.cluster.raft.messages.ServerRemoved) Error(org.opendaylight.controller.cluster.common.actor.MessageTracker.Error) PeerAddressResolved(org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved) MessageTracker(org.opendaylight.controller.cluster.common.actor.MessageTracker) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) MakeLeaderLocal(org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal) ConnectClientRequest(org.opendaylight.controller.cluster.access.commands.ConnectClientRequest) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) PersistAbortTransactionPayload(org.opendaylight.controller.cluster.datastore.messages.PersistAbortTransactionPayload)

Example 22 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardCommitCoordinator method handleReadyLocalTransaction.

/**
 * This method handles {@link ReadyLocalTransaction} message. All transaction modifications have
 * been prepared beforehand by the sender and we just need to drive them through into the
 * dataTree.
 *
 * @param message the ReadyLocalTransaction message to process
 * @param sender the sender of the message
 * @param shard the transaction's shard actor
 */
void handleReadyLocalTransaction(final ReadyLocalTransaction message, final ActorRef sender, final Shard shard) {
    final TransactionIdentifier txId = message.getTransactionId();
    final ShardDataTreeCohort cohort = dataTree.newReadyCohort(txId, message.getModification());
    final CohortEntry cohortEntry = CohortEntry.createReady(cohort, DataStoreVersions.CURRENT_VERSION);
    cohortCache.put(cohortEntry.getTransactionId(), cohortEntry);
    cohortEntry.setDoImmediateCommit(message.isDoCommitOnReady());
    log.debug("{}: Applying local modifications for Tx {}", name, txId);
    if (message.isDoCommitOnReady()) {
        cohortEntry.setReplySender(sender);
        cohortEntry.setShard(shard);
        handleCanCommit(cohortEntry);
    } else {
        sender.tell(readyTransactionReply(shard.self()), shard.self());
    }
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)

Example 23 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardDataTree method finishCommit.

@SuppressWarnings("checkstyle:IllegalCatch")
private void finishCommit(final SimpleShardDataTreeCohort cohort) {
    final TransactionIdentifier txId = cohort.getIdentifier();
    final DataTreeCandidate candidate = cohort.getCandidate();
    LOG.debug("{}: Resuming commit of transaction {}", logContext, txId);
    if (tip == candidate) {
        // All pending candidates have been committed, reset the tip to the data tree.
        tip = dataTree;
    }
    try {
        dataTree.commit(candidate);
    } catch (Exception e) {
        LOG.error("{}: Failed to commit transaction {}", logContext, txId, e);
        failCommit(e);
        return;
    }
    shard.getShardMBean().incrementCommittedTransactionCount();
    shard.getShardMBean().setLastCommittedTransactionTime(System.currentTimeMillis());
    // FIXME: propagate journal index
    pendingFinishCommits.poll().cohort.successfulCommit(UnsignedLong.ZERO, () -> {
        LOG.trace("{}: Transaction {} committed, proceeding to notify", logContext, txId);
        notifyListeners(candidate);
        processNextPending();
    });
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) TimeoutException(java.util.concurrent.TimeoutException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) IOException(java.io.IOException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Example 24 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardDataTree method abortTransaction.

@Override
void abortTransaction(final AbstractShardDataTreeTransaction<?> transaction, final Runnable callback) {
    final TransactionIdentifier id = transaction.getIdentifier();
    LOG.debug("{}: aborting transaction {}", logContext, id);
    replicatePayload(id, AbortTransactionPayload.create(id), callback);
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)

Example 25 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier 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

TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)57 Test (org.junit.Test)37 FiniteDuration (scala.concurrent.duration.FiniteDuration)17 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)16 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)12 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)11 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)10 ActorRef (akka.actor.ActorRef)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)7 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)6 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)6 Failure (akka.actor.Status.Failure)5 Timeout (akka.util.Timeout)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)5