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 Details

  • Constructor Details

    • ClusterConfiguration

      public ClusterConfiguration(long version, Map<MemberId,MemberState> members, Optional<CompletedChange> lastChange, Optional<ClusterChangePlan> pendingChanges, Optional<RoutingState> routingState)
      Creates an instance of a ClusterConfiguration record class.
      Parameters:
      version - the value for the version record component
      members - the value for the members record component
      lastChange - the value for the lastChange record component
      pendingChanges - the value for the pendingChanges record component
      routingState - the value for the routingState record component
  • Method Details

    • uninitialized

      public static ClusterConfiguration uninitialized()
    • isUninitialized

      public boolean isUninitialized()
    • init

      public static ClusterConfiguration init()
    • addMember

      public ClusterConfiguration addMember(MemberId memberId, MemberState state)
    • 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 updated
      memberStateUpdater - 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

      public Optional<ClusterConfigurationChangeOperation> pendingChangesFor(MemberId memberId)
      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 by pendingChangesFor(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

      public boolean hasMember(MemberId memberId)
    • getMember

      public MemberState getMember(MemberId memberId)
    • clusterSize

      public int clusterSize()
    • partitionCount

      public int partitionCount()
    • minReplicationFactor

      public Integer minReplicationFactor()
    • nextPendingOperation

      public ClusterConfigurationChangeOperation nextPendingOperation()
    • cancelPendingChanges

      public ClusterConfiguration 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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • version

      public long version()
      Returns the value of the version record component.
      Returns:
      the value of the version record component
    • members

      public Map<MemberId,MemberState> members()
      Returns the value of the members record component.
      Returns:
      the value of the members record component
    • lastChange

      public Optional<CompletedChange> lastChange()
      Returns the value of the lastChange record component.
      Returns:
      the value of the lastChange record component
    • pendingChanges

      public Optional<ClusterChangePlan> pendingChanges()
      Returns the value of the pendingChanges record component.
      Returns:
      the value of the pendingChanges record component
    • routingState

      public Optional<RoutingState> routingState()
      Returns the value of the routingState record component.
      Returns:
      the value of the routingState record component