Search in sources :

Example 26 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class OverseerTest method testOverseerStatsReset.

@Test
public void testOverseerStatsReset() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    ZkStateReader reader = null;
    MockZKController mockController = null;
    SolrZkClient zkClient = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        mockController = new MockZKController(server.getZkAddress(), "node1");
        LeaderElector overseerElector = new LeaderElector(zkClient);
        if (overseers.size() > 0) {
            overseers.get(overseers.size() - 1).close();
            overseers.get(overseers.size() - 1).getZkStateReader().getZkClient().close();
        }
        UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
        updateShardHandlers.add(updateShardHandler);
        HttpShardHandlerFactory httpShardHandlerFactory = new HttpShardHandlerFactory();
        httpShardHandlerFactorys.add(httpShardHandlerFactory);
        Overseer overseer = new Overseer(httpShardHandlerFactory.getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "").build());
        overseers.add(overseer);
        ElectionContext ec = new OverseerElectionContext(zkClient, overseer, server.getZkAddress().replaceAll("/", "_"));
        overseerElector.setup(ec);
        overseerElector.joinElection(ec, false);
        mockController.publishState(COLLECTION, "core1", "core_node1", Replica.State.ACTIVE, 1);
        assertNotNull(overseer.getStats());
        assertTrue((overseer.getStats().getSuccessCount(OverseerAction.STATE.toLower())) > 0);
        // shut it down
        overseer.close();
        ec.cancelElection();
        // start it again
        overseerElector.setup(ec);
        overseerElector.joinElection(ec, false);
        assertNotNull(overseer.getStats());
        assertEquals(0, (overseer.getStats().getSuccessCount(OverseerAction.STATE.toLower())));
    } finally {
        close(mockController);
        close(zkClient);
        close(reader);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) Test(org.junit.Test)

Example 27 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class OverseerTest method testStateChange.

@Test
public void testStateChange() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    SolrZkClient overseerClient = null;
    try {
        server.run();
        zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        overseerClient = electNewOverseer(server.getZkAddress());
        DistributedQueue q = Overseer.getStateUpdateQueue(zkClient);
        ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.STATE.toLower(), ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr", ZkStateReader.NODE_NAME_PROP, "node1", ZkStateReader.COLLECTION_PROP, COLLECTION, ZkStateReader.CORE_NAME_PROP, "core1", ZkStateReader.ROLES_PROP, "", ZkStateReader.STATE_PROP, Replica.State.RECOVERING.toString());
        q.offer(Utils.toJSON(m));
        waitForCollections(reader, COLLECTION);
        assertSame(reader.getClusterState().toString(), Replica.State.RECOVERING, reader.getClusterState().getSlice(COLLECTION, "shard1").getReplica("core_node1").getState());
        //publish node state (active)
        m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.STATE.toLower(), ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr", ZkStateReader.NODE_NAME_PROP, "node1", ZkStateReader.COLLECTION_PROP, COLLECTION, ZkStateReader.CORE_NAME_PROP, "core1", ZkStateReader.ROLES_PROP, "", ZkStateReader.STATE_PROP, Replica.State.ACTIVE.toString());
        q.offer(Utils.toJSON(m));
        verifyReplicaStatus(reader, "collection1", "shard1", "core_node1", Replica.State.ACTIVE);
    } finally {
        close(zkClient);
        close(overseerClient);
        close(reader);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 28 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class OverseerTest method testPlaceholders.

@Test
public void testPlaceholders() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient controllerClient = null;
    SolrZkClient overseerClient = null;
    ZkStateReader reader = null;
    MockZKController mockController = null;
    try {
        server.run();
        controllerClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        ZkController.createClusterZkNodes(controllerClient);
        reader = new ZkStateReader(controllerClient);
        reader.createClusterStateWatchersAndUpdate();
        mockController = new MockZKController(server.getZkAddress(), "node1");
        overseerClient = electNewOverseer(server.getZkAddress());
        mockController.publishState(COLLECTION, "core1", "node1", Replica.State.RECOVERING, 12);
        waitForCollections(reader, COLLECTION);
        assertEquals("Slicecount does not match", 12, reader.getClusterState().getSlices(COLLECTION).size());
    } finally {
        close(overseerClient);
        close(mockController);
        close(controllerClient);
        close(reader);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 29 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class OverseerTest method tearDown.

@After
public void tearDown() throws Exception {
    super.tearDown();
    for (Overseer overseer : overseers) {
        overseer.close();
    }
    overseers.clear();
    for (ZkStateReader reader : readers) {
        reader.close();
    }
    readers.clear();
    for (HttpShardHandlerFactory handlerFactory : httpShardHandlerFactorys) {
        handlerFactory.close();
    }
    httpShardHandlerFactorys.clear();
    for (UpdateShardHandler updateShardHandler : updateShardHandlers) {
        updateShardHandler.close();
    }
    updateShardHandlers.clear();
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) After(org.junit.After)

Example 30 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class ZkStateReaderTest method testWatchedCollectionCreation.

public void testWatchedCollectionCreation() throws Exception {
    String zkDir = createTempDir("testWatchedCollectionCreation").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        reader.registerCore("c1");
        // Initially there should be no c1 collection.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
        reader.forceUpdateCollection("c1");
        // Still no c1 collection, despite a collection path.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
        // create new collection with stateFormat = 2
        DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
        ZkWriteCommand wc = new ZkWriteCommand("c1", state);
        writer.enqueueUpdate(reader.getClusterState(), wc, null);
        writer.writePendingUpdates();
        assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
        //reader.forceUpdateCollection("c1");
        reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
        ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
        assertNotNull(ref);
        assertFalse(ref.isLazilyLoaded());
        assertEquals(2, ref.get().getStateFormat());
    } finally {
        IOUtils.close(reader, zkClient);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkTestServer(org.apache.solr.cloud.ZkTestServer) Overseer(org.apache.solr.cloud.Overseer) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Aggregations

ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)133 ClusterState (org.apache.solr.common.cloud.ClusterState)58 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)48 HashMap (java.util.HashMap)34 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)33 ArrayList (java.util.ArrayList)32 DocCollection (org.apache.solr.common.cloud.DocCollection)31 Test (org.junit.Test)26 SolrException (org.apache.solr.common.SolrException)25 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)22 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)20 IOException (java.io.IOException)19 Map (java.util.Map)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)18 KeeperException (org.apache.zookeeper.KeeperException)16 SolrQuery (org.apache.solr.client.solrj.SolrQuery)15 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 SolrServerException (org.apache.solr.client.solrj.SolrServerException)13 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)12