Record Class ClusterConfiguration
java.lang.Object
java.lang.Record
io.camunda.zeebe.dynamic.config.state.ClusterConfiguration
public record ClusterConfiguration(long version, Map<MemberId,MemberState> members, Optional<CompletedChange> lastChange, Optional<ClusterChangePlan> pendingChanges, Optional<RoutingState> routingState)
extends Record
Represents the cluster configuration which describes the current active, joining or leaving
brokers and the partitions that each broker replicates.
version - represents the current version of the configuration. It is incremented only by the coordinator when a new configuration change is triggered.
members - represents the state of each member
changes - keeps track of the ongoing configuration changes
This class is immutable. Each mutable methods returns a new instance with the updated state.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionClusterConfiguration(long version, Map<MemberId, MemberState> members, Optional<CompletedChange> lastChange, Optional<ClusterChangePlan> pendingChanges, Optional<RoutingState> routingState) Creates an instance of aClusterConfigurationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaddMember(MemberId memberId, MemberState state) advanceConfigurationChange(UnaryOperator<ClusterConfiguration> configurationUpdater) When the operation returned bypendingChangesFor(MemberId)is completed, the changes should be reflected in ClusterConfiguration by invoking this method.Cancel any pending changes and return a new configuration with the already applied changes.intfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanbooleanstatic ClusterConfigurationinit()booleanReturns the value of thelastChangerecord component.members()Returns the value of themembersrecord component.merge(ClusterConfiguration other) Returns a new ClusterConfiguration after merging this and other.intReturns the value of thependingChangesrecord component.pendingChangesFor(MemberId memberId) Returns the next pending operation for the given memberId.Returns the value of theroutingStaterecord component.final StringtoString()Returns a string representation of this record class.static ClusterConfigurationupdateMember(MemberId memberId, UnaryOperator<MemberState> memberStateUpdater) Adds or updates a member in the configuration.longversion()Returns the value of theversionrecord component.
-
Field Details
-
INITIAL_VERSION
public static final int INITIAL_VERSION- See Also:
-
-
Constructor Details
-
ClusterConfiguration
public ClusterConfiguration(long version, Map<MemberId, MemberState> members, Optional<CompletedChange> lastChange, Optional<ClusterChangePlan> pendingChanges, Optional<RoutingState> routingState) Creates an instance of aClusterConfigurationrecord class.- Parameters:
version- the value for theversionrecord componentmembers- the value for themembersrecord componentlastChange- the value for thelastChangerecord componentpendingChanges- the value for thependingChangesrecord componentroutingState- the value for theroutingStaterecord component
-
-
Method Details
-
uninitialized
-
isUninitialized
public boolean isUninitialized() -
init
-
addMember
-
updateMember
public ClusterConfiguration updateMember(MemberId memberId, UnaryOperator<MemberState> memberStateUpdater) Adds or updates a member in the configuration.memberStateUpdater is invoked with the current state of the member. If the member does not exist, and memberStateUpdater returns a non-null value, then the member is added to the configuration. If the member exists, and the memberStateUpdater returns a null value, then the member is removed.
- Parameters:
memberId- id of the member to be updatedmemberStateUpdater- transforms the current state of the member to the new state- Returns:
- the updated ClusterConfiguration
-
startConfigurationChange
public ClusterConfiguration startConfigurationChange(List<ClusterConfigurationChangeOperation> operations) -
merge
Returns a new ClusterConfiguration after merging this and other. This doesn't overwrite this or other. If this.version == other.version then the new ClusterConfiguration contains merged members and changes. Otherwise, it returns the one with the highest version.- Parameters:
other- ClusterConfiguration to merge- Returns:
- merged ClusterConfiguration
-
hasPendingChanges
public boolean hasPendingChanges() -
pendingChangesFor
Returns the next pending operation for the given memberId. If there is no pending operation for this member, then returns an empty optional.- Parameters:
memberId- id of the member- Returns:
- the next pending operation for the given memberId.
-
advanceConfigurationChange
public ClusterConfiguration advanceConfigurationChange(UnaryOperator<ClusterConfiguration> configurationUpdater) When the operation returned bypendingChangesFor(MemberId)is completed, the changes should be reflected in ClusterConfiguration by invoking this method. This removes the completed operation from the pending changes and update the member state using the given updater.- Parameters:
configurationUpdater- the method to update the configuration- Returns:
- the updated ClusterConfiguration
-
hasMember
-
getMember
-
clusterSize
public int clusterSize() -
partitionCount
public int partitionCount() -
minReplicationFactor
-
nextPendingOperation
-
cancelPendingChanges
Cancel any pending changes and return a new configuration with the already applied changes.- Returns:
- a new configuration with the already applied changes and no pending changes.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
version
public long version()Returns the value of theversionrecord component.- Returns:
- the value of the
versionrecord component
-
members
Returns the value of themembersrecord component.- Returns:
- the value of the
membersrecord component
-
lastChange
Returns the value of thelastChangerecord component.- Returns:
- the value of the
lastChangerecord component
-
pendingChanges
Returns the value of thependingChangesrecord component.- Returns:
- the value of the
pendingChangesrecord component
-
routingState
Returns the value of theroutingStaterecord component.- Returns:
- the value of the
routingStaterecord component
-