public interface Node extends Lifecycle<NodeOptions>, Describer
Describer.DefaultPrinter, Describer.Printer| 限定符和类型 | 方法和说明 |
|---|---|
void |
addLearners(List<PeerId> learners,
Closure done)
Add some new learners to the raft group. done.run() will be invoked after this
operation finishes, describing the detailed result.
|
void |
addPeer(PeerId peer,
Closure done)
Add a new peer to the raft group. done.run() would be invoked after this
operation finishes, describing the detailed result.
|
void |
addReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
SOFAJRaft users can implement the ReplicatorStateListener interface by themselves.
|
void |
apply(Task task)
[Thread-safe and wait-free]
Apply task to the replicated-state-machine
About the ownership:
|task.data|: for the performance consideration, we will take away the
content.
|
void |
changePeers(Configuration newPeers,
Closure done)
Change the configuration of the raft group to |newPeers| , done.un()
would be invoked after this operation finishes, describing the detailed result.
|
void |
clearReplicatorStateListeners()
Remove all the ReplicatorStateListeners which have been added by users.
|
String |
getGroupId()
Get the raft group id.
|
PeerId |
getLeaderId()
Get the leader peer id for redirect, null if absent.
|
NodeId |
getNodeId()
Get current node id.
|
NodeMetrics |
getNodeMetrics()
Get the node metrics, only valid when node option
NodeOptions.isEnableMetrics() is true. |
State |
getNodeState()
Get the node's state.
|
int |
getNodeTargetPriority()
Get the node's target election priority value.
|
NodeOptions |
getOptions()
Get the node options.
|
RaftOptions |
getRaftOptions()
Get the raft options
|
List<Replicator.ReplicatorStateListener> |
getReplicatorStatueListeners()
Get the ReplicatorStateListeners which have been added by users.
|
boolean |
isLeader()
Returns true when the node is leader.
|
boolean |
isLeader(boolean blocking)
Returns true when the node is leader.
|
void |
join()
Block the thread until the node is successfully stopped.
|
List<PeerId> |
listAliveLearners()
List all alive learners of this raft group, only leader returns.
|
List<PeerId> |
listAlivePeers()
List all alive peers of this raft group, only leader returns.
|
List<PeerId> |
listLearners()
List all learners of this raft group, only leader returns.
|
List<PeerId> |
listPeers()
List peers of this raft group, only leader returns.
|
UserLog |
readCommittedUserLog(long index)
Read the first committed user log from the given index.
|
void |
readIndex(byte[] requestContext,
ReadIndexClosure done)
[Thread-safe and wait-free]
Starts a linearizable read-only query request with request context(optional,
such as request id etc.) and closure.
|
void |
removeLearners(List<PeerId> learners,
Closure done)
Remove some learners from the raft group. done.run() will be invoked after this
operation finishes, describing the detailed result.
|
void |
removePeer(PeerId peer,
Closure done)
Remove the peer from the raft group. done.run() would be invoked after
operation finishes, describing the detailed result.
|
void |
removeReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
End User can remove their implement the ReplicatorStateListener interface by themselves.
|
void |
resetElectionTimeoutMs(int electionTimeoutMs)
Reset the election_timeout for the every node.
|
void |
resetLearners(List<PeerId> learners,
Closure done)
Reset learners in the raft group. done.run() will be invoked after this
operation finishes, describing the detailed result.
|
Status |
resetPeers(Configuration newPeers)
Reset the configuration of this node individually, without any replication
to other peers before this node becomes the leader.
|
void |
shutdown(Closure done)
Shutdown local replica node.
|
void |
snapshot(Closure done)
Start a snapshot immediately if possible. done.run() would be invoked when
the snapshot finishes, describing the detailed result.
|
Status |
transferLeadershipTo(PeerId peer)
Try transferring leadership to |peer|.
|
PeerId getLeaderId()
NodeId getNodeId()
NodeMetrics getNodeMetrics()
NodeOptions.isEnableMetrics() is true.String getGroupId()
NodeOptions getOptions()
RaftOptions getRaftOptions()
boolean isLeader()
boolean isLeader(boolean blocking)
blocking - if true, will be blocked until the node finish it's state changevoid shutdown(Closure done)
done - callbackvoid join() throws InterruptedException
InterruptedException - if the current thread is interrupted
while waitingvoid apply(Task task)
StateMachine.onApply(Iterator).
Otherwise we will specify the error and call it.task - task to applyvoid readIndex(byte[] requestContext,
ReadIndexClosure done)
requestContext - the context of requestdone - callbackList<PeerId> listPeers()
addPeer(PeerId, Closure)/removePeer(PeerId, Closure),
maybe return peers is staled. Because addPeer(PeerId, Closure)/removePeer(PeerId, Closure)
immediately modify configuration in memoryList<PeerId> listAlivePeers()
List<PeerId> listLearners()
addLearners(List, Closure)/removeLearners(List, Closure)/resetLearners(List, Closure),
maybe return peers is staled. Because addLearners(List, Closure)/removeLearners(List, Closure)/resetLearners(List, Closure)
immediately modify configuration in memoryList<PeerId> listAliveLearners()
addLearners(List, Closure)/removeLearners(List, Closure)/resetLearners(List, Closure),
maybe return peers is staled. Because addLearners(List, Closure)/removeLearners(List, Closure)/resetLearners(List, Closure)
immediately modify configuration in memoryvoid addPeer(PeerId peer, Closure done)
peer - peer to adddone - callbackvoid removePeer(PeerId peer, Closure done)
peer - peer to removedone - callbackvoid changePeers(Configuration newPeers, Closure done)
newPeers - new peers to changedone - callbackStatus resetPeers(Configuration newPeers)
newPeers - new peersvoid addLearners(List<PeerId> learners, Closure done)
learners - learners to adddone - callbackvoid removeLearners(List<PeerId> learners, Closure done)
learners - learners to removedone - callbackvoid resetLearners(List<PeerId> learners, Closure done)
learners - learners to setdone - callbackvoid snapshot(Closure done)
done - callbackvoid resetElectionTimeoutMs(int electionTimeoutMs)
electionTimeoutMs - the timeout millis of electionStatus transferLeadershipTo(PeerId peer)
peer - the target peer of new leaderUserLog readCommittedUserLog(long index)
index - log indexLogNotFoundException - the user log is deleted at index.LogIndexOutOfBoundsException - the special index is out of bounds.void addReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
replicatorStateListener - added ReplicatorStateListener which is implemented by users.void removeReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
replicatorStateListener - need to remove the ReplicatorStateListener which has been added by users.void clearReplicatorStateListeners()
List<Replicator.ReplicatorStateListener> getReplicatorStatueListeners()
int getNodeTargetPriority()
State getNodeState()
Copyright © 2021. All rights reserved.