Class ClusterMember
-
Constructor Summary
ConstructorsConstructorDescriptionClusterMember(int id, String ingressEndpoint, String consensusEndpoint, String logEndpoint, String catchupEndpoint, String archiveEndpoint, String endpoints) Construct a new member of the cluster.ClusterMember(int id, String ingressEndpoint, String consensusEndpoint, String logEndpoint, String catchupEndpoint, String archiveEndpoint, String archiveResponseEndpoint, String egressResponseEndpoint, String endpoints) Construct a new member of the cluster. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddClusterMemberIds(ClusterMember[] clusterMembers, Int2ObjectHashMap<ClusterMember> clusterMemberByIdMap) Populate map ofClusterMembers which can be looked up by id.static voidaddConsensusPublication(ClusterMember thisMember, ClusterMember otherMember, String channelTemplate, int streamId, boolean bindConsensusControl, Aeron aeron, ErrorHandler errorHandler) Add an exclusivePublicationfor communicating to a member on the consensus channel.static voidaddConsensusPublications(ClusterMember[] members, ClusterMember thisMember, String channelTemplate, int streamId, boolean bindConsensusControl, Aeron aeron, ErrorHandler errorHandler) Add the publications for sending consensus messages to the other members of the cluster.The address:port endpoint for this cluster member that the archive can be reached.The address:port endpoint for this cluster member to use on the archive to set up a response channel for control, replay and replication.static booleanareSameEndpoints(ClusterMember lhs, ClusterMember rhs) Are two cluster members using the same endpoints?static voidbecomeCandidate(ClusterMember[] members, long candidateTermId, int candidateMemberId) Become a candidate by voting for yourself and resetting the other votes toAeron.NULL_VALUE.longThe candidate term id used when voting.candidateTermId(long candidateTermId) The candidate term id used when voting.The address:port endpoint for this cluster member to which a stream is replayed for catchup to the leader.longThe correlation id for the replay when catching up to the leader.catchupReplayCorrelationId(long correlationId) The correlation id for the replay when catching up to the leader.longThe session id for the replay when catching up to the leader.catchupReplaySessionId(long replaySessionId) The session id for the replay when catching up to the leader.static voidcloseConsensusPublications(ErrorHandler errorHandler, ClusterMember[] clusterMembers) Close the publications associated with members of the cluster used for the consensus protocol.voidclosePublication(ErrorHandler errorHandler) Close consensus publication and null out reference.static intcompareLog(long lhsLogLeadershipTermId, long lhsLogPosition, long rhsLogLeadershipTermId, long rhsLogPosition) The result is positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.static intcompareLog(ClusterMember lhs, ClusterMember rhs) The result is positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.The address:port endpoint for this cluster member that other members connect to for achieving consensus.longCorrelation id assigned to the current action undertaken by the cluster member.correlationId(long correlationId) Correlation id assigned to the current action undertaken by the cluster member.static ClusterMemberdetermineMember(ClusterMember[] clusterMembers, int memberId, String memberEndpoints) Determine which member of a cluster this is and check endpoints.The address:port endpoint for the cluster member that will serve as the control address for the egress response channel that client can connect to.static StringencodeAsString(ClusterMember[] clusterMembers) Encode member endpoints from a cluster members array to a String.static StringencodeAsString(List<ClusterMember> clusterMembers) Encode member endpoints from a cluster membersListto a String.The string of endpoints for this member in a comma separated list in the same order they are parsed.static ClusterMemberfindMember(ClusterMember[] clusterMembers, int memberId) Find aClusterMemberwith a given id.static booleanhasActiveQuorum(ClusterMember[] clusterMembers, long nowNs, long timeoutNs) Check if the cluster leader has an active quorum of cluster followers.static booleanhasQuorumAtPosition(ClusterMember[] clusterMembers, long leadershipTermId, long position, long nowNs, long timeoutNs) Has a quorum of members of appended a position to their local log.booleanHas this member notified that it has terminated?hasTerminated(boolean hasTerminated) Set if this member has terminated.intid()Unique identity for this member in the cluster.id(int id) Set the unique id for this member of the cluster.The address:port endpoint for this cluster member that clients send ingress to.static StringingressEndpoints(ClusterMember[] members) Create a string of ingress endpoints by member id in formatid=endpoint,id=endpoint, ....booleanIs the ballot for the current election sent to this member?isBallotSent(boolean isBallotSent) Is the ballot for the current election sent to this member?booleanisLeader()Is this member currently the leader?isLeader(boolean isLeader) Set if this member should be leader.static booleanisQuorumCandidate(ClusterMember[] clusterMembers, ClusterMember candidate) Has the member achieved a quorum view to be a suitable candidate in an election.static booleanisQuorumLeader(ClusterMember[] clusterMembers, long candidateTermId) Is this member considered leader by a quorum of members by having positive votes being counted for a majority and no negative votes.static booleanisUnanimousCandidate(ClusterMember[] clusterMembers, ClusterMember candidate, int gracefulClosedLeaderId) Is the member considered a candidate by a unanimous view to be a suitable candidate in an election.static booleanisUnanimousLeader(ClusterMember[] clusterMembers, long candidateTermId, int gracefulClosedLeaderId) Is a member considered unanimously to be leader after voting.longThe leadership term reached for the cluster member.leadershipTermId(long leadershipTermId) The leadership term reached for the cluster member.The address:port endpoint for this cluster member that the log is replicated to.longThe log position this member has persisted.logPosition(long logPosition) The log position this member has persisted.static ClusterMember[]Parse the details for a cluster members from a string.static ClusterMemberparseEndpoints(int id, String endpoints) Parse a string containing the endpoints for a cluster node and passing toClusterMember(int, String, String, String, String, String, String).ThePublicationused for send status updates to the member.voidpublication(ExclusivePublication publication) Publicationused for send status updates to the member.static longquorumPosition(ClusterMember[] members, long[] rankedPositions, long nowNs, long timeoutNs) Calculate the position reached by a quorum of cluster members.static intquorumThreshold(int memberCount) The threshold of clusters members required to achieve quorum given a count of cluster members.voidreset()Reset the state of a cluster member, so it can be canvassed and reestablished.static voidreset(ClusterMember[] members) Reset the state of all cluster members.static voidsetIsLeader(ClusterMember[] clusterMembers, int leaderMemberId) Run through the list of cluster members and set the isLeader field based on the supplied leaderMemberId.longTime (in ns) of last received appendPosition.timeOfLastAppendPositionNs(long timeNs) Time (in ns) of last received appendPosition.toString()static voidtryAddPublication(ClusterMember member, int streamId, Aeron aeron, ErrorHandler errorHandler) Try and add an exclusivePublicationfor communicating to a member on the consensus channel.static voidvalidateMemberEndpoints(ClusterMember member, String memberEndpoints) Check the member with the memberEndpoints.vote()The status of the vote for this member in an election.Set the result of the vote for this member.
-
Constructor Details
-
ClusterMember
public ClusterMember(int id, String ingressEndpoint, String consensusEndpoint, String logEndpoint, String catchupEndpoint, String archiveEndpoint, String endpoints) Construct a new member of the cluster.- Parameters:
id- unique id for the member.ingressEndpoint- address and port endpoint to which cluster clients send ingress.consensusEndpoint- address and port endpoint to which other cluster members connect.logEndpoint- address and port endpoint to which the log is replicated.catchupEndpoint- address and port endpoint to which a stream is replayed for catchup to the leader.archiveEndpoint- address and port endpoint to which the archive control channel can be reached.endpoints- comma separated list of endpoints.
-
ClusterMember
public ClusterMember(int id, String ingressEndpoint, String consensusEndpoint, String logEndpoint, String catchupEndpoint, String archiveEndpoint, String archiveResponseEndpoint, String egressResponseEndpoint, String endpoints) Construct a new member of the cluster.- Parameters:
id- unique id for the member.ingressEndpoint- address and port endpoint to which cluster clients send ingress.consensusEndpoint- address and port endpoint to which other cluster members connect.logEndpoint- address and port endpoint to which the log is replicated.catchupEndpoint- address and port endpoint to which a stream is replayed for catchup to the leader.archiveEndpoint- address and port endpoint to which the archive control channel can be reached.archiveResponseEndpoint- address and port endpoint to which the archive control response channel can be reached.egressResponseEndpoint- address and port endpoint to which the egress response channel can be reached.endpoints- comma separated list of endpoints.
-
-
Method Details
-
reset
public void reset()Reset the state of a cluster member, so it can be canvassed and reestablished. -
isLeader
Set if this member should be leader.- Parameters:
isLeader- value.- Returns:
- this for a fluent API.
-
isLeader
public boolean isLeader()Is this member currently the leader?- Returns:
- true if this member is currently the leader otherwise false.
-
isBallotSent
Is the ballot for the current election sent to this member?- Parameters:
isBallotSent- is the ballot for the current election sent to this member?- Returns:
- this for a fluent API.
-
isBallotSent
public boolean isBallotSent()Is the ballot for the current election sent to this member?- Returns:
- true if the ballot has been sent for this member in the current election.
-
hasTerminated
Set if this member has terminated.- Parameters:
hasTerminated- in notification to the leader.- Returns:
- this for a fluent API.
-
hasTerminated
public boolean hasTerminated()Has this member notified that it has terminated?- Returns:
- has this member notified that it has terminated?
-
id
Set the unique id for this member of the cluster.- Parameters:
id- for this member of the cluster.- Returns:
- this for a fluent API.
-
id
public int id()Unique identity for this member in the cluster.- Returns:
- the unique identity for this member in the cluster.
-
vote
Set the result of the vote for this member.Boolean.TRUEmeans they voted for this member,Boolean.FALSEmeans they voted against this member, and null means no vote was received.- Parameters:
vote- for this member in the election.- Returns:
- this for a fluent API.
-
vote
The status of the vote for this member in an election.Boolean.TRUEmeans they voted for this member,Boolean.FALSEmeans they voted against this member, and null means no vote was received.- Returns:
- the status of the vote for this member in an election.
-
leadershipTermId
The leadership term reached for the cluster member.- Parameters:
leadershipTermId- leadership term reached for the cluster member.- Returns:
- this for a fluent API.
-
leadershipTermId
public long leadershipTermId()The leadership term reached for the cluster member.- Returns:
- The leadership term reached for the cluster member.
-
logPosition
The log position this member has persisted.- Parameters:
logPosition- this member has persisted.- Returns:
- this for a fluent API.
-
logPosition
public long logPosition()The log position this member has persisted.- Returns:
- the log position this member has persisted.
-
candidateTermId
The candidate term id used when voting.- Parameters:
candidateTermId- used when voting.- Returns:
- this for a fluent API.
-
candidateTermId
public long candidateTermId()The candidate term id used when voting.- Returns:
- the candidate term id used when voting.
-
catchupReplaySessionId
The session id for the replay when catching up to the leader.- Parameters:
replaySessionId- for the replay when catching up to the leader.- Returns:
- this for a fluent API.
-
catchupReplaySessionId
public long catchupReplaySessionId()The session id for the replay when catching up to the leader.- Returns:
- the session id for the replay when catching up to the leader.
-
catchupReplayCorrelationId
The correlation id for the replay when catching up to the leader.- Parameters:
correlationId- for the replay when catching up to the leader.- Returns:
- this for a fluent API.
-
catchupReplayCorrelationId
public long catchupReplayCorrelationId()The correlation id for the replay when catching up to the leader.- Returns:
- the correlation id for the replay when catching up to the leader.
-
correlationId
Correlation id assigned to the current action undertaken by the cluster member.- Parameters:
correlationId- assigned to the current action undertaken by the cluster member.- Returns:
- this for a fluent API.
-
correlationId
public long correlationId()Correlation id assigned to the current action undertaken by the cluster member.- Returns:
- correlation id assigned to the current action undertaken by the cluster member.
-
timeOfLastAppendPositionNs
Time (in ns) of last received appendPosition.- Parameters:
timeNs- of the last received appendPosition.- Returns:
- this for a fluent API.
-
timeOfLastAppendPositionNs
public long timeOfLastAppendPositionNs()Time (in ns) of last received appendPosition.- Returns:
- time (in ns) of last received appendPosition or
Aeron.NULL_VALUEif none received.
-
consensusEndpoint
The address:port endpoint for this cluster member that other members connect to for achieving consensus.- Returns:
- the address:port endpoint for this cluster member that other members will connect to for consensus.
-
ingressEndpoint
The address:port endpoint for this cluster member that clients send ingress to.- Returns:
- the address:port endpoint for this cluster member that listens for ingress.
-
logEndpoint
The address:port endpoint for this cluster member that the log is replicated to.- Returns:
- the address:port endpoint for this cluster member that the log is replicated to.
-
catchupEndpoint
The address:port endpoint for this cluster member to which a stream is replayed for catchup to the leader.It is recommended a port of 0 is used, so it is system allocated to avoid potential clashes.
- Returns:
- the address:port endpoint for this cluster member to which a stream is replayed for catchup to the leader.
-
archiveEndpoint
The address:port endpoint for this cluster member that the archive can be reached.- Returns:
- the address:port endpoint for this cluster member that the archive can be reached.
-
archiveResponseEndpoint
The address:port endpoint for this cluster member to use on the archive to set up a response channel for control, replay and replication.- Returns:
- the address:port endpoint for the archive response channel to be used by archive clients within the cluster.
-
egressResponseEndpoint
The address:port endpoint for the cluster member that will serve as the control address for the egress response channel that client can connect to.- Returns:
- the endpoint used for the egress response channel.
-
endpoints
The string of endpoints for this member in a comma separated list in the same order they are parsed.- Returns:
- list of endpoints for this member in a comma separated list.
- See Also:
-
publication
ThePublicationused for send status updates to the member.- Returns:
Publicationused for send status updates to the member.
-
publication
Publicationused for send status updates to the member.- Parameters:
publication- used for send status updates to the member.
-
closePublication
Close consensus publication and null out reference.- Parameters:
errorHandler- to capture errors during close.
-
parse
Parse the details for a cluster members from a string.member-id,ingress:port,consensus:port,log:port,catchup:port,archive:port|1,...- Parameters:
value- of the string to be parsed.- Returns:
- An array of cluster members.
-
parseEndpoints
Parse a string containing the endpoints for a cluster node and passing toClusterMember(int, String, String, String, String, String, String).- Parameters:
id- of the member node.endpoints- comma separated.- Returns:
- the
ClusterMemberwith the endpoints set.
-
encodeAsString
Encode member endpoints from a cluster members array to a String.- Parameters:
clusterMembers- to fill the details from.- Returns:
- String representation suitable for use with
parse(String).
-
encodeAsString
Encode member endpoints from a cluster membersListto a String.- Parameters:
clusterMembers- to fill the details from.- Returns:
- String representation suitable for use with
parse(String).
-
addConsensusPublications
public static void addConsensusPublications(ClusterMember[] members, ClusterMember thisMember, String channelTemplate, int streamId, boolean bindConsensusControl, Aeron aeron, ErrorHandler errorHandler) Add the publications for sending consensus messages to the other members of the cluster.- Parameters:
members- of the cluster.thisMember- this member when adding publications.channelTemplate- for the publications.streamId- for the publications.bindConsensusControl- if the control endpoint should be bound for the publication.aeron- to add the publications to.errorHandler- to log registration exceptions to.
-
addConsensusPublication
public static void addConsensusPublication(ClusterMember thisMember, ClusterMember otherMember, String channelTemplate, int streamId, boolean bindConsensusControl, Aeron aeron, ErrorHandler errorHandler) Add an exclusivePublicationfor communicating to a member on the consensus channel.- Parameters:
thisMember- from which the publication is addressed.otherMember- to which the publication is addressed.channelTemplate- for the target member.streamId- for the target member.bindConsensusControl- if the control endpoint should be bound for the publication.aeron- from which the publication will be created.errorHandler- to log registration exceptions to.
-
tryAddPublication
public static void tryAddPublication(ClusterMember member, int streamId, Aeron aeron, ErrorHandler errorHandler) Try and add an exclusivePublicationfor communicating to a member on the consensus channel.- Parameters:
member- to which the publication is added.streamId- for the target member.aeron- from which the publication will be created.errorHandler- to log registration exceptions to.
-
closeConsensusPublications
public static void closeConsensusPublications(ErrorHandler errorHandler, ClusterMember[] clusterMembers) Close the publications associated with members of the cluster used for the consensus protocol.- Parameters:
errorHandler- to capture errors during close.clusterMembers- to close the publications for.
-
addClusterMemberIds
public static void addClusterMemberIds(ClusterMember[] clusterMembers, Int2ObjectHashMap<ClusterMember> clusterMemberByIdMap) Populate map ofClusterMembers which can be looked up by id.- Parameters:
clusterMembers- to populate the map.clusterMemberByIdMap- to be populated.
-
hasActiveQuorum
Check if the cluster leader has an active quorum of cluster followers.- Parameters:
clusterMembers- for the current cluster.nowNs- for the current time.timeoutNs- after which a member is not considered active.- Returns:
- true if quorum of cluster members are considered active.
-
quorumThreshold
public static int quorumThreshold(int memberCount) The threshold of clusters members required to achieve quorum given a count of cluster members.- Parameters:
memberCount- for the cluster- Returns:
- the threshold for achieving quorum.
-
quorumPosition
public static long quorumPosition(ClusterMember[] members, long[] rankedPositions, long nowNs, long timeoutNs) Calculate the position reached by a quorum of cluster members.- Parameters:
members- of the cluster.rankedPositions- temp array to be used for sorting the positions to avoid allocation.nowNs- for the current time.timeoutNs- after which a member is not considered active.- Returns:
- the position reached by a quorum of active cluster members.
-
hasQuorumAtPosition
public static boolean hasQuorumAtPosition(ClusterMember[] clusterMembers, long leadershipTermId, long position, long nowNs, long timeoutNs) Has a quorum of members of appended a position to their local log.- Parameters:
clusterMembers- to check.leadershipTermId- expected of the members.position- to compare thelogPosition()against.nowNs- for the current time.timeoutNs- after which a member is not considered active.- Returns:
trueif a quorum of members reached this position otherwisefalse.
-
reset
Reset the state of all cluster members.- Parameters:
members- to reset.
-
becomeCandidate
public static void becomeCandidate(ClusterMember[] members, long candidateTermId, int candidateMemberId) Become a candidate by voting for yourself and resetting the other votes toAeron.NULL_VALUE.- Parameters:
members- to reset the votes for.candidateTermId- for the candidacy.candidateMemberId- for the election.
-
isUnanimousLeader
public static boolean isUnanimousLeader(ClusterMember[] clusterMembers, long candidateTermId, int gracefulClosedLeaderId) Is a member considered unanimously to be leader after voting.If a leader has been gracefully closed then it is not included in the membership for considering a unanimous position but will be considered in the membership for quorum.
Note: all members are considered (i.e. no
isActive(long, long)check), because this method is called duringElectionState.CANDIDATE_BALLOTphase before append position is notified from the followers.- Parameters:
clusterMembers- to check for votes.candidateTermId- for the vote.gracefulClosedLeaderId- id of a leader if gracefully closed otherwiseAeron.NULL_VALUE.- Returns:
trueif all members voted positively.
-
isQuorumLeader
Is this member considered leader by a quorum of members by having positive votes being counted for a majority and no negative votes.Note: all members are considered (i.e. no
isActive(long, long)check), because this method is called duringElectionState.CANDIDATE_BALLOTphase before append position is notified from the followers.- Parameters:
clusterMembers- to check for votes.candidateTermId- for the vote.- Returns:
trueif sufficient positive votes being counted for a majority and no negative votes.
-
determineMember
public static ClusterMember determineMember(ClusterMember[] clusterMembers, int memberId, String memberEndpoints) Determine which member of a cluster this is and check endpoints.- Parameters:
clusterMembers- for the current cluster which can be null.memberId- for this member.memberEndpoints- for this member.- Returns:
- the
ClusterMemberdetermined.
-
validateMemberEndpoints
Check the member with the memberEndpoints.- Parameters:
member- to check memberEndpoints against.memberEndpoints- to check member against.- See Also:
-
areSameEndpoints
Are two cluster members using the same endpoints?- Parameters:
lhs- to compare for equality.rhs- to compare for equality.- Returns:
- true if both are using the same endpoints or false if not.
-
isUnanimousCandidate
public static boolean isUnanimousCandidate(ClusterMember[] clusterMembers, ClusterMember candidate, int gracefulClosedLeaderId) Is the member considered a candidate by a unanimous view to be a suitable candidate in an election.If a leader has been gracefully closed then it is not included in the membership for considering a unanimous position but will be considered in the membership for quorum.
- Parameters:
clusterMembers- to compare the candidate against.candidate- for leadership.gracefulClosedLeaderId- id of a leader if gracefully closed otherwiseAeron.NULL_VALUE.- Returns:
- true if the candidate is suitable otherwise false.
-
isQuorumCandidate
Has the member achieved a quorum view to be a suitable candidate in an election.- Parameters:
clusterMembers- to compare the candidate against.candidate- for leadership.- Returns:
- true if the candidate is suitable otherwise false.
-
compareLog
public static int compareLog(long lhsLogLeadershipTermId, long lhsLogPosition, long rhsLogLeadershipTermId, long rhsLogPosition) The result is positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.- Parameters:
lhsLogLeadershipTermId- term for which the position is most recent.lhsLogPosition- reached in the provided term.rhsLogLeadershipTermId- term for which the position is most recent.rhsLogPosition- reached in the provided term.- Returns:
- positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.
-
compareLog
The result is positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.- Parameters:
lhs- member to compare.rhs- member to compare.- Returns:
- positive if lhs has the more recent log, zero if logs are equal, and negative if rhs has the more recent log.
-
findMember
Find aClusterMemberwith a given id.- Parameters:
clusterMembers- to search.memberId- to search for.- Returns:
- the
ClusterMemberif found otherwise null.
-
ingressEndpoints
Create a string of ingress endpoints by member id in formatid=endpoint,id=endpoint, ....- Parameters:
members- for which the ingress endpoints string will be generated.- Returns:
- a string of ingress endpoints by id.
-
setIsLeader
Run through the list of cluster members and set the isLeader field based on the supplied leaderMemberId.- Parameters:
clusterMembers- list of cluster members.leaderMemberId- memberId of the current leader.
-
toString
-