public class QuorumPeer extends java.lang.Thread implements QuorumStats.Provider
int xid; long myid; long leader_id; long leader_zxid;The request for the current leader will consist solely of an xid: int xid;
Modifier and Type | Class and Description |
---|---|
static interface |
QuorumPeer.Factory
Create an instance of a quorum peer
|
static class |
QuorumPeer.LearnerType |
static class |
QuorumPeer.QuorumServer |
static class |
QuorumPeer.ServerState |
Modifier and Type | Field and Description |
---|---|
Follower |
follower |
protected int |
initLimit
The number of ticks that the initial synchronization phase can take
|
Leader |
leader |
protected int |
maxSessionTimeout
Maximum number of milliseconds to allow for session timeout.
|
protected int |
minSessionTimeout
Minimum number of milliseconds to allow for session timeout.
|
Observer |
observer |
protected java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> |
quorumPeers
The servers that make up the cluster
|
protected int |
syncLimit
The number of ticks that can pass between sending a request and getting
an acknowledgment
|
protected int |
tick
The current tick
|
protected int |
tickTime
The number of milliseconds of each tick
|
FOLLOWING_STATE, LEADING_STATE, LOOKING_STATE, OBSERVING_STATE, UNKNOWN_STATE
Constructor and Description |
---|
QuorumPeer() |
QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers,
java.io.File snapDir,
java.io.File logDir,
int clientPort,
int electionAlg,
long myid,
int tickTime,
int initLimit,
int syncLimit)
This constructor is only used by the existing unit test code.
|
QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers,
java.io.File snapDir,
java.io.File logDir,
int clientPort,
int electionAlg,
long myid,
int tickTime,
int initLimit,
int syncLimit,
QuorumVerifier quorumConfig)
This constructor is only used by the existing unit test code.
|
QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers,
java.io.File dataDir,
java.io.File dataLogDir,
int electionType,
long myid,
int tickTime,
int initLimit,
int syncLimit,
NIOServerCnxn.Factory cnxnFactory)
For backward compatibility purposes, we instantiate QuorumMaj by default.
|
QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers,
java.io.File dataDir,
java.io.File dataLogDir,
int electionType,
long myid,
int tickTime,
int initLimit,
int syncLimit,
NIOServerCnxn.Factory cnxnFactory,
QuorumVerifier quorumConfig) |
Modifier and Type | Method and Description |
---|---|
protected static int |
countParticipants(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> peers)
Count the number of nodes in the map that could be followers.
|
protected Election |
createElectionAlgorithm(int electionAlgorithm) |
ZooKeeperServer |
getActiveServer() |
int |
getClientPort() |
NIOServerCnxn.Factory |
getCnxnFactory() |
Vote |
getCurrentVote() |
Election |
getElectionAlg()
Get an instance of LeaderElection
|
int |
getElectionType()
Gets the election type
|
long |
getId()
get the id of this quorum peer.
|
int |
getInitLimit()
Get the number of ticks that the initial synchronization phase can take
|
long |
getLastLoggedZxid()
returns the highest zxid that this host has seen
|
QuorumPeer.LearnerType |
getLearnerType() |
int |
getMaxSessionTimeout()
maximum session timeout in milliseconds
|
int |
getMinSessionTimeout()
minimum session timeout in milliseconds
|
long |
getMyid()
get the id of this quorum peer.
|
java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> |
getObservingView()
Returns only observers, no followers.
|
QuorumPeer.ServerState |
getPeerState() |
java.net.InetSocketAddress |
getQuorumAddress() |
QuorumCnxManager |
getQuorumCnxManager()
get reference to QuorumCnxManager
|
java.lang.String[] |
getQuorumPeers()
Only used by QuorumStats at the moment
|
int |
getQuorumSize() |
QuorumVerifier |
getQuorumVerifier()
Return QuorumVerifier object
|
java.lang.String |
getServerState() |
int |
getSyncLimit()
Get the synclimit
|
int |
getTick()
Get the current tick
|
int |
getTickTime()
Get the number of milliseconds of each tick
|
FileTxnSnapLog |
getTxnFactory() |
java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> |
getView()
A 'view' is a node's current opinion of the membership of the entire
ensemble.
|
java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> |
getVotingView()
Observers are not contained in this view, only nodes with
PeerType=PARTICIPANT.
|
boolean |
isRunning() |
protected Follower |
makeFollower(FileTxnSnapLog logFactory) |
protected Leader |
makeLeader(FileTxnSnapLog logFactory) |
protected Election |
makeLEStrategy() |
protected Observer |
makeObserver(FileTxnSnapLog logFactory) |
void |
run() |
void |
setClientPortAddress(java.net.InetSocketAddress addr) |
void |
setCnxnFactory(NIOServerCnxn.Factory cnxnFactory) |
void |
setCurrentVote(Vote v) |
void |
setElectionType(int electionType)
Sets the election type
|
protected void |
setFollower(Follower newFollower) |
void |
setInitLimit(int initLimit)
Set the number of ticks that the initial synchronization phase can take
|
protected void |
setLeader(Leader newLeader) |
void |
setLearnerType(QuorumPeer.LearnerType p)
Sets the LearnerType both in the QuorumPeer and in the peerMap
|
void |
setMaxSessionTimeout(int max)
minimum session timeout in milliseconds
|
void |
setMinSessionTimeout(int min)
minimum session timeout in milliseconds
|
void |
setMyid(long myid)
set the id of this quorum peer.
|
protected void |
setObserver(Observer newObserver) |
void |
setPeerState(QuorumPeer.ServerState newState) |
void |
setQuorumPeers(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers) |
void |
setQuorumVerifier(QuorumVerifier quorumConfig) |
void |
setRunning(boolean running) |
void |
setSyncLimit(int syncLimit)
Set the synclimit
|
void |
setTickTime(int tickTime)
Set the number of milliseconds of each tick
|
void |
setTxnFactory(FileTxnSnapLog factory) |
void |
setZKDatabase(ZKDatabase database)
set zk database for this node
|
void |
shutdown() |
void |
start() |
void |
startLeaderElection() |
void |
stopLeaderElection() |
boolean |
viewContains(java.lang.Long sid)
Check if a node is in the current view.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
protected java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers
protected int tickTime
protected int minSessionTimeout
protected int maxSessionTimeout
protected int initLimit
protected int syncLimit
protected int tick
public Follower follower
public Leader leader
public Observer observer
public QuorumPeer()
public QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers, java.io.File dataDir, java.io.File dataLogDir, int electionType, long myid, int tickTime, int initLimit, int syncLimit, NIOServerCnxn.Factory cnxnFactory) throws java.io.IOException
java.io.IOException
public QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers, java.io.File dataDir, java.io.File dataLogDir, int electionType, long myid, int tickTime, int initLimit, int syncLimit, NIOServerCnxn.Factory cnxnFactory, QuorumVerifier quorumConfig) throws java.io.IOException
java.io.IOException
public QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers, java.io.File snapDir, java.io.File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit) throws java.io.IOException
java.io.IOException
public QuorumPeer(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers, java.io.File snapDir, java.io.File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit, QuorumVerifier quorumConfig) throws java.io.IOException
java.io.IOException
public QuorumPeer.LearnerType getLearnerType()
public void setLearnerType(QuorumPeer.LearnerType p)
public int getQuorumSize()
public long getId()
getId
in class java.lang.Thread
public Vote getCurrentVote()
public void setCurrentVote(Vote v)
public void setPeerState(QuorumPeer.ServerState newState)
public QuorumPeer.ServerState getPeerState()
public java.net.InetSocketAddress getQuorumAddress()
public void start()
start
in class java.lang.Thread
public void stopLeaderElection()
public void startLeaderElection()
protected static int countParticipants(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> peers)
peers
- public long getLastLoggedZxid()
protected Follower makeFollower(FileTxnSnapLog logFactory) throws java.io.IOException
java.io.IOException
protected Leader makeLeader(FileTxnSnapLog logFactory) throws java.io.IOException
java.io.IOException
protected Observer makeObserver(FileTxnSnapLog logFactory) throws java.io.IOException
java.io.IOException
protected Election createElectionAlgorithm(int electionAlgorithm)
protected Election makeLEStrategy()
protected void setLeader(Leader newLeader)
protected void setFollower(Follower newFollower)
protected void setObserver(Observer newObserver)
public ZooKeeperServer getActiveServer()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void shutdown()
public java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> getView()
public java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> getVotingView()
public java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> getObservingView()
public boolean viewContains(java.lang.Long sid)
public java.lang.String[] getQuorumPeers()
getQuorumPeers
in interface QuorumStats.Provider
public java.lang.String getServerState()
getServerState
in interface QuorumStats.Provider
public long getMyid()
public void setMyid(long myid)
public int getTickTime()
public void setTickTime(int tickTime)
public int getMinSessionTimeout()
public void setMinSessionTimeout(int min)
public int getMaxSessionTimeout()
public void setMaxSessionTimeout(int max)
public int getInitLimit()
public void setInitLimit(int initLimit)
public int getTick()
public QuorumVerifier getQuorumVerifier()
public void setQuorumVerifier(QuorumVerifier quorumConfig)
public Election getElectionAlg()
public int getSyncLimit()
public void setSyncLimit(int syncLimit)
public int getElectionType()
public void setElectionType(int electionType)
public NIOServerCnxn.Factory getCnxnFactory()
public void setCnxnFactory(NIOServerCnxn.Factory cnxnFactory)
public void setQuorumPeers(java.util.Map<java.lang.Long,QuorumPeer.QuorumServer> quorumPeers)
public int getClientPort()
public void setClientPortAddress(java.net.InetSocketAddress addr)
public void setTxnFactory(FileTxnSnapLog factory)
public FileTxnSnapLog getTxnFactory()
public void setZKDatabase(ZKDatabase database)
database
- public void setRunning(boolean running)
public boolean isRunning()
public QuorumCnxManager getQuorumCnxManager()
Copyright © 2012 The Apache Software Foundation