Search in sources :

Example 1 with CloudDescriptor

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"));
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CoreDescriptor(org.apache.solr.core.CoreDescriptor) AggregateMetric(org.apache.solr.metrics.AggregateMetric) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor) CoreContainer(org.apache.solr.core.CoreContainer) Slice(org.apache.solr.common.cloud.Slice) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Example 2 with CloudDescriptor

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;
    }
}
Also used : CorruptIndexException(org.apache.lucene.index.CorruptIndexException) Replica(org.apache.solr.common.cloud.Replica) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor) SolrException(org.apache.solr.common.SolrException)

Example 3 with CloudDescriptor

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);
}
Also used : CloudDescriptor(org.apache.solr.cloud.CloudDescriptor)

Example 4 with CloudDescriptor

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();
        }
    }
}
Also used : CloudDescriptor(org.apache.solr.cloud.CloudDescriptor)

Example 5 with CloudDescriptor

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());
        }
    }
}
Also used : ZkController(org.apache.solr.cloud.ZkController) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor)

Aggregations

CloudDescriptor (org.apache.solr.cloud.CloudDescriptor)15 Replica (org.apache.solr.common.cloud.Replica)8 SolrException (org.apache.solr.common.SolrException)6 ClusterState (org.apache.solr.common.cloud.ClusterState)6 Slice (org.apache.solr.common.cloud.Slice)6 ArrayList (java.util.ArrayList)5 ZkController (org.apache.solr.cloud.ZkController)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)5 DocCollection (org.apache.solr.common.cloud.DocCollection)4 SolrParams (org.apache.solr.common.params.SolrParams)4 NamedList (org.apache.solr.common.util.NamedList)4 HashMap (java.util.HashMap)3 List (java.util.List)3 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)3 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)3 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2