Search in sources :

Example 56 with SolrZkClient

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

the class MiniSolrCloudCluster method waitForAllNodes.

private void waitForAllNodes(int numServers, int timeout) throws IOException, InterruptedException {
    try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) {
        int numliveNodes = 0;
        int retries = timeout;
        String liveNodesPath = "/solr/live_nodes";
        // Wait up to {timeout} seconds for number of live_nodes to match up number of servers
        do {
            if (zkClient.exists(liveNodesPath, true)) {
                numliveNodes = zkClient.getChildren(liveNodesPath, null, true).size();
                if (numliveNodes == numServers) {
                    break;
                }
            }
            retries--;
            if (retries == 0) {
                throw new IllegalStateException("Solr servers failed to register with ZK." + " Current count: " + numliveNodes + "; Expected count: " + numServers);
            }
            Thread.sleep(1000);
        } while (numliveNodes != numServers);
    } catch (KeeperException e) {
        throw new IOException("Error communicating with zookeeper", e);
    }
}
Also used : IOException(java.io.IOException) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 57 with SolrZkClient

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

the class MiniSolrCloudCluster method expireZkSession.

/**
   * Make the zookeeper session on a particular jetty expire
   */
public void expireZkSession(JettySolrRunner jetty) {
    CoreContainer cores = jetty.getCoreContainer();
    if (cores != null) {
        SolrZkClient zkClient = cores.getZkController().getZkClient();
        zkClient.getSolrZooKeeper().closeCnxn();
        long sessionId = zkClient.getSolrZooKeeper().getSessionId();
        zkServer.expire(sessionId);
        log.info("Expired zookeeper session {} from node {}", sessionId, jetty.getBaseUrl());
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 58 with SolrZkClient

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

the class AbstractZkTestCase method tryCleanPath.

static void tryCleanPath(String zkHost, String path) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT);
    if (zkClient.exists(path, true)) {
        zkClient.clean(path);
    }
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 59 with SolrZkClient

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

the class ChaosMonkeyShardSplitTest method electNewOverseer.

/**
   * Elects a new overseer
   *
   * @return SolrZkClient
   */
private SolrZkClient electNewOverseer(String address) throws KeeperException, InterruptedException, IOException {
    SolrZkClient zkClient = new SolrZkClient(address, TIMEOUT);
    ZkStateReader reader = new ZkStateReader(zkClient);
    LeaderElector overseerElector = new LeaderElector(zkClient);
    UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
    // TODO: close Overseer
    Overseer overseer = new Overseer(new HttpShardHandlerFactory().getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build());
    overseer.close();
    ElectionContext ec = new OverseerElectionContext(zkClient, overseer, address.replaceAll("/", "_"));
    overseerElector.setup(ec);
    overseerElector.joinElection(ec, false);
    reader.close();
    return zkClient;
}
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)

Example 60 with SolrZkClient

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

the class ConnectionManagerTest method testReconnectWhenZkDisappeared.

@Test
public void testReconnectWhenZkDisappeared() throws Exception {
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new DefaultSolrThreadFactory("connectionManagerTest"));
    // setup a SolrZkClient to do some getBaseUrlForNodeName testing
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        MockZkClientConnectionStrategy strat = new MockZkClientConnectionStrategy();
        SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, strat, null);
        ConnectionManager cm = zkClient.getConnectionManager();
        try {
            assertFalse(cm.isLikelyExpired());
            assertTrue(cm.isConnected());
            // reconnect -- should no longer be likely expired
            cm.process(new WatchedEvent(EventType.None, KeeperState.Expired, ""));
            assertFalse(cm.isLikelyExpired());
            assertTrue(cm.isConnected());
            assertTrue(strat.isExceptionThrow());
        } finally {
            cm.close();
            zkClient.close();
            executor.shutdown();
        }
    } finally {
        server.shutdown();
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectionManager(org.apache.solr.common.cloud.ConnectionManager) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Aggregations

SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)130 Test (org.junit.Test)46 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)34 HashMap (java.util.HashMap)21 KeeperException (org.apache.zookeeper.KeeperException)18 SolrException (org.apache.solr.common.SolrException)15 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)14 IOException (java.io.IOException)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 DocCollection (org.apache.solr.common.cloud.DocCollection)12 Map (java.util.Map)11 Slice (org.apache.solr.common.cloud.Slice)11 Replica (org.apache.solr.common.cloud.Replica)10 ArrayList (java.util.ArrayList)9 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 Overseer (org.apache.solr.cloud.Overseer)8 ZkTestServer (org.apache.solr.cloud.ZkTestServer)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 NamedList (org.apache.solr.common.util.NamedList)7