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.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.compact()Compacts server logs.flushLog()Ensures that all records written to the log are flushed to diskReturns the current Raft context.getRole()Returns the server role.longgetTerm()Returns the server's term.Transitions the server to INACTIVE without shutting down or leaving the cluster.booleanReturns a boolean indicating whether the server is running.name()Returns the server name.promote()Promotes the server to leader if possible.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
-
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.
-
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
-
compact
Description copied from interface:RaftServerCompacts server logs.- Specified by:
compactin interfaceRaftServer- Returns:
- a future to be completed once the server's logs have been compacted
-
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.
-
goInactive
Description copied from interface:RaftServerTransitions the server to INACTIVE without shutting down or leaving the cluster.- Specified by:
goInactivein interfaceRaftServer- Returns:
- A completable future to be completed once the server is inactive.
-
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
-