X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShard.java;h=7b34f5df6097ce4ea00c49233f3f4a4a8e5c7728;hb=0b9b1dcba996fd76e0e1bde731692570747f5efd;hp=5a10c3e961bc8e038a0dd3969134b903aace2a56;hpb=2088e1ffef92b11e9d877b2a51280b142a84c58b;p=controller.git 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 5a10c3e961..7b34f5df60 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 @@ -162,14 +162,8 @@ public class Shard extends RaftActor { datastoreContext.getShardTransactionCommitTimeoutInSeconds(), TimeUnit.SECONDS) / 2; } - public static Props props(final ShardIdentifier name, - final Map peerAddresses, - final DatastoreContext datastoreContext, final SchemaContext schemaContext) { - Preconditions.checkNotNull(name, "name should not be null"); - Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null"); - Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null"); - Preconditions.checkNotNull(schemaContext, "schemaContext should not be null"); - + public static Props props(final ShardIdentifier name, final Map peerAddresses, + final DatastoreContext datastoreContext, final SchemaContext schemaContext) { return Props.create(new ShardCreator(name, peerAddresses, datastoreContext, schemaContext)); } @@ -221,7 +215,7 @@ public class Shard extends RaftActor { if(context.error().isPresent()){ LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(), - context.error()); + context.error()); } try { @@ -243,9 +237,9 @@ public class Shard extends RaftActor { } else if (CloseTransactionChain.SERIALIZABLE_CLASS.isInstance(message)) { closeTransactionChain(CloseTransactionChain.fromSerializable(message)); } else if (message instanceof RegisterChangeListener) { - changeSupport.onMessage((RegisterChangeListener) message, isLeader()); + changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader()); } else if (message instanceof RegisterDataTreeChangeListener) { - treeChangeSupport.onMessage((RegisterDataTreeChangeListener) message, isLeader()); + treeChangeSupport.onMessage((RegisterDataTreeChangeListener) message, isLeader(), hasLeader()); } else if (message instanceof UpdateSchemaContext) { updateSchemaContext((UpdateSchemaContext) message); } else if (message instanceof PeerAddressResolved) { @@ -271,6 +265,10 @@ public class Shard extends RaftActor { } } + private boolean hasLeader() { + return getLeaderId() != null; + } + public int getPendingTxCommitQueueSize() { return commitCoordinator.getQueueSize(); } @@ -287,7 +285,7 @@ public class Shard extends RaftActor { leaderPayloadVersion); } - private void onDatastoreContext(DatastoreContext context) { + protected void onDatastoreContext(DatastoreContext context) { datastoreContext = context; commitCoordinator.setQueueCapacity(datastoreContext.getShardTransactionCommitQueueCapacity()); @@ -655,8 +653,9 @@ public class Shard extends RaftActor { @Override protected void onStateChanged() { boolean isLeader = isLeader(); - changeSupport.onLeadershipChange(isLeader); - treeChangeSupport.onLeadershipChange(isLeader); + boolean hasLeader = hasLeader(); + changeSupport.onLeadershipChange(isLeader, hasLeader); + treeChangeSupport.onLeadershipChange(isLeader, hasLeader); // If this actor is no longer the leader close all the transaction chains if (!isLeader) { @@ -685,22 +684,29 @@ public class Shard extends RaftActor { return commitCoordinator; } + protected abstract static class AbstractShardCreator implements Creator { + private static final long serialVersionUID = 1L; + + protected final ShardIdentifier name; + protected final Map peerAddresses; + protected final DatastoreContext datastoreContext; + protected final SchemaContext schemaContext; - private static class ShardCreator implements Creator { + protected AbstractShardCreator(final ShardIdentifier name, final Map peerAddresses, + final DatastoreContext datastoreContext, final SchemaContext schemaContext) { + this.name = Preconditions.checkNotNull(name, "name should not be null"); + this.peerAddresses = Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null"); + this.datastoreContext = Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null"); + this.schemaContext = Preconditions.checkNotNull(schemaContext, "schemaContext should not be null"); + } + } + private static class ShardCreator extends AbstractShardCreator { private static final long serialVersionUID = 1L; - final ShardIdentifier name; - final Map peerAddresses; - final DatastoreContext datastoreContext; - final SchemaContext schemaContext; - ShardCreator(final ShardIdentifier name, final Map peerAddresses, final DatastoreContext datastoreContext, final SchemaContext schemaContext) { - this.name = name; - this.peerAddresses = peerAddresses; - this.datastoreContext = datastoreContext; - this.schemaContext = schemaContext; + super(name, peerAddresses, datastoreContext, schemaContext); } @Override