Class RaftClusterContext
- All Implemented Interfaces:
RaftCluster,AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbootstrap(Collection<MemberId> cluster) Bootstraps the cluster.voidclose()voidCommit the current configuration to disk.voidconfigure(Configuration configuration) Configures the cluster state.Returns the local cluster member.Returns a member by ID.Returns the context for a given member.Returns a collection of all cluster members.<T extends Comparable<T>>
Optional<T> getQuorumFor(Function<RaftMemberContext, T> calculateMemberValue) Calculates the smallest value that is reported for a majority of this cluster, assuming that the local node always has the highest value.getVoteQuorum(Consumer<Boolean> callback) booleanbooleanbooleanjoin(Collection<MemberId> cluster) 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
-
toString
-
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.
-
join
- Specified by:
joinin interfaceRaftCluster
-
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.
-
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.
-
getMemberContext
Returns the context for a given member. -
getQuorumFor
public <T extends Comparable<T>> Optional<T> getQuorumFor(Function<RaftMemberContext, T> calculateMemberValue) Calculates the smallest value that is reported for a majority of this cluster, assuming that the local node always has the highest value.- Parameters:
calculateMemberValue- a function that calculates a value for a given member. Will be evaluated at least once for every remote member.- Returns:
- empty when no remote members are present, otherwise the smallest value that is reported by enough remote members to form a quorum with the local member.
-
isSingleMemberCluster
public boolean isSingleMemberCluster()- Returns:
- true if the cluster has no remote active members and only the local member is active.
-
getVotingMembers
- Returns:
- A list remote members which participate in voting, i.e. are active.
-
getReplicationTargets
- Returns:
- A list of remote members that a leader should replicate to.
-
isMember
- Returns:
- true if the given member is part of the cluster, false otherwise
-
inJointConsensus
public boolean inJointConsensus()- Returns:
- true if the current configuration is a join consensus configuration.
-
getConfiguration
-
getContext
-
getVoteQuorum
-
reset
Resets the cluster state to the persisted state.- Returns:
- The cluster state.
-
configure
Configures the cluster state.- Parameters:
configuration- The cluster configuration.
-
commitCurrentConfiguration
public void commitCurrentConfiguration()Commit the current configuration to disk. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-