X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShard.java;h=94be1b0dc1db9bec4211a801e98d6ed568576b32;hp=c509580ac657f920564cc2c4db1a43f91fa7d325;hb=b9508ff048e882f4227abbaa9b6ac991bb45f9ab;hpb=a23ab6d60b7b57184a8fe59e282e46b448c86d6a diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index c509580ac6..94be1b0dc1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -63,9 +63,11 @@ import org.opendaylight.controller.cluster.datastore.modification.MutableComposi import org.opendaylight.controller.cluster.datastore.utils.Dispatchers; import org.opendaylight.controller.cluster.datastore.utils.MessageTracker; import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; +import org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener; import org.opendaylight.controller.cluster.notifications.RoleChangeNotifier; import org.opendaylight.controller.cluster.raft.RaftActor; import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; +import org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus; import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply; import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload; import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload; @@ -131,6 +133,10 @@ public class Shard extends RaftActor { private final MessageTracker appendEntriesReplyTracker; + private final ReadyTransactionReply READY_TRANSACTION_REPLY = new ReadyTransactionReply( + Serialization.serializedActorPath(getSelf())); + + /** * Coordinates persistence recovery on startup. */ @@ -215,7 +221,7 @@ public class Shard extends RaftActor { private Optional createRoleChangeNotifier(String shardId) { ActorRef shardRoleChangeNotifier = this.getContext().actorOf( RoleChangeNotifier.getProps(shardId), shardId + "-notifier"); - return Optional.of(shardRoleChangeNotifier); + return Optional.of(shardRoleChangeNotifier); } @Override @@ -264,17 +270,17 @@ public class Shard extends RaftActor { } try { - if (message.getClass().equals(CreateTransaction.SERIALIZABLE_CLASS)) { + if (CreateTransaction.SERIALIZABLE_CLASS.isInstance(message)) { handleCreateTransaction(message); } else if (message instanceof ForwardedReadyTransaction) { handleForwardedReadyTransaction((ForwardedReadyTransaction) message); - } else if (message.getClass().equals(CanCommitTransaction.SERIALIZABLE_CLASS)) { + } else if (CanCommitTransaction.SERIALIZABLE_CLASS.isInstance(message)) { handleCanCommitTransaction(CanCommitTransaction.fromSerializable(message)); - } else if (message.getClass().equals(CommitTransaction.SERIALIZABLE_CLASS)) { + } else if (CommitTransaction.SERIALIZABLE_CLASS.isInstance(message)) { handleCommitTransaction(CommitTransaction.fromSerializable(message)); - } else if (message.getClass().equals(AbortTransaction.SERIALIZABLE_CLASS)) { + } else if (AbortTransaction.SERIALIZABLE_CLASS.isInstance(message)) { handleAbortTransaction(AbortTransaction.fromSerializable(message)); - } else if (message.getClass().equals(CloseTransactionChain.SERIALIZABLE_CLASS)) { + } else if (CloseTransactionChain.SERIALIZABLE_CLASS.isInstance(message)) { closeTransactionChain(CloseTransactionChain.fromSerializable(message)); } else if (message instanceof RegisterChangeListener) { registerChangeListener((RegisterChangeListener) message); @@ -288,6 +294,11 @@ public class Shard extends RaftActor { handleTransactionCommitTimeoutCheck(); } 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 { super.onReceiveCommand(message); } @@ -454,17 +465,21 @@ public class Shard extends RaftActor { // node. In that case, the subsequent 3-phase commit messages won't contain the // transactionId so to maintain backwards compatibility, we create a separate cohort actor // to provide the compatible behavior. - ActorRef replyActorPath = self(); if(ready.getTxnClientVersion() < DataStoreVersions.HELIUM_1_VERSION) { LOG.debug("{}: Creating BackwardsCompatibleThreePhaseCommitCohort", persistenceId()); - replyActorPath = getContext().actorOf(BackwardsCompatibleThreePhaseCommitCohort.props( + ActorRef replyActorPath = getContext().actorOf(BackwardsCompatibleThreePhaseCommitCohort.props( ready.getTransactionID())); - } - ReadyTransactionReply readyTransactionReply = new ReadyTransactionReply( - Serialization.serializedActorPath(replyActorPath)); - getSender().tell(ready.isReturnSerialized() ? readyTransactionReply.toSerializable() : - readyTransactionReply, getSelf()); + ReadyTransactionReply readyTransactionReply = + new ReadyTransactionReply(Serialization.serializedActorPath(replyActorPath)); + getSender().tell(ready.isReturnSerialized() ? readyTransactionReply.toSerializable() : + readyTransactionReply, getSelf()); + + } else { + + getSender().tell(ready.isReturnSerialized() ? READY_TRANSACTION_REPLY.toSerializable() : + READY_TRANSACTION_REPLY, getSelf()); + } } private void handleAbortTransaction(final AbortTransaction abort) { @@ -547,11 +562,11 @@ public class Shard extends RaftActor { throw new IllegalStateException("SchemaContext is not set"); } - if (transactionType == TransactionProxy.TransactionType.READ_ONLY.ordinal()) { + if (transactionType == TransactionProxy.TransactionType.WRITE_ONLY.ordinal()) { - shardMBean.incrementReadOnlyTransactionCount(); + shardMBean.incrementWriteOnlyTransactionCount(); - return createShardTransaction(factory.newReadOnlyTransaction(), transactionId, clientVersion); + return createShardTransaction(factory.newWriteOnlyTransaction(), transactionId, clientVersion); } else if (transactionType == TransactionProxy.TransactionType.READ_WRITE.ordinal()) { @@ -559,11 +574,12 @@ public class Shard extends RaftActor { return createShardTransaction(factory.newReadWriteTransaction(), transactionId, clientVersion); - } else if (transactionType == TransactionProxy.TransactionType.WRITE_ONLY.ordinal()) { + } else if (transactionType == TransactionProxy.TransactionType.READ_ONLY.ordinal()) { - shardMBean.incrementWriteOnlyTransactionCount(); + shardMBean.incrementReadOnlyTransactionCount(); + + return createShardTransaction(factory.newReadOnlyTransaction(), transactionId, clientVersion); - return createShardTransaction(factory.newWriteOnlyTransaction(), transactionId, clientVersion); } else { throw new IllegalArgumentException( "Shard="+name + ":CreateTransaction message has unidentified transaction type=" @@ -598,10 +614,8 @@ public class Shard extends RaftActor { private ActorRef createTransaction(int transactionType, String remoteTransactionId, String transactionChainId, short clientVersion) { - ShardTransactionIdentifier transactionId = - ShardTransactionIdentifier.builder() - .remoteTransactionId(remoteTransactionId) - .build(); + + ShardTransactionIdentifier transactionId = new ShardTransactionIdentifier(remoteTransactionId); if(LOG.isDebugEnabled()) { LOG.debug("{}: Creating transaction : {} ", persistenceId(), transactionId); @@ -967,7 +981,7 @@ public class Shard extends RaftActor { } @VisibleForTesting - InMemoryDOMDataStore getDataStore() { + public InMemoryDOMDataStore getDataStore() { return store; }