org.apache.zookeeper.server.quorum
Class Leader

java.lang.Object
  extended by org.apache.zookeeper.server.quorum.Leader

public class Leader
extends Object

This class has the control logic for the Leader.


Nested Class Summary
static class Leader.Proposal
           
 
Field Summary
static int ACKEPOCH
          This message is used by the follow to ack a proposed epoch.
 HashSet<LearnerHandler> forwardingFollowers
           
static int LEADERINFO
          This message is the first that a follower receives from the leader.
 HashSet<LearnerHandler> learners
           
protected  HashSet<LearnerHandler> observingLearners
           
 HashMap<Long,List<LearnerSyncRequest>> pendingSyncs
           
static int PROPOSAL
          This message type is sent by a leader to propose a mutation.
 
Method Summary
 void commit(long zxid)
          Create a commit packet and send it to all the members of the quorum
 long getEpoch()
          Returns the current epoch of the leader.
 long getEpochToPropose(long sid, long lastAcceptedEpoch)
           
 void inform(Leader.Proposal proposal)
          Create an inform packet and send it to all observers.
 void processAck(long sid, long zxid, SocketAddress followerAddr)
          Keep a count of acks that are received by the leader for a particular proposal
 void processSync(LearnerSyncRequest r)
          Process sync requests
 Leader.Proposal propose(Request request)
          create a proposal and send it out to all the members
 void sendSync(LearnerSyncRequest r)
          Sends a sync message to the appropriate server
 long startForwarding(LearnerHandler handler, long lastSeenZxid)
          lets the leader know that a follower is capable of following and is done syncing
 void waitForEpochAck(long id, StateSummary ss)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

learners

public final HashSet<LearnerHandler> learners

forwardingFollowers

public final HashSet<LearnerHandler> forwardingFollowers

observingLearners

protected final HashSet<LearnerHandler> observingLearners

pendingSyncs

public final HashMap<Long,List<LearnerSyncRequest>> pendingSyncs

LEADERINFO

public static final int LEADERINFO
This message is the first that a follower receives from the leader. It has the protocol version and the epoch of the leader.

See Also:
Constant Field Values

ACKEPOCH

public static final int ACKEPOCH
This message is used by the follow to ack a proposed epoch.

See Also:
Constant Field Values

PROPOSAL

public static final int PROPOSAL
This message type is sent by a leader to propose a mutation.

See Also:
Constant Field Values
Method Detail

processAck

public void processAck(long sid,
                       long zxid,
                       SocketAddress followerAddr)
Keep a count of acks that are received by the leader for a particular proposal

Parameters:
zxid - the zxid of the proposal sent out
followerAddr -

commit

public void commit(long zxid)
Create a commit packet and send it to all the members of the quorum

Parameters:
zxid -

inform

public void inform(Leader.Proposal proposal)
Create an inform packet and send it to all observers.

Parameters:
zxid -
proposal -

getEpoch

public long getEpoch()
Returns the current epoch of the leader.

Returns:

propose

public Leader.Proposal propose(Request request)
create a proposal and send it out to all the members

Parameters:
request -
Returns:
the proposal that is queued to send to all the members

processSync

public void processSync(LearnerSyncRequest r)
Process sync requests

Parameters:
r - the request

sendSync

public void sendSync(LearnerSyncRequest r)
Sends a sync message to the appropriate server

Parameters:
f -
r -

startForwarding

public long startForwarding(LearnerHandler handler,
                            long lastSeenZxid)
lets the leader know that a follower is capable of following and is done syncing

Parameters:
handler - handler of the follower
Returns:
last proposed zxid

getEpochToPropose

public long getEpochToPropose(long sid,
                              long lastAcceptedEpoch)
                       throws InterruptedException,
                              IOException
Throws:
InterruptedException
IOException

waitForEpochAck

public void waitForEpochAck(long id,
                            StateSummary ss)
                     throws IOException,
                            InterruptedException
Throws:
IOException
InterruptedException


Copyright © 2011 The Apache Software Foundation