Class RaftClusterContext
- All Implemented Interfaces:
RaftCluster,AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbootstrap(Collection<MemberId> cluster) Bootstraps the cluster.voidclose()commit()Commit the current configuration to disk.configure(Configuration configuration) Configures the cluster state.Returns a list of active members.getActiveMemberStates(Comparator<RaftMemberContext> comparator) Returns a list of active members.Returns the cluster configuration.Returns the parent context.Returns the current cluster leader.Returns the local cluster member.Returns a member by ID.Returns a collection of all cluster members.Returns a member state by ID.intReturns the remote quorum count.Returns a member by ID.Returns a list of all member states.Returns a list of member states for the given type.longgetTerm()Returns the current cluster term.reset()Resets the cluster state to the persisted state.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.atomix.raft.cluster.RaftCluster
bootstrap
-
Constructor Details
-
RaftClusterContext
-
-
Method Details
-
getMember
Description copied from interface:RaftClusterReturns a member by ID.The returned
RaftMemberis referenced by the uniqueRaftMember.memberId().- Specified by:
getMemberin interfaceRaftCluster- Parameters:
id- The member ID.- Returns:
- The member or
nullif no member with the givenidexists.
-
bootstrap
Description copied from interface:RaftClusterBootstraps the cluster.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 interfaceRaftCluster- Parameters:
cluster- The bootstrap cluster configuration.- Returns:
- A completable future to be completed once the cluster has been bootstrapped.
-
getLeader
Description copied from interface:RaftClusterReturns the current cluster leader.If no leader has been elected for the current
term, the leader will benull. Once a leader is elected, the leader must be known to the local server's configuration. If the returnedRaftMemberisnullthen that does not necessarily indicate that no leader yet exists for the current term, only that the local server has not learned of a valid leader for the term.- Specified by:
getLeaderin interfaceRaftCluster- Returns:
- The current cluster leader or
nullif no leader is known for the current term.
-
getLocalMember
Description copied from interface:RaftClusterReturns the local cluster member.- Specified by:
getLocalMemberin interfaceRaftCluster- Returns:
- The local cluster member.
-
getMembers
Description copied from interface:RaftClusterReturns a collection of all cluster members.The returned members are representative of the last configuration known to the local server. Over time, the cluster configuration may change. In the event of a membership change, the returned
Collectionwill not be modified, but instead a new collection will be created. Similarly, modifying the returned collection will have no impact on the cluster membership.- Specified by:
getMembersin interfaceRaftCluster- Returns:
- A collection of all cluster members.
-
getTerm
public long getTerm()Description copied from interface:RaftClusterReturns the current cluster term.The term is representative of the epoch determined by the underlying Raft consensus algorithm. The term is a monotonically increasing number used by Raft to represent a point in logical time. The term is guaranteed to be unique and monotonically increasing even across cluster restarts. Additionally, for any given term, Raft guarantees that only a single
leadercan be elected.- Specified by:
getTermin interfaceRaftCluster- Returns:
- The current cluster term.
-
getRemoteMember
Returns a member by ID.- Parameters:
id- The member ID.- Returns:
- The member.
-
getMemberState
Returns a member state by ID.- Parameters:
id- The member ID.- Returns:
- The member state.
-
getActiveMemberStates
Returns a list of active members.- Parameters:
comparator- A comparator with which to sort the members list.- Returns:
- The sorted members list.
-
getActiveMemberStates
Returns a list of active members.- Returns:
- A list of active members.
-
getRemoteMemberStates
Returns a list of member states for the given type.- Parameters:
type- The member type.- Returns:
- A list of member states for the given type.
-
reset
Resets the cluster state to the persisted state.- Returns:
- The cluster state.
-
configure
Configures the cluster state.- Parameters:
configuration- The cluster configuration.- Returns:
- The cluster state.
-
commit
Commit the current configuration to disk.- Returns:
- The cluster state.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
getConfiguration
Returns the cluster configuration.- Returns:
- The cluster configuration.
-
getContext
Returns the parent context.- Returns:
- The parent context.
-
getQuorum
public int getQuorum()Returns the remote quorum count.- Returns:
- The remote quorum count.
-
getRemoteMemberStates
Returns a list of all member states.- Returns:
- A list of all member states.
-