import org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged;
import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
+import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
import org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener;
import org.opendaylight.controller.cluster.notifications.RoleChangeNotification;
import org.opendaylight.controller.cluster.raft.RaftState;
private final CountDownLatch waitTillReadyCountdownLatch;
+ private final PrimaryShardInfoFutureCache primaryShardInfoCache;
+
/**
*/
protected ShardManager(ClusterWrapper cluster, Configuration configuration,
- DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch) {
+ DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch,
+ PrimaryShardInfoFutureCache primaryShardInfoCache) {
this.cluster = Preconditions.checkNotNull(cluster, "cluster should not be null");
this.configuration = Preconditions.checkNotNull(configuration, "configuration should not be null");
this.shardDispatcherPath =
new Dispatchers(context().system().dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard);
this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
+ this.primaryShardInfoCache = primaryShardInfoCache;
// Subscribe this actor to cluster member events
cluster.subscribeToMemberEvents(getSelf());
final ClusterWrapper cluster,
final Configuration configuration,
final DatastoreContext datastoreContext,
- final CountDownLatch waitTillReadyCountdownLatch) {
+ final CountDownLatch waitTillReadyCountdownLatch,
+ final PrimaryShardInfoFutureCache primaryShardInfoCache) {
Preconditions.checkNotNull(cluster, "cluster should not be null");
Preconditions.checkNotNull(configuration, "configuration should not be null");
Preconditions.checkNotNull(waitTillReadyCountdownLatch, "waitTillReadyCountdownLatch should not be null");
+ Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
- return Props.create(new ShardManagerCreator(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch));
+ return Props.create(new ShardManagerCreator(cluster, configuration, datastoreContext,
+ waitTillReadyCountdownLatch, primaryShardInfoCache));
}
@Override
ShardInformation shardInformation = findShardInformation(leaderStateChanged.getMemberId());
if(shardInformation != null) {
shardInformation.setLocalDataTree(leaderStateChanged.getLocalShardDataTree());
- shardInformation.setLeaderId(leaderStateChanged.getLeaderId());
+ if(shardInformation.setLeaderId(leaderStateChanged.getLeaderId())) {
+ primaryShardInfoCache.remove(shardInformation.getShardName());
+ }
+
checkReady();
} else {
LOG.debug("No shard found with member Id {}", leaderStateChanged.getMemberId());
return false;
}
- void setLeaderId(String leaderId) {
+ boolean setLeaderId(String leaderId) {
+ boolean changed = !Objects.equal(this.leaderId, leaderId);
this.leaderId = leaderId;
notifyOnShardInitializedCallbacks();
+
+ return changed;
}
}
final Configuration configuration;
final DatastoreContext datastoreContext;
private final CountDownLatch waitTillReadyCountdownLatch;
+ private final PrimaryShardInfoFutureCache primaryShardInfoCache;
- ShardManagerCreator(ClusterWrapper cluster,
- Configuration configuration, DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch) {
+ ShardManagerCreator(ClusterWrapper cluster, Configuration configuration, DatastoreContext datastoreContext,
+ CountDownLatch waitTillReadyCountdownLatch, PrimaryShardInfoFutureCache primaryShardInfoCache) {
this.cluster = cluster;
this.configuration = configuration;
this.datastoreContext = datastoreContext;
this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
+ this.primaryShardInfoCache = primaryShardInfoCache;
}
@Override
public ShardManager create() throws Exception {
- return new ShardManager(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch);
+ return new ShardManager(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch,
+ primaryShardInfoCache);
}
}