Search in sources :

Example 1 with ForwardedReadyTransaction

use of org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testForwardedReadyTransactionForwardedToLeader.

@SuppressWarnings("unchecked")
@Test
public void testForwardedReadyTransactionForwardedToLeader() throws Exception {
    initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
    followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
    final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
    assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
    carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
    final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
    // Send a tx with immediate commit.
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
    new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
    ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx1, modification), true);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    Object resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", CommitTransactionReply.class, resp.getClass());
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);
    // Send another tx without immediate commit.
    modification = dataTree.takeSnapshot().newModification();
    MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
    new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);
    forwardedReady = new ForwardedReadyTransaction(tx2, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx2, modification), false);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());
    ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(((ReadyTransactionReply) resp).getCohortPath());
    final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
    Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
    final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(leaderDistributedDataStore.getActorContext(), Arrays.asList(new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
    cohort.canCommit().get(5, TimeUnit.SECONDS);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ActorSelection(akka.actor.ActorSelection) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) Test(org.junit.Test)

Example 2 with ForwardedReadyTransaction

use of org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction 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 3 with ForwardedReadyTransaction

use of org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction in project controller by opendaylight.

the class ShardWriteTransaction method readyTransaction.

private void readyTransaction(boolean returnSerialized, boolean doImmediateCommit, short clientTxVersion) {
    TransactionIdentifier transactionID = getTransactionId();
    LOG.debug("readyTransaction : {}", transactionID);
    getShardActor().forward(new ForwardedReadyTransaction(transactionID, clientTxVersion, transaction, doImmediateCommit), getContext());
    // The shard will handle the commit from here so we're no longer needed - self-destruct.
    getSelf().tell(PoisonPill.getInstance(), getSelf());
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction)

Aggregations

ForwardedReadyTransaction (org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction)3 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)2 ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 Test (org.junit.Test)1 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)1 MessageTracker (org.opendaylight.controller.cluster.common.actor.MessageTracker)1 Error (org.opendaylight.controller.cluster.common.actor.MessageTracker.Error)1 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)1 MakeLeaderLocal (org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal)1 PeerAddressResolved (org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved)1 PersistAbortTransactionPayload (org.opendaylight.controller.cluster.datastore.messages.PersistAbortTransactionPayload)1 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)1 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)1 RegisterDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener)1 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)1 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)1 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)1