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%2FShardManager.java;h=58cdefe5371d2b58be6e7c9f5e461734f34acd07;hb=35f74293edf98402e2b622e060185f7874d10857;hp=6162a0327ca6ab229be75b4f8b8c2c994dcb253a;hpb=bd943b7ee79b6324c561f8fbe2bea4a4293d5dd1;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java index 6162a0327c..58cdefe537 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java @@ -30,6 +30,8 @@ import org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolve import org.opendaylight.controller.cluster.datastore.messages.PrimaryFound; import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound; import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext; +import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.duration.Duration; import java.util.ArrayList; @@ -68,42 +70,38 @@ public class ShardManager extends AbstractUntypedActor { private ShardManagerInfoMBean mBean; + private final DatastoreContext datastoreContext; + /** * @param type defines the kind of data that goes into shards created by this shard manager. Examples of type would be * configuration or operational */ - private ShardManager(String type, ClusterWrapper cluster, Configuration configuration) { + private ShardManager(String type, ClusterWrapper cluster, Configuration configuration, + DatastoreContext datastoreContext) { this.type = Preconditions.checkNotNull(type, "type should not be null"); this.cluster = Preconditions.checkNotNull(cluster, "cluster should not be null"); this.configuration = Preconditions.checkNotNull(configuration, "configuration should not be null"); + this.datastoreContext = datastoreContext; // Subscribe this actor to cluster member events cluster.subscribeToMemberEvents(getSelf()); - // Create all the local Shards and make them a child of the ShardManager - // TODO: This may need to be initiated when we first get the schema context - createLocalShards(); + //createLocalShards(null); } public static Props props(final String type, final ClusterWrapper cluster, - final Configuration configuration) { + final Configuration configuration, + final DatastoreContext datastoreContext) { Preconditions.checkNotNull(type, "type should not be null"); Preconditions.checkNotNull(cluster, "cluster should not be null"); Preconditions.checkNotNull(configuration, "configuration should not be null"); - return Props.create(new Creator() { - - @Override - public ShardManager create() throws Exception { - return new ShardManager(type, cluster, configuration); - } - }); + return Props.create(new ShardManagerCreator(type, cluster, configuration, datastoreContext)); } - @Override public void handleReceive(Object message) throws Exception { if (message.getClass().equals(FindPrimary.SERIALIZABLE_CLASS)) { @@ -160,8 +158,14 @@ public class ShardManager extends AbstractUntypedActor { * @param message */ private void updateSchemaContext(Object message) { - for(ShardInformation info : localShards.values()){ - info.getActor().tell(message,getSelf()); + SchemaContext schemaContext = ((UpdateSchemaContext) message).getSchemaContext(); + + if(localShards.size() == 0){ + createLocalShards(schemaContext); + } else { + for (ShardInformation info : localShards.values()) { + info.getActor().tell(message, getSelf()); + } } } @@ -233,7 +237,7 @@ public class ShardManager extends AbstractUntypedActor { * runs * */ - private void createLocalShards() { + private void createLocalShards(SchemaContext schemaContext) { String memberName = this.cluster.getCurrentMemberName(); List memberShardNames = this.configuration.getMemberShardNames(memberName); @@ -243,15 +247,14 @@ public class ShardManager extends AbstractUntypedActor { ShardIdentifier shardId = getShardIdentifier(memberName, shardName); Map peerAddresses = getPeerAddresses(shardName); ActorRef actor = getContext() - .actorOf(Shard.props(shardId, peerAddresses), - shardId.toString()); + .actorOf(Shard.props(shardId, peerAddresses, datastoreContext, schemaContext). + withMailbox(ActorContext.MAILBOX), shardId.toString()); localShardActorNames.add(shardId.toString()); localShards.put(shardName, new ShardInformation(shardName, actor, peerAddresses)); } - mBean = ShardManagerInfo - .createShardManagerMBean("shard-manager-" + this.type, localShardActorNames); - + mBean = ShardManagerInfo.createShardManagerMBean("shard-manager-" + this.type, + datastoreContext.getDataStoreMXBeanType(), localShardActorNames); } /** @@ -283,10 +286,17 @@ public class ShardManager extends AbstractUntypedActor { @Override public SupervisorStrategy supervisorStrategy() { + return new OneForOneStrategy(10, Duration.create("1 minute"), new Function() { @Override public SupervisorStrategy.Directive apply(Throwable t) { + StringBuilder sb = new StringBuilder(); + for(StackTraceElement element : t.getStackTrace()) { + sb.append("\n\tat ") + .append(element.toString()); + } + LOG.warning("Supervisor Strategy of resume applied {}",sb.toString()); return SupervisorStrategy.resume(); } } @@ -337,6 +347,28 @@ public class ShardManager extends AbstractUntypedActor { } } } + + private static class ShardManagerCreator implements Creator { + private static final long serialVersionUID = 1L; + + final String type; + final ClusterWrapper cluster; + final Configuration configuration; + final DatastoreContext datastoreContext; + + ShardManagerCreator(String type, ClusterWrapper cluster, + Configuration configuration, DatastoreContext datastoreContext) { + this.type = type; + this.cluster = cluster; + this.configuration = configuration; + this.datastoreContext = datastoreContext; + } + + @Override + public ShardManager create() throws Exception { + return new ShardManager(type, cluster, configuration, datastoreContext); + } + } }