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);
}
}
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());
}
}
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();
}
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;
}
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();
}
}
Aggregations