BUG-2138: Make DistributedShardFactory return Futures.
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / shardmanager / ShardManager.java
index 9085027..0596872 100644 (file)
@@ -389,7 +389,11 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering {
                                   final Map<DOMDataTreeIdentifier, PrefixShardConfiguration> configs) {
         LOG.debug("{} ShardManager : {}, resolving added configs : {}", addedConfigs);
 
-        addedConfigs.forEach(id -> doCreatePrefixedShard(configs.get(id)));
+        addedConfigs.stream().filter(identifier
+            -> identifier
+            .getDatastoreType().equals(
+                    ClusterUtils.toMDSalApi(datastoreContextFactory.getBaseDatastoreContext().getLogicalStoreType())))
+            .forEach(id -> doCreatePrefixedShard(configs.get(id)));
     }
 
     private void resolveUpdates(Set<DOMDataTreeIdentifier> maybeUpdatedConfigs) {
@@ -581,6 +585,17 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering {
                 config.getPrefix());
         final String shardName = shardId.getShardName();
 
+        if (localShards.containsKey(shardName)) {
+            LOG.debug("{}: Received create for an already existing shard {}", persistenceId(), shardName);
+            final PrefixShardConfiguration existing =
+                    configuration.getAllPrefixShardConfigurations().get(config.getPrefix());
+
+            if (existing != null && existing.equals(config)) {
+                // we don't have to do nothing here
+                return;
+            }
+        }
+
         configuration.addPrefixShardConfiguration(config);
 
         final Builder builder = newShardDatastoreContextBuilder(shardName);