public final class ClusterMember extends Object
| Constructor and Description |
|---|
ClusterMember(int id,
String ingressEndpoint,
String consensusEndpoint,
String logEndpoint,
String catchupEndpoint,
String archiveEndpoint,
String endpoints)
Construct a new member of the cluster.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addClusterMemberIds(ClusterMember[] clusterMembers,
Int2ObjectHashMap<ClusterMember> clusterMemberByIdMap)
Populate map of
ClusterMembers which can be looked up by id. |
static void |
addConsensusPublication(ClusterMember member,
ChannelUri channelUri,
int streamId,
Aeron aeron)
Add an exclusive
Publication for communicating to a member on the consensus channel. |
static void |
addConsensusPublications(ClusterMember[] members,
ClusterMember exclude,
ChannelUri channelUri,
int streamId,
Aeron aeron)
Add the publications for sending status messages to the other members of the cluster.
|
static ClusterMember[] |
addMember(ClusterMember[] oldMembers,
ClusterMember newMember)
Add a new member to an array of
ClusterMembers. |
String |
archiveEndpoint()
The address:port endpoint for this cluster member that the archive can be reached.
|
static boolean |
areSameEndpoints(ClusterMember lhs,
ClusterMember rhs)
Are two cluster members using the same endpoints?
|
static void |
becomeCandidate(ClusterMember[] members,
long candidateTermId,
int candidateMemberId)
Become a candidate by voting for yourself and resetting the other votes to
Aeron.NULL_VALUE. |
long |
candidateTermId()
The candidate term id used when voting.
|
ClusterMember |
candidateTermId(long candidateTermId)
The candidate term id used when voting.
|
String |
catchupEndpoint()
The address:port endpoint for this cluster member to which a stream is replayed to for leader catchup.
|
long |
catchupReplayCorrelationId()
The correlation id for the replay when catching up to the leader.
|
ClusterMember |
catchupReplayCorrelationId(long correlationId)
The correlation id for the replay when catching up to the leader.
|
long |
catchupReplaySessionId()
The session id for the replay when catching up to the leader.
|
ClusterMember |
catchupReplaySessionId(long replaySessionId)
The session id for the replay when catching up to the leader.
|
static void |
closeConsensusPublications(ErrorHandler errorHandler,
ClusterMember[] clusterMembers)
Close the publications associated with members of the cluster used for the consensus protocol.
|
void |
closePublication(ErrorHandler errorHandler)
Close consensus publication and null out reference.
|
static int |
compareLog(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.
|
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.
|
String |
consensusEndpoint()
The address:port endpoint for this cluster member that other members connect to for achieving consensus.
|
static void |
copyVotes(ClusterMember[] srcMembers,
ClusterMember[] dstMembers)
Copy votes from one array of members to another where the
id()s match. |
long |
correlationId()
Correlation id assigned to the current action undertaken by the cluster member.
|
ClusterMember |
correlationId(long correlationId)
Correlation id assigned to the current action undertaken by the cluster member.
|
static ClusterMember |
determineMember(ClusterMember[] clusterMembers,
int memberId,
String memberEndpoints)
Determine which member of a cluster this is and check endpoints.
|
static String |
encodeAsString(ClusterMember[] clusterMembers)
Encode member endpoints from a cluster members array to a String.
|
static String |
encodeAsString(List<ClusterMember> clusterMembers)
Encode member endpoints from a cluster members
List to a String. |
String |
endpoints()
The string of endpoints for this member in a comma separated list in the same order they are parsed.
|
static ClusterMember |
findMember(ClusterMember[] clusterMembers,
int memberId)
Find a
ClusterMember with a given id. |
static int |
findMemberIndex(ClusterMember[] clusterMembers,
int memberId)
Find the index at which a member id is present.
|
static boolean |
hasActiveQuorum(ClusterMember[] clusterMembers,
long nowNs,
long timeoutNs)
Check if the cluster leader has an active quorum of cluster followers.
|
static boolean |
hasMajorityVote(ClusterMember[] clusterMembers,
long candidateTermId)
Has sufficient votes being counted for a majority?
|
static boolean |
hasMajorityVoteWithCanvassMembers(ClusterMember[] members,
long candidateTermId)
Has sufficient votes being counted for a majority for all members observed during
ElectionState.CANVASS? |
boolean |
hasRequestedJoin()
Has this member requested to join the cluster?
|
ClusterMember |
hasRequestedJoin(boolean hasRequestedJoin)
Set if this member requested to join the cluster.
|
boolean |
hasRequestedRemove()
Has this member requested to be removed from the cluster.
|
boolean |
hasTerminated()
Has this member notified that it has terminated?
|
ClusterMember |
hasTerminated(boolean hasTerminated)
Set if this member has terminated.
|
static boolean |
hasWonVoteOnFullCount(ClusterMember[] members,
long candidateTermId)
Has the candidate got unanimous support of the cluster?
|
static boolean |
haveVotersReachedPosition(ClusterMember[] clusterMembers,
long position,
long leadershipTermId)
Has the members of the cluster the voted reached the provided position in their log.
|
static int |
highMemberId(ClusterMember[] clusterMembers)
Find the highest member id in an array of members.
|
int |
id()
Unique identity for this member in the cluster.
|
ClusterMember |
id(int id)
Set the unique id for this member of the cluster.
|
String |
ingressEndpoint()
The address:port endpoint for this cluster member that clients send ingress to.
|
static String |
ingressEndpoints(ClusterMember[] members)
Create a string of ingress endpoints by member id in format
id=endpoint,id=endpoint, .... |
boolean |
isBallotSent()
Is the ballot for the current election sent to this member?
|
ClusterMember |
isBallotSent(boolean isBallotSent)
Is the ballot for the current election sent to this member?
|
boolean |
isLeader()
Is this member currently the leader?
|
ClusterMember |
isLeader(boolean isLeader)
Set if this member should be leader.
|
static boolean |
isQuorumCandidate(ClusterMember[] clusterMembers,
ClusterMember candidate)
Has the member achieved a quorum view to be a suitable candidate in an election.
|
static boolean |
isUnanimousCandidate(ClusterMember[] clusterMembers,
ClusterMember candidate)
Has the member achieved a unanimous view to be a suitable candidate in an election.
|
long |
leadershipTermId()
The leadership term reached for the cluster member.
|
ClusterMember |
leadershipTermId(long leadershipTermId)
The leadership term reached for the cluster member.
|
String |
logEndpoint()
The address:port endpoint for this cluster member that the log is replicated to.
|
long |
logPosition()
The log position this member has persisted.
|
ClusterMember |
logPosition(long logPosition)
The log position this member has persisted.
|
static boolean |
notDuplicateEndpoint(ClusterMember[] members,
String endpoints)
Is the string of member endpoints not duplicated in the members.
|
static ClusterMember[] |
parse(String value)
Parse the details for a cluster members from a string.
|
static ClusterMember |
parseEndpoints(int id,
String endpoints)
Parse a string containing the endpoints for a cluster node and passing to
ClusterMember(int, String, String, String, String, String, String). |
ExclusivePublication |
publication()
The
Publication used for send status updates to the member. |
void |
publication(ExclusivePublication publication)
Publication used for send status updates to the member. |
static long |
quorumPosition(ClusterMember[] members,
long[] rankedPositions)
Calculate the position reached by a quorum of cluster members.
|
static int |
quorumThreshold(int memberCount)
The threshold of clusters members required to achieve quorum given a count of cluster members.
|
long |
removalPosition()
The log position as of appending the event to be removed from the cluster.
|
ClusterMember |
removalPosition(long removalPosition)
Set the log position as of appending the event to be removed from the cluster.
|
static ClusterMember[] |
removeMember(ClusterMember[] oldMembers,
int memberId)
Remove a member from an array if found, otherwise return the array unmodified.
|
void |
reset()
Reset the state of a cluster member so it can be canvassed and reestablished.
|
static void |
reset(ClusterMember[] members)
Reset the state of all cluster members.
|
static void |
resetLogPositions(ClusterMember[] clusterMembers,
long logPosition)
Reset the log position of all the members to the provided value.
|
long |
timeOfLastAppendPositionNs()
Time (in ns) of last received appendPosition.
|
ClusterMember |
timeOfLastAppendPositionNs(long timeNs)
Time (in ns) of last received appendPosition.
|
String |
toString() |
static void |
validateMemberEndpoints(ClusterMember member,
String memberEndpoints)
Check the member with the memberEndpoints.
|
Boolean |
vote()
The status of the vote for this member in an election.
|
ClusterMember |
vote(Boolean vote)
Set the result of the vote for this member.
|
public ClusterMember(int id,
String ingressEndpoint,
String consensusEndpoint,
String logEndpoint,
String catchupEndpoint,
String archiveEndpoint,
String endpoints)
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 to catchup to the leader.archiveEndpoint - address and port endpoint to which the archive control channel can be reached.endpoints - comma separated list of endpoints.public void reset()
public ClusterMember isLeader(boolean isLeader)
isLeader - value.public boolean isLeader()
public ClusterMember isBallotSent(boolean isBallotSent)
isBallotSent - is the ballot for the current election sent to this member?public boolean isBallotSent()
public ClusterMember hasRequestedJoin(boolean hasRequestedJoin)
hasRequestedJoin - the cluster.public boolean hasRequestedJoin()
public ClusterMember hasTerminated(boolean hasTerminated)
hasTerminated - in notification to the leader.public boolean hasTerminated()
public ClusterMember removalPosition(long removalPosition)
removalPosition - as of appending the event to be removed from the cluster.public long removalPosition()
AeronArchive.NULL_POSITION if not requested remove.public boolean hasRequestedRemove()
public ClusterMember id(int id)
id - for this member of the cluster.public int id()
public ClusterMember vote(Boolean vote)
Boolean.TRUE means they voted for this member,
Boolean.FALSE means they voted against this member, and null means no vote was received.vote - for this member in the election.public Boolean vote()
Boolean.TRUE means they voted for this member,
Boolean.FALSE means they voted against this member, and null means no vote was received.public ClusterMember leadershipTermId(long leadershipTermId)
leadershipTermId - leadership term reached for the cluster member.public long leadershipTermId()
public ClusterMember logPosition(long logPosition)
logPosition - this member has persisted.public long logPosition()
public ClusterMember candidateTermId(long candidateTermId)
candidateTermId - used when voting.public long candidateTermId()
public ClusterMember catchupReplaySessionId(long replaySessionId)
replaySessionId - for the replay when catching up to the leader.public long catchupReplaySessionId()
public ClusterMember catchupReplayCorrelationId(long correlationId)
correlationId - for the replay when catching up to the leader.public long catchupReplayCorrelationId()
public ClusterMember correlationId(long correlationId)
correlationId - assigned to the current action undertaken by the cluster member.public long correlationId()
public ClusterMember timeOfLastAppendPositionNs(long timeNs)
timeNs - of the last received appendPosition.public long timeOfLastAppendPositionNs()
Aeron.NULL_VALUE if none received.public String ingressEndpoint()
public String consensusEndpoint()
public String logEndpoint()
public String catchupEndpoint()
public String archiveEndpoint()
public String endpoints()
parse(String)public ExclusivePublication publication()
Publication used for send status updates to the member.Publication used for send status updates to the member.public void publication(ExclusivePublication publication)
Publication used for send status updates to the member.publication - used for send status updates to the member.public void closePublication(ErrorHandler errorHandler)
errorHandler - to capture errors during close.public static ClusterMember[] parse(String value)
member-id,ingress:port,consensus:port,log:port,catchup:port,archive:port|1,...
value - of the string to be parsed.public static ClusterMember parseEndpoints(int id, String endpoints)
ClusterMember(int, String, String, String, String, String, String).id - of the member node.endpoints - comma separated.ClusterMember with the endpoints set.public static String encodeAsString(ClusterMember[] clusterMembers)
clusterMembers - to fill the details from.parse(String).public static String encodeAsString(List<ClusterMember> clusterMembers)
List to a String.clusterMembers - to fill the details from.parse(String).public static void copyVotes(ClusterMember[] srcMembers, ClusterMember[] dstMembers)
id()s match.srcMembers - to copy the votes from.dstMembers - to copy the votes to.public static void addConsensusPublications(ClusterMember[] members, ClusterMember exclude, ChannelUri channelUri, int streamId, Aeron aeron)
members - of the cluster.exclude - this member when adding publications.channelUri - for the publication.streamId - for the publication.aeron - to add the publications to.public static void addConsensusPublication(ClusterMember member, ChannelUri channelUri, int streamId, Aeron aeron)
Publication for communicating to a member on the consensus channel.member - to which the publication is addressed.channelUri - for the target member.streamId - for the target member.aeron - from which the publication will be created.public static void closeConsensusPublications(ErrorHandler errorHandler, ClusterMember[] clusterMembers)
errorHandler - to capture errors during close.clusterMembers - to close the publications for.public static void addClusterMemberIds(ClusterMember[] clusterMembers, Int2ObjectHashMap<ClusterMember> clusterMemberByIdMap)
ClusterMembers which can be looked up by id.clusterMembers - to populate the map.clusterMemberByIdMap - to be populated.public static boolean hasActiveQuorum(ClusterMember[] clusterMembers, long nowNs, long timeoutNs)
clusterMembers - for the current cluster.nowNs - for the current time.timeoutNs - after which a follower is not considered active.public static int quorumThreshold(int memberCount)
memberCount - for the clusterpublic static long quorumPosition(ClusterMember[] members, long[] rankedPositions)
members - of the cluster.rankedPositions - temp array to be used for sorting the positions to avoid allocation.public static void resetLogPositions(ClusterMember[] clusterMembers, long logPosition)
clusterMembers - to be reset.logPosition - to set for them all.public static boolean haveVotersReachedPosition(ClusterMember[] clusterMembers, long position, long leadershipTermId)
clusterMembers - to check.position - to compare the logPosition() against.leadershipTermId - expected of the members.public static void reset(ClusterMember[] members)
members - to reset.public static void becomeCandidate(ClusterMember[] members, long candidateTermId, int candidateMemberId)
Aeron.NULL_VALUE.members - to reset the votes for.candidateTermId - for the candidacy.candidateMemberId - for the election.public static boolean hasWonVoteOnFullCount(ClusterMember[] members, long candidateTermId)
members - to check for votes.candidateTermId - for the vote.public static boolean hasMajorityVoteWithCanvassMembers(ClusterMember[] members, long candidateTermId)
ElectionState.CANVASS?members - to check for votes.candidateTermId - for the vote.public static boolean hasMajorityVote(ClusterMember[] clusterMembers, long candidateTermId)
clusterMembers - to check for votes.candidateTermId - for the vote.public static ClusterMember determineMember(ClusterMember[] clusterMembers, int memberId, String memberEndpoints)
clusterMembers - for the current cluster which can be null.memberId - for this member.memberEndpoints - for this member.ClusterMember determined.public static void validateMemberEndpoints(ClusterMember member, String memberEndpoints)
member - to check memberEndpoints against.memberEndpoints - to check member against.ConsensusModule.Context.memberEndpoints(),
ConsensusModule.Context.clusterMembers()public static boolean areSameEndpoints(ClusterMember lhs, ClusterMember rhs)
lhs - to compare for equality.rhs - to compare for equality.public static boolean isUnanimousCandidate(ClusterMember[] clusterMembers, ClusterMember candidate)
clusterMembers - to compare the candidate against.candidate - for leadership.public static boolean isQuorumCandidate(ClusterMember[] clusterMembers, ClusterMember candidate)
clusterMembers - to compare the candidate against.candidate - for leadership.public static int compareLog(long lhsLogLeadershipTermId,
long lhsLogPosition,
long rhsLogLeadershipTermId,
long rhsLogPosition)
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.public static int compareLog(ClusterMember lhs, ClusterMember rhs)
lhs - member to compare.rhs - member to compare.public static boolean notDuplicateEndpoint(ClusterMember[] members, String endpoints)
members - to check if the provided endpoints have a duplicate.endpoints - to check for duplicates.public static int findMemberIndex(ClusterMember[] clusterMembers, int memberId)
clusterMembers - to be searched.memberId - to search for.ArrayUtil.UNKNOWN_INDEX.public static ClusterMember findMember(ClusterMember[] clusterMembers, int memberId)
ClusterMember with a given id.clusterMembers - to search.memberId - to search for.ClusterMember if found otherwise null.public static ClusterMember[] addMember(ClusterMember[] oldMembers, ClusterMember newMember)
ClusterMembers.oldMembers - to add to.newMember - to add.public static ClusterMember[] removeMember(ClusterMember[] oldMembers, int memberId)
oldMembers - to remove a member from.memberId - of the member to remove.public static int highMemberId(ClusterMember[] clusterMembers)
clusterMembers - to search for the highest id.Aeron.NULL_VALUE if empty.public static String ingressEndpoints(ClusterMember[] members)
id=endpoint,id=endpoint, ....members - for which the ingress endpoints string will be generated.Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.