Search in sources :

Example 6 with CoreDescriptor

use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.

the class TestIndexSearcher method testDontUseColdSearcher.

public void testDontUseColdSearcher() throws Exception {
    MockSearchComponent.registerFirstSearcherListener = false;
    MockSearchComponent.registerNewSearcherListener = false;
    MockSearchComponent.registerSlowSearcherListener = true;
    final AtomicBoolean querySucceeded = new AtomicBoolean(false);
    SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
    SlowSearcherListener.latch = new CountDownLatch(1);
    CoreContainer cores = h.getCoreContainer();
    CoreDescriptor cd = h.getCore().getCoreDescriptor();
    final SolrCore newCore;
    boolean coreCreated = false;
    try {
        // Create a new core, this should call all the firstSearcherListeners
        newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
        coreCreated = true;
        //validate that the new core was created with the correct solrconfig
        assertNotNull(newCore.getSearchComponent("mock"));
        assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
        assertFalse(newCore.getSolrConfig().useColdSearcher);
        Thread t = new Thread() {

            public void run() {
                try {
                    doQuery(newCore);
                    querySucceeded.set(true);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            ;
        };
        t.start();
        if (System.getProperty(SYSPROP_NIGHTLY) != null) {
            // even if we wait here, the SearcherListener should not finish
            Thread.sleep(500);
        }
        // validate that the searcher warmer didn't finish yet. 
        assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
        assertFalse("Query should be waiting for warming to finish", querySucceeded.get());
        // Let warmer finish 
        SlowSearcherListener.latch.countDown();
        // Validate that the query eventually succeeds
        for (int i = 0; i <= 1000; i++) {
            if (querySucceeded.get()) {
                break;
            }
            if (i == 1000) {
                fail("Query didn't succeed after 10 secoonds");
            }
            Thread.sleep(10);
        }
    } finally {
        if (coreCreated) {
            cores.unload("core1");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoreContainer(org.apache.solr.core.CoreContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Example 7 with CoreDescriptor

use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.

the class ZkControllerTest method testGetHostName.

public void testGetHostName() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    CoreContainer cc = null;
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        cc = getCoreContainer();
        ZkController zkController = null;
        try {
            CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
            zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {

                @Override
                public List<CoreDescriptor> getCurrentDescriptors() {
                    // do nothing
                    return null;
                }
            });
        } catch (IllegalArgumentException e) {
            fail("ZkController did not normalize host name correctly");
        } finally {
            if (zkController != null)
                zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CoreDescriptor(org.apache.solr.core.CoreDescriptor) CloudConfig(org.apache.solr.core.CloudConfig)

Example 8 with CoreDescriptor

use of org.apache.solr.core.CoreDescriptor 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 9 with CoreDescriptor

use of org.apache.solr.core.CoreDescriptor in project stanbol by apache.

the class EmbeddedSolrHelper method makeEmbeddedSolrServer.

/**
     * Create a single core Solr server with it's own folder hierarchy.
     */
public static EmbeddedSolrServer makeEmbeddedSolrServer(File rootFolder, String solrServerId, String coreId, String configName) throws IOException, ParserConfigurationException, SAXException {
    File solrFolder = new File(rootFolder, solrServerId);
    FileUtils.deleteQuietly(solrFolder);
    solrFolder.mkdir();
    // solr conf file
    File solrFile = new File(solrFolder, "solr.xml");
    InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/solr.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test solr.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(solrFile));
    // solr conf folder with schema
    File solrCoreFolder = new File(solrFolder, coreId);
    solrCoreFolder.mkdir();
    File solrConfFolder = new File(solrCoreFolder, "conf");
    solrConfFolder.mkdir();
    File schemaFile = new File(solrConfFolder, "schema.xml");
    is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/schema.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test schema.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(schemaFile));
    File solrConfigFile = new File(solrConfFolder, "solrconfig.xml");
    is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/solrconfig.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test solrconfig.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(solrConfigFile));
    // create the embedded server
    SolrResourceLoader loader = new SolrResourceLoader(solrFolder.getAbsolutePath());
    CoreContainer coreContainer = new CoreContainer(loader);
    //NOTE: with Solr 4.4 we need to call coreContainer.load() otherwise we
    //would be affected by the issue stated at 
    //http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201301.mbox/%3CB7B8B36F1A0BE24F842758C318E56E925EB334%40EXCHDB2.na1.ad.group%3E
    //while this was introduced with 4.1 this only affects this code with 4.4
    //as with an API change the methods implicitly calling load() where
    //removed.
    coreContainer.load();
    CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId, solrCoreFolder.getAbsolutePath());
    SolrCore core = coreContainer.create(coreDescriptor);
    //        coreContainer.createAndLoad(solrHome, configFile)load();
    coreContainer.register(coreId, core, true);
    return new EmbeddedSolrServer(coreContainer, coreId);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) InputStream(java.io.InputStream) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) FileOutputStream(java.io.FileOutputStream) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)

Example 10 with CoreDescriptor

use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.

the class SuggestComponentTest method reloadCore.

private void reloadCore(boolean createNewCore) throws Exception {
    if (createNewCore) {
        CoreContainer cores = h.getCoreContainer();
        SolrCore core = h.getCore();
        String dataDir1 = core.getDataDir();
        CoreDescriptor cd = core.getCoreDescriptor();
        h.close();
        createCore();
        SolrCore createdCore = h.getCore();
        assertEquals(dataDir1, createdCore.getDataDir());
        assertEquals(createdCore, h.getCore());
    } else {
        h.reload();
        // On regular reloading, wait until the new searcher is registered
        waitForWarming();
    }
    assertQ(req("qt", "standard", "q", "*:*"), "//*[@numFound='11']");
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) CoreDescriptor(org.apache.solr.core.CoreDescriptor)

Aggregations

CoreDescriptor (org.apache.solr.core.CoreDescriptor)21 CoreContainer (org.apache.solr.core.CoreContainer)11 SolrCore (org.apache.solr.core.SolrCore)11 File (java.io.File)7 IOException (java.io.IOException)6 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)5 SolrException (org.apache.solr.common.SolrException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NamedList (org.apache.solr.common.util.NamedList)3 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)3 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 CloudDescriptor (org.apache.solr.cloud.CloudDescriptor)2 ZkController (org.apache.solr.cloud.ZkController)2 ClusterState (org.apache.solr.common.cloud.ClusterState)2 Slice (org.apache.solr.common.cloud.Slice)2