From: Jakub Morvay Date: Thu, 23 Mar 2017 13:56:14 +0000 (+0100) Subject: BUG 2138 - Do not fail on module-based default shard X-Git-Tag: release/carbon~126 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ef3b9a8300db1c791f2c4088d39152ccf9f5b97c BUG 2138 - Do not fail on module-based default shard Currently, DistributedShardedDOMDataTree will try to create default shards on its start. However, this can collide with module-based default shards. If present in modules.conf, modules-based default shards will be created on DistributedDatastore's start. If already present, do no create default shards. Create just DistributedShardFrontend for them. Change-Id: I05857f520e3467116e8748e6ae231ab9dc39f44c Signed-off-by: Jakub Morvay --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java index 30b46e52ff..6e53a27912 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java @@ -18,6 +18,7 @@ import akka.dispatch.Mapper; import akka.dispatch.OnComplete; import akka.pattern.Patterns; import akka.util.Timeout; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.ForwardingObject; @@ -518,6 +519,25 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat shardedDataTreeActor, this); } else { try { + // There can be situation when there is already started default shard + // because it is present in modules.conf. In that case we have to create + // just frontend for default shard, but not shard itself + // TODO we don't have to do it for config and operational default shard + // separately. Just one of them should be enough + final ActorContext actorContext = logicalDatastoreType == LogicalDatastoreType.CONFIGURATION + ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext(); + + final Optional defaultLocalShardOptional = + actorContext.findLocalShard(ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY)); + + if (defaultLocalShardOptional.isPresent()) { + LOG.debug("{} Default shard is already started, creating just frontend", logicalDatastoreType); + createShardFrontend(new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY)); + return new DistributedShardRegistrationImpl( + new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY), + shardedDataTreeActor, this); + } + // we should probably only have one node create the default shards return Await.result(FutureConverters.toScala(createDistributedShard( new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY), names)),