Java Code Examples for org.apache.solr.common.cloud.ZkStateReader#LIVE_NODES_ZKNODE
The following examples show how to use
org.apache.solr.common.cloud.ZkStateReader#LIVE_NODES_ZKNODE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
private void createEphemeralLiveNode() throws KeeperException, InterruptedException { if (zkRunOnly) { return; } String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; String nodeAddedPath = ZkStateReader.SOLR_AUTOSCALING_NODE_ADDED_PATH + "/" + nodeName; log.info("Register node as live in ZooKeeper:{}", nodePath); List<Op> ops = new ArrayList<>(2); ops.add(Op.create(nodePath, null, zkClient.getZkACLProvider().getACLsToAdd(nodePath), CreateMode.EPHEMERAL)); // if there are nodeAdded triggers don't create nodeAdded markers boolean createMarkerNode = zkStateReader.getAutoScalingConfig().hasTriggerForEvents(TriggerEventType.NODEADDED); if (createMarkerNode && !zkClient.exists(nodeAddedPath, true)) { // use EPHEMERAL so that it disappears if this node goes down // and no other action is taken byte[] json = Utils.toJSON(Collections.singletonMap("timestamp", TimeSource.NANO_TIME.getEpochTimeNs())); ops.add(Op.create(nodeAddedPath, json, zkClient.getZkACLProvider().getACLsToAdd(nodeAddedPath), CreateMode.EPHEMERAL)); } zkClient.multi(ops, true); }
Example 2
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
public void removeEphemeralLiveNode() throws KeeperException, InterruptedException { if (zkRunOnly) { return; } String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; String nodeAddedPath = ZkStateReader.SOLR_AUTOSCALING_NODE_ADDED_PATH + "/" + nodeName; log.info("Remove node as live in ZooKeeper:{}", nodePath); List<Op> ops = new ArrayList<>(2); ops.add(Op.delete(nodePath, -1)); ops.add(Op.delete(nodeAddedPath, -1)); try { zkClient.multi(ops, true); } catch (NoNodeException e) { } }
Example 3
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
private void checkForExistingEphemeralNode() throws KeeperException, InterruptedException { if (zkRunOnly) { return; } String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; if (!zkClient.exists(nodePath, true)) { return; } final CountDownLatch deletedLatch = new CountDownLatch(1); Stat stat = zkClient.exists(nodePath, event -> { if (Watcher.Event.EventType.None.equals(event.getType())) { return; } if (Watcher.Event.EventType.NodeDeleted.equals(event.getType())) { deletedLatch.countDown(); } }, true); if (stat == null) { // znode suddenly disappeared but that's okay return; } boolean deleted = deletedLatch.await(zkClient.getSolrZooKeeper().getSessionTimeout() * 2, TimeUnit.MILLISECONDS); if (!deleted) { throw new SolrException(ErrorCode.SERVER_ERROR, "A previous ephemeral live node still exists. " + "Solr cannot continue. Please ensure that no other Solr process using the same port is running already."); } }
Example 4
Source File: TestStressLiveNodes.java From lucene-solr with Apache License 2.0 | 5 votes |
/** returns the number of nodes actually added w/o error */ public Integer call() { running = true; // NOTE: test includes 'running' for (int i = 0; running && i < numNodesToAdd; i++) { final String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/thrasher-" + id + "-" + i; try { client.makePath(nodePath, CreateMode.EPHEMERAL, true); numAdded++; } catch (Exception e) { log.error("failed to create: {}", nodePath, e); } } return numAdded; }
Example 5
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public MockZKController(String zkAddress, String nodeName, List<Overseer> overseers) throws InterruptedException, TimeoutException, IOException, KeeperException { this.overseers = overseers; this.nodeName = nodeName; zkClient = new SolrZkClient(zkAddress, TIMEOUT); ZkController.createClusterZkNodes(zkClient); zkStateReader = new ZkStateReader(zkClient); zkStateReader.createClusterStateWatchersAndUpdate(); // live node final String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; zkClient.makePath(nodePath, CreateMode.EPHEMERAL, true); }