X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FConfigurationImpl.java;h=37b565d2131debe797ca2ab975baf82550740a68;hp=34590025d59ab78d3e0095e81addaa8ed874935f;hb=bc7b4edec3c868a14e0a0de3a3b8e1af2406448b;hpb=516a4b2ea78179c9bd6ebb584862e8fc686ebf08 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java index 34590025d5..37b565d213 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; import com.typesafe.config.ConfigObject; @@ -34,11 +35,23 @@ public class ConfigurationImpl implements Configuration { private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStore.class); + // Look up maps to speed things up + + // key = memberName, value = list of shardNames + private Map> memberShardNames = new HashMap<>(); + + // key = shardName, value = list of replicaNames (replicaNames are the same as memberNames) + private Map> shardReplicaNames = new HashMap<>(); + public ConfigurationImpl(String moduleShardsConfigPath, String modulesConfigPath){ + Preconditions.checkNotNull(moduleShardsConfigPath, "moduleShardsConfigPath should not be null"); + Preconditions.checkNotNull(modulesConfigPath, "modulesConfigPath should not be null"); + + File moduleShardsFile = new File("./configuration/initial/" + moduleShardsConfigPath); File modulesFile = new File("./configuration/initial/" + modulesConfigPath); @@ -66,6 +79,13 @@ public class ConfigurationImpl implements Configuration { } @Override public List getMemberShardNames(String memberName){ + + Preconditions.checkNotNull(memberName, "memberName should not be null"); + + if(memberShardNames.containsKey(memberName)){ + return memberShardNames.get(memberName); + } + List shards = new ArrayList(); for(ModuleShard ms : moduleShards){ for(Shard s : ms.getShards()){ @@ -76,11 +96,17 @@ public class ConfigurationImpl implements Configuration { } } } + + memberShardNames.put(memberName, shards); + return shards; } @Override public Optional getModuleNameFromNameSpace(String nameSpace) { + + Preconditions.checkNotNull(nameSpace, "nameSpace should not be null"); + for(Module m : modules){ if(m.getNameSpace().equals(nameSpace)){ return Optional.of(m.getName()); @@ -98,6 +124,9 @@ public class ConfigurationImpl implements Configuration { } @Override public List getShardNamesFromModuleName(String moduleName) { + + Preconditions.checkNotNull(moduleName, "moduleName should not be null"); + for(ModuleShard m : moduleShards){ if(m.getModuleName().equals(moduleName)){ List l = new ArrayList<>(); @@ -112,14 +141,23 @@ public class ConfigurationImpl implements Configuration { } @Override public List getMembersFromShardName(String shardName) { - List shards = new ArrayList(); + + Preconditions.checkNotNull(shardName, "shardName should not be null"); + + if(shardReplicaNames.containsKey(shardName)){ + return shardReplicaNames.get(shardName); + } + for(ModuleShard ms : moduleShards){ for(Shard s : ms.getShards()) { if(s.getName().equals(shardName)){ - return s.getReplicas(); + List replicas = s.getReplicas(); + shardReplicaNames.put(shardName, replicas); + return replicas; } } } + shardReplicaNames.put(shardName, Collections.EMPTY_LIST); return Collections.EMPTY_LIST; }