public class NodeImpl extends Object implements Node, RaftServerService
Describer.DefaultPrinter, Describer.Printer| 限定符和类型 | 字段和说明 |
|---|---|
static AtomicInteger |
GLOBAL_NUM_NODES |
protected Lock |
readLock |
static RaftTimerFactory |
TIMER_FACTORY |
protected Lock |
writeLock |
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
boolean |
bootstrap(BootstrapOptions opts) |
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.
|
void |
describe(Describer.Printer out) |
Configuration |
getCurrentConf()
Retrieve current configuration this node seen so far.
|
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()
Returns the node metrics.
|
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.
|
RaftClientService |
getRpcService() |
PeerId |
getServerId() |
JRaftServiceFactory |
getServiceFactory()
Returns the JRaft service factory for current node.
|
Scheduler |
getTimerManager() |
com.google.protobuf.Message |
handleAppendEntriesRequest(RpcRequests.AppendEntriesRequest request,
RpcRequestClosure done)
Handle append-entries request, return response message or
called done.run() with response.
|
com.google.protobuf.Message |
handleInstallSnapshot(RpcRequests.InstallSnapshotRequest request,
RpcRequestClosure done)
Handle install-snapshot request, return response message or
called done.run() with response.
|
com.google.protobuf.Message |
handlePreVoteRequest(RpcRequests.RequestVoteRequest request)
Handle pre-vote request.
|
void |
handlePreVoteResponse(PeerId peerId,
long term,
RpcRequests.RequestVoteResponse response) |
void |
handleReadIndexRequest(RpcRequests.ReadIndexRequest request,
RpcResponseClosure<RpcRequests.ReadIndexResponse> done)
Handle read index request.
|
com.google.protobuf.Message |
handleRequestVoteRequest(RpcRequests.RequestVoteRequest request)
Handle request-vote request.
|
void |
handleRequestVoteResponse(PeerId peerId,
long term,
RpcRequests.RequestVoteResponse response) |
com.google.protobuf.Message |
handleTimeoutNowRequest(RpcRequests.TimeoutNowRequest request,
RpcRequestClosure done)
Handle time-out-now request, return response message or
called done.run() with response.
|
boolean |
init(NodeOptions opts)
Initialize the service.
|
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.
|
void |
onConfigurationChangeDone(long term) |
void |
onError(RaftException error) |
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()
Dispose the resources for service.
|
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.
|
String |
toString() |
Status |
transferLeadershipTo(PeerId peer)
Try transferring leadership to |peer|.
|
void |
updateConfigurationAfterInstallingSnapshot() |
public static final RaftTimerFactory TIMER_FACTORY
public static final AtomicInteger GLOBAL_NUM_NODES
protected final Lock writeLock
protected final Lock readLock
public boolean bootstrap(BootstrapOptions opts) throws InterruptedException
public boolean init(NodeOptions opts)
Lifecycleinit 在接口中 Lifecycle<NodeOptions>public NodeMetrics getNodeMetrics()
getNodeMetrics 在接口中 Nodepublic JRaftServiceFactory getServiceFactory()
public void readIndex(byte[] requestContext,
ReadIndexClosure done)
Nodepublic void handleReadIndexRequest(RpcRequests.ReadIndexRequest request, RpcResponseClosure<RpcRequests.ReadIndexResponse> done)
handleReadIndexRequest 在接口中 RaftServerServicerequest - data of the readIndex readdone - callbackpublic void apply(Task task)
NodeStateMachine.onApply(Iterator).
Otherwise we will specify the error and call it.public com.google.protobuf.Message handlePreVoteRequest(RpcRequests.RequestVoteRequest request)
RaftServerServicehandlePreVoteRequest 在接口中 RaftServerServicerequest - data of the pre votepublic com.google.protobuf.Message handleRequestVoteRequest(RpcRequests.RequestVoteRequest request)
RaftServerServicehandleRequestVoteRequest 在接口中 RaftServerServicerequest - data of the votepublic com.google.protobuf.Message handleAppendEntriesRequest(RpcRequests.AppendEntriesRequest request, RpcRequestClosure done)
RaftServerServicehandleAppendEntriesRequest 在接口中 RaftServerServicerequest - data of the entries to appenddone - callbackpublic NodeOptions getOptions()
NodegetOptions 在接口中 Nodepublic Scheduler getTimerManager()
public RaftOptions getRaftOptions()
NodegetRaftOptions 在接口中 Nodepublic void shutdown()
Lifecycleshutdown 在接口中 Lifecycle<NodeOptions>public void onConfigurationChangeDone(long term)
public PeerId getLeaderId()
NodegetLeaderId 在接口中 Nodepublic String getGroupId()
NodegetGroupId 在接口中 Nodepublic PeerId getServerId()
public RaftClientService getRpcService()
public void onError(RaftException error)
public void handleRequestVoteResponse(PeerId peerId, long term, RpcRequests.RequestVoteResponse response)
public void handlePreVoteResponse(PeerId peerId, long term, RpcRequests.RequestVoteResponse response)
public boolean isLeader()
Nodepublic boolean isLeader(boolean blocking)
Nodepublic void join()
throws InterruptedException
Nodejoin 在接口中 NodeInterruptedException - if the current thread is interrupted
while waitingpublic Configuration getCurrentConf()
listPeers() instead.public List<PeerId> listPeers()
NodeNode.addPeer(PeerId, Closure)/Node.removePeer(PeerId, Closure),
maybe return peers is staled. Because Node.addPeer(PeerId, Closure)/Node.removePeer(PeerId, Closure)
immediately modify configuration in memorypublic List<PeerId> listAlivePeers()
NodelistAlivePeers 在接口中 Nodepublic List<PeerId> listLearners()
NodeNode.addLearners(List, Closure)/Node.removeLearners(List, Closure)/Node.resetLearners(List, Closure),
maybe return peers is staled. Because Node.addLearners(List, Closure)/Node.removeLearners(List, Closure)/Node.resetLearners(List, Closure)
immediately modify configuration in memorylistLearners 在接口中 Nodepublic List<PeerId> listAliveLearners()
NodeNode.addLearners(List, Closure)/Node.removeLearners(List, Closure)/Node.resetLearners(List, Closure),
maybe return peers is staled. Because Node.addLearners(List, Closure)/Node.removeLearners(List, Closure)/Node.resetLearners(List, Closure)
immediately modify configuration in memorylistAliveLearners 在接口中 Nodepublic void addPeer(PeerId peer, Closure done)
Nodepublic void removePeer(PeerId peer, Closure done)
NoderemovePeer 在接口中 Nodepeer - peer to removedone - callbackpublic void changePeers(Configuration newPeers, Closure done)
NodechangePeers 在接口中 NodenewPeers - new peers to changedone - callbackpublic Status resetPeers(Configuration newPeers)
NoderesetPeers 在接口中 NodenewPeers - new peerspublic void addLearners(List<PeerId> learners, Closure done)
NodeaddLearners 在接口中 Nodelearners - learners to adddone - callbackpublic void removeLearners(List<PeerId> learners, Closure done)
NoderemoveLearners 在接口中 Nodelearners - learners to removedone - callbackpublic void resetLearners(List<PeerId> learners, Closure done)
NoderesetLearners 在接口中 Nodelearners - learners to setdone - callbackpublic void snapshot(Closure done)
Nodepublic void resetElectionTimeoutMs(int electionTimeoutMs)
NoderesetElectionTimeoutMs 在接口中 NodeelectionTimeoutMs - the timeout millis of electionpublic Status transferLeadershipTo(PeerId peer)
NodetransferLeadershipTo 在接口中 Nodepeer - the target peer of new leaderpublic com.google.protobuf.Message handleTimeoutNowRequest(RpcRequests.TimeoutNowRequest request, RpcRequestClosure done)
RaftServerServicehandleTimeoutNowRequest 在接口中 RaftServerServicerequest - data of the timeout now requestdone - callbackpublic com.google.protobuf.Message handleInstallSnapshot(RpcRequests.InstallSnapshotRequest request, RpcRequestClosure done)
RaftServerServicehandleInstallSnapshot 在接口中 RaftServerServicerequest - data of the install snapshot requestdone - callbackpublic void updateConfigurationAfterInstallingSnapshot()
public UserLog readCommittedUserLog(long index)
NodereadCommittedUserLog 在接口中 Nodeindex - log indexpublic void addReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
NodeaddReplicatorStateListener 在接口中 NodereplicatorStateListener - added ReplicatorStateListener which is implemented by users.public void removeReplicatorStateListener(Replicator.ReplicatorStateListener replicatorStateListener)
NoderemoveReplicatorStateListener 在接口中 NodereplicatorStateListener - need to remove the ReplicatorStateListener which has been added by users.public void clearReplicatorStateListeners()
NodeclearReplicatorStateListeners 在接口中 Nodepublic List<Replicator.ReplicatorStateListener> getReplicatorStatueListeners()
NodegetReplicatorStatueListeners 在接口中 Nodepublic int getNodeTargetPriority()
NodegetNodeTargetPriority 在接口中 Nodepublic State getNodeState()
NodegetNodeState 在接口中 Nodepublic void describe(Describer.Printer out)
Copyright © 2021. All rights reserved.