use of org.apache.solr.cloud.CloudDescriptor in project lucene-solr by apache.
the class SolrShardReporterTest method test.
@Test
public void test() throws Exception {
waitForRecoveriesToFinish("control_collection", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
waitForRecoveriesToFinish("collection1", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
printLayout();
// wait for at least two reports
Thread.sleep(10000);
ClusterState state = jettys.get(0).getCoreContainer().getZkController().getClusterState();
for (JettySolrRunner jetty : jettys) {
CoreContainer cc = jetty.getCoreContainer();
SolrMetricManager metricManager = cc.getMetricManager();
for (final String coreName : cc.getLoadedCoreNames()) {
CoreDescriptor cd = cc.getCoreDescriptor(coreName);
if (cd.getCloudDescriptor() == null) {
// not a cloud collection
continue;
}
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName());
String replicaName = SolrCoreMetricManager.parseReplicaName(cloudDesc.getCollectionName(), coreName);
if (replicaName == null) {
replicaName = cloudDesc.getCoreNodeName();
}
String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null);
String leaderRegistryName = SolrCoreMetricManager.createLeaderRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId());
boolean leader = cloudDesc.isLeader();
Slice slice = docCollection.getSlice(cloudDesc.getShardId());
int numReplicas = slice.getReplicas().size();
if (leader) {
assertTrue(metricManager.registryNames() + " doesn't contain " + leaderRegistryName, metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), numReplicas, am.size());
}
});
} else {
assertFalse(metricManager.registryNames() + " contains " + leaderRegistryName + " but it's not a leader!", metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), 1, am.size());
}
});
}
assertTrue(metricManager.registryNames() + " doesn't contain " + registryName, metricManager.registryNames().contains(registryName));
}
}
SolrMetricManager metricManager = controlJetty.getCoreContainer().getMetricManager();
assertTrue(metricManager.registryNames().contains("solr.cluster"));
}
use of org.apache.solr.cloud.CloudDescriptor in project lucene-solr by apache.
the class CloserThread method processCoreCreateException.
/**
* Take action when we failed to create a SolrCore. If error is due to corrupt index, try to recover. Various recovery
* strategies can be specified via system properties "-DCoreInitFailedAction={fromleader, none}"
*
* @see CoreInitFailedAction
*
* @param original
* the problem seen when loading the core the first time.
* @param dcore
* core descriptor for the core to create
* @param coreConfig
* core config for the core to create
* @return if possible
* @throws SolrException
* rethrows the original exception if we will not attempt to recover, throws a new SolrException with the
* original exception as a suppressed exception if there is a second problem creating the solr core.
*/
private SolrCore processCoreCreateException(SolrException original, CoreDescriptor dcore, ConfigSet coreConfig) {
// Traverse full chain since CIE may not be root exception
Throwable cause = original;
while ((cause = cause.getCause()) != null) {
if (cause instanceof CorruptIndexException) {
break;
}
}
// If no CorruptIndexExeption, nothing we can try here
if (cause == null)
throw original;
CoreInitFailedAction action = CoreInitFailedAction.valueOf(System.getProperty(CoreInitFailedAction.class.getSimpleName(), "none"));
log.debug("CorruptIndexException while creating core, will attempt to repair via {}", action);
switch(action) {
case // Recovery from leader on a CorruptedIndexException
fromleader:
if (isZooKeeperAware()) {
CloudDescriptor desc = dcore.getCloudDescriptor();
try {
Replica leader = getZkController().getClusterState().getCollection(desc.getCollectionName()).getSlice(desc.getShardId()).getLeader();
if (leader != null && leader.getState() == State.ACTIVE) {
log.info("Found active leader, will attempt to create fresh core and recover.");
resetIndexDirectory(dcore, coreConfig);
return new SolrCore(this, dcore, coreConfig);
}
} catch (SolrException se) {
se.addSuppressed(original);
throw se;
}
}
throw original;
case none:
throw original;
default:
log.warn("Failed to create core, and did not recognize specified 'CoreInitFailedAction': [{}]. Valid options are {}.", action, Arrays.asList(CoreInitFailedAction.values()));
throw original;
}
}
use of org.apache.solr.cloud.CloudDescriptor in project lucene-solr by apache.
the class SolrCoreMetricManager method createRegistryName.
/**
* This method is used by {@link org.apache.solr.core.CoreContainer#rename(String, String)}.
* @param aCore existing core with old name
* @param coreName new name
* @return new registry name
*/
public static String createRegistryName(SolrCore aCore, String coreName) {
CloudDescriptor cd = aCore.getCoreDescriptor().getCloudDescriptor();
String replicaName = null;
if (cd != null) {
replicaName = parseReplicaName(cd.getCollectionName(), coreName);
}
return createRegistryName(cd != null, cd != null ? cd.getCollectionName() : null, cd != null ? cd.getShardId() : null, replicaName, coreName);
}
use of org.apache.solr.cloud.CloudDescriptor in project lucene-solr by apache.
the class SolrCoreMetricManager method initCloudMode.
private void initCloudMode() {
CloudDescriptor cd = core.getCoreDescriptor().getCloudDescriptor();
if (cd != null) {
cloudMode = true;
collectionName = core.getCoreDescriptor().getCollectionName();
shardName = cd.getShardId();
//replicaName = cd.getCoreNodeName();
String coreName = core.getName();
replicaName = parseReplicaName(collectionName, coreName);
if (replicaName == null) {
replicaName = cd.getCoreNodeName();
}
}
}
use of org.apache.solr.cloud.CloudDescriptor in project lucene-solr by apache.
the class MDCLoggingContext method setCoreDescriptor.
public static void setCoreDescriptor(CoreContainer coreContainer, CoreDescriptor cd) {
if (cd != null) {
int callDepth = CALL_DEPTH.get();
CALL_DEPTH.set(callDepth + 1);
if (callDepth > 0) {
return;
}
setCoreName(cd.getName());
if (coreContainer != null) {
ZkController zkController = coreContainer.getZkController();
if (zkController != null) {
setNodeName(zkController.getNodeName());
}
}
CloudDescriptor ccd = cd.getCloudDescriptor();
if (ccd != null) {
setCollection(ccd.getCollectionName());
setShard(ccd.getShardId());
setReplica(ccd.getCoreNodeName());
}
}
}
Aggregations