From 57e976341b24c5f86f090c52f41ce6940f9cd6a5 Mon Sep 17 00:00:00 2001 From: Cao Manh Dat Date: Tue, 17 Oct 2017 17:35:00 +0700 Subject: [PATCH] SOLR-11478: Solr should remove itself from live_nodes in zk immediately on shutdown --- solr/CHANGES.txt | 4 ++++ .../java/org/apache/solr/cloud/ZkController.java | 14 ++++++++++++++ .../java/org/apache/solr/core/CoreContainer.java | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d7dddf4abe1..645664cf252 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -61,6 +61,10 @@ Optimizations * SOLR-11443: Remove the usage of workqueue for Overseer. (Cao Manh Dat, Scott Blum) +Other Changes +---------------------- +* SOLR-11478: Solr should remove itself from live_nodes in zk immediately on shutdown. (Cao Manh Dat) + ================== 7.1.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index 35171dab5fa..b6a88ea45c2 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -976,6 +976,20 @@ public class ZkController { zkClient.multi(ops, true); } + 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 ops = new ArrayList<>(2); + ops.add(Op.delete(nodePath, -1)); + ops.add(Op.delete(nodeAddedPath, -1)); + zkClient.multi(ops, true); + } + public String getNodeName() { return nodeName; } diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index b41d2007658..a9e815d9131 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -747,6 +747,11 @@ public class CoreContainer { if (isZooKeeperAware()) { cancelCoreRecoveries(); zkSys.zkController.publishNodeAsDown(zkSys.zkController.getNodeName()); + try { + zkSys.zkController.removeEphemeralLiveNode(); + } catch (Exception e) { + log.warn("Error removing live node. Continuing to close CoreContainer", e); + } if (metricManager != null) { metricManager.closeReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.cluster)); }