Class DefaultRaftServer
- All Implemented Interfaces:
RaftServer
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault Raft server builder.Nested classes/interfaces inherited from interface io.atomix.raft.RaftServer
RaftServer.CancelledBootstrapException, RaftServer.Role -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFailureListener(FailureListener listener) Adds a failure listenervoidaddRoleChangeListener(RaftRoleChangeListener listener) Adds a role change listener.bootstrap(Collection<MemberId> cluster) Bootstraps the cluster using the provided cluster configuration.cluster()Returns the server's cluster configuration.flushLog()Ensures that all records written to the log are flushed to diskforceConfigure(Map<MemberId, RaftMember.Type> membersToRetain) Force configure the partition to remove all members which are not part of the given membersToRetain.Returns the current Raft context.getRole()Returns the server role.longgetTerm()Returns the server's term.booleanReturns a boolean indicating whether the server is running.join(Collection<MemberId> cluster) Starts this raft server by joining an existing replication group.leave()Requests to leave the replication group by sending aLeaveRequestto an arbitrary member of the cluster, as provided by theClusterMembershipService.name()Returns the server name.promote()Promotes the server to leader if possible.reconfigurePriority(int newPriority) Update priority of this server used for priority election.voidremoveFailureListener(FailureListener listener) Removes a failure listenervoidRemoves a role change listener.shutdown()Shuts down the server without leaving the Raft cluster.stepDown()Steps down from the current leadership, which means tries to transition directly to follower.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.atomix.raft.RaftServer
bootstrap, bootstrap, isFollower, isLeader, join
-
Field Details
-
context
-
-
Constructor Details
-
DefaultRaftServer
-
-
Method Details
-
toString
-
name
Description copied from interface:RaftServerReturns the server name.The server name is provided to the server via the
builder configuration. The name is used internally to manage the server's on-disk state.Log,snapshot, andconfigurationfiles stored on disk use the server name as the prefix.- Specified by:
namein interfaceRaftServer- Returns:
- The server name.
-
cluster
Description copied from interface:RaftServerReturns the server's cluster configuration.The
RaftClusteris representative of the server's current view of the cluster configuration. The first time the server isstarted, the cluster configuration will be initialized using theMemberIdlist provided to the serverbuilder- Specified by:
clusterin interfaceRaftServer- Returns:
- The server's cluster configuration.
-
addRoleChangeListener
Description copied from interface:RaftServerAdds a role change listener.- Specified by:
addRoleChangeListenerin interfaceRaftServer- Parameters:
listener- The role change listener that consumes the role and the raft term.
-
removeRoleChangeListener
Description copied from interface:RaftServerRemoves a role change listener.- Specified by:
removeRoleChangeListenerin interfaceRaftServer- Parameters:
listener- The role change listener to remove.
-
addFailureListener
Description copied from interface:RaftServerAdds a failure listener- Specified by:
addFailureListenerin interfaceRaftServer
-
removeFailureListener
Description copied from interface:RaftServerRemoves a failure listener- Specified by:
removeFailureListenerin interfaceRaftServer
-
bootstrap
Description copied from interface:RaftServerBootstraps the cluster using the provided cluster configuration.Bootstrapping the cluster results in a new cluster being formed with the provided configuration. The initial nodes in a cluster must always be bootstrapped. This is necessary to prevent split brain. If the provided configuration is empty, the local server will form a single-node cluster.
Only
RaftMember.Type.ACTIVEmembers can be included in a bootstrap configuration. If the local server is not initialized as an active member, it cannot be part of the bootstrap configuration for the cluster.When the cluster is bootstrapped, the local server will be transitioned into the active state and begin participating in the Raft consensus algorithm. When the cluster is first bootstrapped, no leader will exist. The bootstrapped members will elect a leader amongst themselves.
It is critical that all servers in a bootstrap configuration be started with the same exact set of members. Bootstrapping multiple servers with different configurations may result in split brain.
The
CompletableFuturereturned by this method will be completed once the cluster has been bootstrapped, a leader has been elected, and the leader has been notified of the local server's client configurations.- Specified by:
bootstrapin interfaceRaftServer- Parameters:
cluster- The bootstrap cluster configuration.- Returns:
- A completable future to be completed once the cluster has been bootstrapped.
-
join
Description copied from interface:RaftServerStarts this raft server by joining an existing replication group. AJoinRequestis sent to an arbitrary member of the cluster.- Specified by:
joinin interfaceRaftServer- Parameters:
cluster- a list of member ids that are part of the cluster and assist in joining.- Returns:
- A completable future to be completed once the server has joined the cluster.
-
leave
Description copied from interface:RaftServerRequests to leave the replication group by sending aLeaveRequestto an arbitrary member of the cluster, as provided by theClusterMembershipService.- Specified by:
leavein interfaceRaftServer- Returns:
- A future to be completed successfully once the server has left the cluster.
-
promote
Description copied from interface:RaftServerPromotes the server to leader if possible.- Specified by:
promotein interfaceRaftServer- Returns:
- a future to be completed once the server has been promoted
-
forceConfigure
Description copied from interface:RaftServerForce configure the partition to remove all members which are not part of the given membersToRetain.This method is typically called to remove a set of unreachable members when there is no leader.
- Specified by:
forceConfigurein interfaceRaftServer- Parameters:
membersToRetain- The members to retain in the partition- Returns:
- a future to be completed once the server has been force configured
-
reconfigurePriority
Description copied from interface:RaftServerUpdate priority of this server used for priority election. If priority election is not enabled, this method has no effect. To get the desired result, priority of all replicas must be updated accordingly. This method only updates the local server's priority.- Specified by:
reconfigurePriorityin interfaceRaftServer- Parameters:
newPriority- the priority to be set- Returns:
- a future to be completed when the new priority is applied
-
flushLog
Description copied from interface:RaftServerEnsures that all records written to the log are flushed to disk- Specified by:
flushLogin interfaceRaftServer- Returns:
- a future which will be completed after the log is flushed to disk
-
shutdown
Shuts down the server without leaving the Raft cluster.- Specified by:
shutdownin interfaceRaftServer- Returns:
- A completable future to be completed once the server has been shutdown.
-
getContext
Description copied from interface:RaftServerReturns the current Raft context.- Specified by:
getContextin interfaceRaftServer- Returns:
- the current Raft context
-
getTerm
public long getTerm()Description copied from interface:RaftServerReturns the server's term.- Specified by:
getTermin interfaceRaftServer- Returns:
- the server's term
-
getRole
Description copied from interface:RaftServerReturns the server role.The initial state of a Raft server is
RaftServer.Role.INACTIVE. Once the server isstartedand until it is explicitly shutdown, the server will be in one of the active states -RaftServer.Role.PASSIVE,RaftServer.Role.FOLLOWER,RaftServer.Role.CANDIDATE, orRaftServer.Role.LEADER.- Specified by:
getRolein interfaceRaftServer- Returns:
- The server role.
-
isRunning
public boolean isRunning()Returns a boolean indicating whether the server is running.- Specified by:
isRunningin interfaceRaftServer- Returns:
- Indicates whether the server is running.
-
stepDown
Description copied from interface:RaftServerSteps down from the current leadership, which means tries to transition directly to follower.- Specified by:
stepDownin interfaceRaftServer
-