Search in sources :

Example 11 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)

Example 12 with CoreDescriptor

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

the class TestIndexSearcher method createCoreAndValidateListeners.

private void createCoreAndValidateListeners(int numTimesCalled, int numTimesCalledFirstSearcher, int numTimesCalledAfterGetSearcher, int numTimesCalledFirstSearcherAfterGetSearcher) throws Exception {
    CoreContainer cores = h.getCoreContainer();
    CoreDescriptor cd = h.getCore().getCoreDescriptor();
    SolrCore newCore = null;
    // reset counters
    MockSearcherListener.numberOfTimesCalled = new AtomicInteger();
    MockSearcherListener.numberOfTimesCalledFirstSearcher = new AtomicInteger();
    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);
        //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);
        doQuery(newCore);
        assertEquals(numTimesCalled, MockSearcherListener.numberOfTimesCalled.get());
        assertEquals(numTimesCalledFirstSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get());
        addDummyDoc(newCore);
        // Open a new searcher, this should call the newSearcherListeners
        Future<?>[] future = new Future[1];
        newCore.getSearcher(true, false, future);
        future[0].get();
        assertEquals(numTimesCalledAfterGetSearcher, MockSearcherListener.numberOfTimesCalled.get());
        assertEquals(numTimesCalledFirstSearcherAfterGetSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get());
    } finally {
        if (newCore != null) {
            cores.unload("core1");
        }
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) Future(java.util.concurrent.Future)

Example 13 with CoreDescriptor

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

the class SchemaManager method waitForOtherReplicasToUpdate.

private void waitForOtherReplicasToUpdate(TimeOut timeOut, int latestVersion) {
    CoreDescriptor cd = req.getCore().getCoreDescriptor();
    String collection = cd.getCollectionName();
    if (collection != null) {
        ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) managedIndexSchema.getResourceLoader();
        if (timeOut.hasTimedOut()) {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Not enough time left to update replicas. However, the schema is updated already.");
        }
        ManagedIndexSchema.waitForSchemaZkVersionAgreement(collection, cd.getCloudDescriptor().getCoreNodeName(), latestVersion, zkLoader.getZkController(), (int) timeOut.timeLeft(TimeUnit.SECONDS));
    }
}
Also used : CoreDescriptor(org.apache.solr.core.CoreDescriptor) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrException(org.apache.solr.common.SolrException)

Example 14 with CoreDescriptor

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

the class ZkController method markAllAsNotLeader.

private void markAllAsNotLeader(final CurrentCoreDescriptorProvider registerOnReconnect) {
    List<CoreDescriptor> descriptors = registerOnReconnect.getCurrentDescriptors();
    if (descriptors != null) {
        for (CoreDescriptor descriptor : descriptors) {
            descriptor.getCloudDescriptor().setLeader(false);
            descriptor.getCloudDescriptor().setHasRegistered(false);
        }
    }
}
Also used : CoreDescriptor(org.apache.solr.core.CoreDescriptor)

Example 15 with CoreDescriptor

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

the class ZkControllerTest method testPublishAndWaitForDownStates.

@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-7736")
public void testPublishAndWaitForDownStates() throws Exception {
    String zkDir = createTempDir("testPublishAndWaitForDownStates").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;
                }
            });
            HashMap<String, DocCollection> collectionStates = new HashMap<>();
            HashMap<String, Replica> replicas = new HashMap<>();
            // than this ZkController instance
            for (int i = 1; i <= 2; i++) {
                Replica r = new Replica("core_node" + i, map(ZkStateReader.STATE_PROP, i == 1 ? "active" : "down", ZkStateReader.NODE_NAME_PROP, i == 1 ? "127.0.0.1:8983_solr" : "non_existent_host", ZkStateReader.CORE_NAME_PROP, "collection1"));
                replicas.put("core_node" + i, r);
            }
            HashMap<String, Object> sliceProps = new HashMap<>();
            sliceProps.put("state", Slice.State.ACTIVE.toString());
            Slice slice = new Slice("shard1", replicas, sliceProps);
            DocCollection c = new DocCollection("testPublishAndWaitForDownStates", map("shard1", slice), Collections.emptyMap(), DocRouter.DEFAULT);
            ClusterState state = new ClusterState(0, Collections.emptySet(), map("testPublishAndWaitForDownStates", c));
            byte[] bytes = Utils.toJSON(state);
            zkController.getZkClient().makePath(ZkStateReader.getCollectionPath("testPublishAndWaitForDownStates"), bytes, CreateMode.PERSISTENT, true);
            zkController.getZkStateReader().forceUpdateCollection("testPublishAndWaitForDownStates");
            assertTrue(zkController.getZkStateReader().getClusterState().hasCollection("testPublishAndWaitForDownStates"));
            assertNotNull(zkController.getZkStateReader().getClusterState().getCollection("testPublishAndWaitForDownStates"));
            long now = System.nanoTime();
            long timeout = now + TimeUnit.NANOSECONDS.convert(ZkController.WAIT_DOWN_STATES_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            zkController.publishAndWaitForDownStates();
            assertTrue("The ZkController.publishAndWaitForDownStates should have timed out but it didn't", System.nanoTime() >= timeout);
        } finally {
            if (zkController != null)
                zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) CoreDescriptor(org.apache.solr.core.CoreDescriptor) CloudConfig(org.apache.solr.core.CloudConfig) CoreContainer(org.apache.solr.core.CoreContainer)

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