diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 91577bf26f0..b97870fa751 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -128,6 +128,8 @@ Bug Fixes * SOLR-6087: SolrIndexSearcher makes no DelegatingCollector.finish() call when IndexSearcher throws an expected exception. (Christine Poerschke via shalin) +* SOLR-7420: Overseer stats are not reset on loss of ZK connection. (Jessica Cheng, shalin) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java index 9d175cf5945..f35c3e57933 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -825,6 +825,7 @@ public class Overseer implements Closeable { this.id = id; closed = false; doClose(); + stats = new Stats(); log.info("Overseer (id=" + id + ") starting"); createOverseerNode(reader.getZkClient()); //launch cluster state updater thread @@ -1048,6 +1049,10 @@ public class Overseer implements Closeable { public void setQueueLength(int queueLength) { this.queueLength = queueLength; } + + public void clear() { + stats.clear(); + } } public static class Stat { diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java index 793cb406b78..c14ffb7cfd6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -434,7 +434,7 @@ public class OverseerTest extends SolrTestCaseJ4 { Thread.sleep(200); } - assertEquals("Unable to verify all cores have been assigned an id in cloudstate", + assertEquals("Unable to verify all cores have been assigned an id in cloudstate", coreCount, cloudStateSliceCount); // make sure all cores have been returned an id @@ -689,6 +689,69 @@ public class OverseerTest extends SolrTestCaseJ4 { server.shutdown(); } } + + @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.RECOVERING, 1); + + assertNotNull(overseer.getStats()); + assertEquals(1, (overseer.getStats().getSuccessCount(OverseerAction.STATE.toLower()))); + + // 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(); + } + } private AtomicInteger killCounter = new AtomicInteger();