+ if (writer.checkDefaultIsPresent()) {
+ LOG.debug("{}: Default shard for {} is already present in the config. Possibly saved in snapshot.",
+ memberName, logicalDatastoreType);
+ } else {
+ try {
+ // Currently the default shard configuration is present in the out-of-box modules.conf and is
+ // expected to be present. So look up the local default shard here and create the frontend.
+
+ // TODO we don't have to do it for config and operational default shard separately. Just one of them
+ // should be enough
+ final ActorUtils actorUtils = logicalDatastoreType == LogicalDatastoreType.CONFIGURATION
+ ? distributedConfigDatastore.getActorUtils() : distributedOperDatastore.getActorUtils();
+
+ final Optional<ActorRef> defaultLocalShardOptional =
+ actorUtils.findLocalShard(ClusterUtils.getCleanShardName(YangInstanceIdentifier.empty()));
+
+ if (defaultLocalShardOptional.isPresent()) {
+ LOG.debug("{}: Default shard for {} is already started, creating just frontend", memberName,
+ logicalDatastoreType);
+ createShardFrontend(new DOMDataTreeIdentifier(logicalDatastoreType,
+ YangInstanceIdentifier.empty()));
+ }
+
+ // The local shard isn't present - we assume that means the local member isn't in the replica list
+ // and will be dynamically created later via an explicit add-shard-replica request. This is the
+ // bootstrapping mechanism to add a new node into an existing cluster. The following code to create
+ // the default shard as a prefix shard is problematic in this scenario so it is commented out. Since
+ // the default shard is a module-based shard by default, it makes sense to always treat it as such,
+ // ie bootstrap it in the same manner as the special prefix-configuration and EOS shards.
+// final Collection<MemberName> names = distributedConfigDatastore.getActorUtils().getConfiguration()
+// .getUniqueMemberNamesForAllShards();
+// Await.result(FutureConverters.toScala(createDistributedShard(
+// new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.empty()), names)),
+// SHARD_FUTURE_TIMEOUT_DURATION);
+// } catch (DOMDataTreeShardingConflictException e) {
+// LOG.debug("{}: Default shard for {} already registered, possibly due to other node doing it faster",
+// memberName, logicalDatastoreType);
+ } catch (Exception e) {
+ LOG.error("{}: Default shard initialization for {} failed", memberName, logicalDatastoreType, e);
+ throw new RuntimeException(e);
+ }
+ }