Search in sources :

Example 1 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 2 with CoreDescriptor

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

the class TestIndexSearcher method testUseColdSearcher.

public void testUseColdSearcher() 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 {
        System.setProperty("tests.solr.useColdSearcher", "true");
        // 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());
        assertTrue(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();
        // validate that the query runs before the searcher warmer finishes
        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);
        }
        assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
    } finally {
        System.getProperties().remove("tests.solr.useColdSearcher");
        if (coreCreated) {
            SlowSearcherListener.latch.countDown();
            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 3 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 4 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 5 with CoreDescriptor

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

the class ZkController method registerAllCoresAsDown.

private void registerAllCoresAsDown(final CurrentCoreDescriptorProvider registerOnReconnect, boolean updateLastPublished) {
    List<CoreDescriptor> descriptors = registerOnReconnect.getCurrentDescriptors();
    if (isClosed)
        return;
    if (descriptors != null) {
        // before registering as live, make sure everyone is in a
        // down state
        publishNodeAsDown(getNodeName());
        for (CoreDescriptor descriptor : descriptors) {
            // if it looks like we are going to be the leader, we don't
            // want to wait for the following stuff
            CloudDescriptor cloudDesc = descriptor.getCloudDescriptor();
            String collection = cloudDesc.getCollectionName();
            String slice = cloudDesc.getShardId();
            try {
                int children = zkStateReader.getZkClient().getChildren(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/leader_elect/" + slice + "/election", null, true).size();
                if (children == 0) {
                    log.debug("looks like we are going to be the leader for collection {} shard {}", collection, slice);
                    continue;
                }
            } catch (NoNodeException e) {
                log.debug("looks like we are going to be the leader for collection {} shard {}", collection, slice);
                continue;
            } catch (InterruptedException e2) {
                Thread.currentThread().interrupt();
            } catch (KeeperException e) {
                log.warn("", e);
                Thread.currentThread().interrupt();
            }
            final String coreZkNodeName = descriptor.getCloudDescriptor().getCoreNodeName();
            try {
                log.debug("calling waitForLeaderToSeeDownState for coreZkNodeName={} collection={} shard={}", new Object[] { coreZkNodeName, collection, slice });
                waitForLeaderToSeeDownState(descriptor, coreZkNodeName);
            } catch (Exception e) {
                SolrException.log(log, "", e);
                if (isClosed) {
                    return;
                }
            }
        }
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) CoreDescriptor(org.apache.solr.core.CoreDescriptor) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) TimeoutException(java.util.concurrent.TimeoutException) SolrException(org.apache.solr.common.SolrException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SolrCoreInitializationException(org.apache.solr.core.SolrCoreInitializationException)

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