SOLR-7420: Overseer stats are not reset on loss of ZK connection

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674458 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-04-18 08:42:57 +00:00
parent 8573f64b9c
commit e541bccd45
3 changed files with 71 additions and 1 deletions

View File

@ -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
----------------------

View File

@ -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 {

View File

@ -690,6 +690,69 @@ public class OverseerTest extends SolrTestCaseJ4 {
}
}
@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();
private class OverseerRestarter implements Runnable{