You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Trym R. Møller" <tr...@sigmat.dk> on 2012/06/21 14:19:08 UTC
LeaderElection
Hi
Messing with behaviour when Solr looses its ZooKeeper connection I'm
trying to reproduce how a replica slice gets leader. I have made the
below unit test in the LeaderElectionTest class which fails.
I don't know if this simulates how Solr uses the LeaderElection class
but please comment on the scenario.
Thanks in advance.
Best regards Trym
@Test
public void testMemoryElection() throws Exception {
LeaderElector first = new LeaderElector(zkClient);
ZkNodeProps props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP,
"http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "1");
ElectionContext firstContext = new
ShardLeaderElectionContextBase(first,
"slice1", "collection2", "dummynode1", props, zkStateReader);
first.setup(firstContext);
first.joinElection(firstContext);
Thread.sleep(1000);
assertEquals("original leader was not registered",
"http://127.0.0.1/solr/1/", getLeaderUrl("collection2", "slice1"));
SolrZkClient zkClient2 = new SolrZkClient(server.getZkAddress(),
TIMEOUT);
LeaderElector second = new LeaderElector(zkClient2);
props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP,
"http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "2");
ElectionContext context = new ShardLeaderElectionContextBase(second,
"slice1", "collection2", "dummynode1", props, zkStateReader);
second.setup(context);
second.joinElection(context);
Thread.sleep(1000);
assertEquals("original leader should have stayed leader",
"http://127.0.0.1/solr/1/", getLeaderUrl(zkClient2, "collection2",
"slice1"));
server.expire(zkClient.getSolrZooKeeper().getSessionId());
assertEquals("new leader was not registered",
"http://127.0.0.1/solr/2/", getLeaderUrl(zkClient2, "collection2",
"slice1"));
}