public class LeaderElector extends Object
setup(ElectionContext) to ensure
the election process is init'd. Next call
joinElection(ElectionContext) to start the leader election.
The implementation follows the classic ZooKeeper recipe of creating an
ephemeral, sequential node for each candidate and then looking at the set
of such nodes - if the created node is the lowest sequential node, the
candidate that created the node is the leader. If not, the candidate puts
a watch on the next lowest node it finds, and if that node goes down,
starts the whole process over by checking if it's the lowest sequential node, etc.
TODO: now we could just reuse the lock package code for leader election| Modifier and Type | Field and Description |
|---|---|
protected SolrZkClient |
zkClient |
| Constructor and Description |
|---|
LeaderElector(SolrZkClient zkClient) |
| Modifier and Type | Method and Description |
|---|---|
int |
joinElection(ElectionContext context)
Begin participating in the election process.
|
protected void |
runIamLeaderProcess(ElectionContext context,
boolean weAreReplacement) |
void |
setup(ElectionContext context)
Set up any ZooKeeper nodes needed for leader election.
|
protected SolrZkClient zkClient
public LeaderElector(SolrZkClient zkClient)
protected void runIamLeaderProcess(ElectionContext context, boolean weAreReplacement) throws org.apache.zookeeper.KeeperException, InterruptedException, IOException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionIOExceptionpublic int joinElection(ElectionContext context) throws org.apache.zookeeper.KeeperException, InterruptedException, IOException
context - org.apache.zookeeper.KeeperExceptionInterruptedExceptionIOExceptionUnsupportedEncodingExceptionpublic void setup(ElectionContext context) throws InterruptedException, org.apache.zookeeper.KeeperException
context - InterruptedExceptionorg.apache.zookeeper.KeeperExceptionCopyright © 2000-2012 Apache Software Foundation. All Rights Reserved.