use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method checkShardConsistency.
/**
* Returns a non-null string if replicas within the same shard do not have a
* consistent number of documents.
* If expectFailure==false, the exact differences found will be logged since
* this would be an unexpected failure.
* verbose causes extra debugging into to be displayed, even if everything is
* consistent.
*/
protected String checkShardConsistency(String shard, boolean expectFailure, boolean verbose) throws Exception {
List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
if (solrJetties == null) {
throw new RuntimeException("shard not found:" + shard + " keys:" + shardToJetty.keySet());
}
long num = -1;
long lastNum = -1;
String failMessage = null;
if (verbose)
System.err.println("check const of " + shard);
int cnt = 0;
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
assertEquals("The client count does not match up with the shard count for slice:" + shard, zkStateReader.getClusterState().getSlice(DEFAULT_COLLECTION, shard).getReplicasMap().size(), solrJetties.size());
CloudJettyRunner lastJetty = null;
for (CloudJettyRunner cjetty : solrJetties) {
ZkNodeProps props = cjetty.info;
if (verbose)
System.err.println("client" + cnt++);
if (verbose)
System.err.println("PROPS:" + props);
try {
// "tests" is just a tag that won't do anything except be echoed in logs
SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", "checkShardConsistency");
num = cjetty.client.solrClient.query(query).getResults().getNumFound();
} catch (SolrServerException e) {
if (verbose)
System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
} catch (SolrException e) {
if (verbose)
System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
}
boolean live = false;
String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
live = true;
}
if (verbose)
System.err.println(" live:" + live);
if (verbose)
System.err.println(" num:" + num + "\n");
boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
if (active && live) {
if (lastNum > -1 && lastNum != num && failMessage == null) {
failMessage = shard + " is not consistent. Got " + lastNum + " from " + lastJetty.url + " (previous client)" + " and got " + num + " from " + cjetty.url;
if (!expectFailure || verbose) {
System.err.println("######" + failMessage);
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
query.set("fl", "id,_version_");
query.set("rows", "100000");
query.set("sort", "id asc");
query.set("tests", "checkShardConsistency/showDiff");
SolrDocumentList lst1 = lastJetty.client.solrClient.query(query).getResults();
SolrDocumentList lst2 = cjetty.client.solrClient.query(query).getResults();
CloudInspectUtil.showDiff(lst1, lst2, lastJetty.url, cjetty.url);
}
}
lastNum = num;
lastJetty = cjetty;
}
}
return failMessage;
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method checkShardConsistency.
/* Checks shard consistency and optionally checks against the control shard.
* The test will be failed if differences are found.
*/
protected void checkShardConsistency(boolean checkVsControl, boolean verbose, Set<String> addFails, Set<String> deleteFails) throws Exception {
updateMappingsFromZk(jettys, clients, true);
Set<String> theShards = shardToJetty.keySet();
String failMessage = null;
for (String shard : theShards) {
String shardFailMessage = checkShardConsistency(shard, false, verbose);
if (shardFailMessage != null && failMessage == null) {
failMessage = shardFailMessage;
}
}
if (failMessage != null) {
fail(failMessage);
}
if (!checkVsControl)
return;
// add a tag to aid in debugging via logs
SolrParams q = params("q", "*:*", "rows", "0", "tests", "checkShardConsistency(vsControl)");
SolrDocumentList controlDocList = controlClient.query(q).getResults();
long controlDocs = controlDocList.getNumFound();
SolrDocumentList cloudDocList = cloudClient.query(q).getResults();
long cloudClientDocs = cloudDocList.getNumFound();
// now check that the right # are on each shard
theShards = shardToJetty.keySet();
int cnt = 0;
for (String s : theShards) {
int times = shardToJetty.get(s).size();
for (int i = 0; i < times; i++) {
try {
CloudJettyRunner cjetty = shardToJetty.get(s).get(i);
ZkNodeProps props = cjetty.info;
SolrClient client = cjetty.client.solrClient;
boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
if (active) {
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
long results = client.query(query).getResults().getNumFound();
if (verbose)
System.err.println(new ZkCoreNodeProps(props).getCoreUrl() + " : " + results);
if (verbose)
System.err.println("shard:" + props.getStr(ZkStateReader.SHARD_ID_PROP));
cnt += results;
break;
}
} catch (Exception e) {
// if we have a problem, try the next one
if (i == times - 1) {
throw e;
}
}
}
}
if (controlDocs != cnt || cloudClientDocs != controlDocs) {
String msg = "document count mismatch. control=" + controlDocs + " sum(shards)=" + cnt + " cloudClient=" + cloudClientDocs;
log.error(msg);
boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient, addFails, deleteFails);
if (shouldFail) {
fail(msg);
}
}
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method getUrlFromZk.
public static String getUrlFromZk(ClusterState clusterState, String collection) {
Map<String, Slice> slices = clusterState.getCollection(collection).getSlicesMap();
if (slices == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
}
for (Map.Entry<String, Slice> entry : slices.entrySet()) {
Slice slice = entry.getValue();
Map<String, Replica> shards = slice.getReplicasMap();
Set<Map.Entry<String, Replica>> shardEntries = shards.entrySet();
for (Map.Entry<String, Replica> shardEntry : shardEntries) {
final ZkNodeProps node = shardEntry.getValue();
if (clusterState.liveNodesContain(node.getStr(ZkStateReader.NODE_NAME_PROP))) {
//new ZkCoreNodeProps(node).getCoreUrl();
return ZkCoreNodeProps.getCoreUrl(node.getStr(ZkStateReader.BASE_URL_PROP), collection);
}
}
}
throw new RuntimeException("Could not find a live node for collection:" + collection);
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class ChaosMonkey method checkIfKillIsLegal.
private int checkIfKillIsLegal(String sliceName, int numActive) throws KeeperException, InterruptedException {
for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) {
// get latest cloud state
zkStateReader.forceUpdateCollection(collection);
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
Slice slice = docCollection.getSlice(sliceName);
ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName);
if (props == null) {
throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
}
final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP));
final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
if (cloudJetty.jetty.isRunning() && state == Replica.State.ACTIVE && zkStateReader.getClusterState().liveNodesContain(nodeName)) {
numActive++;
}
}
return numActive;
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class ChaosMonkey method getTypeForJetty.
private Type getTypeForJetty(String sliceName, CloudJettyRunner cjetty) {
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
Slice slice = docCollection.getSlice(sliceName);
ZkNodeProps props = slice.getReplicasMap().get(cjetty.coreNodeName);
if (props == null) {
throw new RuntimeException("shard name " + cjetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
}
return Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
}
Aggregations