SOLR-12208: added a testcase for fetching arbitrary replica info

This commit is contained in:
Noble Paul 2018-06-14 00:07:30 +10:00
parent 6f9f4f70f2
commit 377f16de5e
2 changed files with 22 additions and 5 deletions

View File

@ -33,16 +33,17 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.cloud.DistributedQueueFactory;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
import org.apache.solr.client.solrj.cloud.autoscaling.Policy;
import org.apache.solr.client.solrj.cloud.autoscaling.ReplicaInfo;
import org.apache.solr.client.solrj.cloud.autoscaling.Row;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.cloud.autoscaling.Suggestion;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.SolrClientCloudManager;
import org.apache.solr.client.solrj.impl.SolrClientNodeStateProvider;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.cloud.OverseerTaskProcessor;
import org.apache.solr.cloud.SolrCloudTestCase;
@ -106,10 +107,19 @@ public class TestPolicyCloud extends SolrCloudTestCase {
" }" +
"}";
AutoScalingConfig config = new AutoScalingConfig((Map<String, Object>) Utils.fromJSONString(autoScaleJson));
AtomicInteger count = new AtomicInteger(0);
SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()), cluster.getSolrClient());
String nodeName = cloudManager.getClusterStateProvider().getLiveNodes().iterator().next();
SolrClientNodeStateProvider nodeStateProvider = (SolrClientNodeStateProvider) cloudManager.getNodeStateProvider();
Map<String, Map<String, List<ReplicaInfo>>> result = nodeStateProvider.getReplicaInfo(nodeName, Collections.singleton("UPDATE./update.requests"));
nodeStateProvider.forEachReplica(nodeName, replicaInfo -> {
if (replicaInfo.getVariables().containsKey("UPDATE./update.requests")) count.incrementAndGet();
});
assertTrue(count.get() > 0);
Policy.Session session = config.getPolicy().createSession(cloudManager);
AtomicInteger count = new AtomicInteger(0);
count .set(0);
for (Row row : session.getSorted()) {
row.collectionVsShardVsReplicas.forEach((c, shardVsReplicas) -> shardVsReplicas.forEach((s, replicaInfos) -> {
for (ReplicaInfo replicaInfo : replicaInfos) {

View File

@ -27,6 +27,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -113,6 +114,10 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
return ctx.getTags();
}
public void forEachReplica(String node, Consumer<ReplicaInfo> consumer){
Row.forEachReplica(nodeVsCollectionVsShardVsReplicaInfo.get(node), consumer);
}
@Override
public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String node, Collection<String> keys) {
@ -124,9 +129,11 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
if (r.getVariables().containsKey(key)) continue;
String perReplicaAttrKeyPrefix = "solr.core." + r.getCollection() + "." + r.getShard() + "." + Utils.parseMetricsReplicaName(r.getCollection(), r.getCore()) + ":";
Suggestion.ConditionType tagType = Suggestion.getTagType(key);
if(tagType == null) continue;
String perReplicaValue = tagType.metricsAttribute;
perReplicaValue = perReplicaValue == null ? key : perReplicaValue;
String perReplicaValue = key;
if (tagType != null) {
perReplicaValue = tagType.metricsAttribute;
perReplicaValue = perReplicaValue == null ? key : perReplicaValue;
}
perReplicaAttrKeyPrefix += perReplicaValue;
keyVsReplica.put(perReplicaAttrKeyPrefix, new Pair<>(key, r));
}