Record Class PartitionTablePayload

java.lang.Object
java.lang.Record
com.loomcache.common.protocol.PartitionTablePayload
Record Components:
numPartitions - number of partitions in the cluster (must be > 0)
partitionToGroup - partition → group id, length == numPartitions
revision - monotonic revision (used to detect staleness between refreshes)

public record PartitionTablePayload(int numPartitions, int[] partitionToGroup, long revision, Map<Integer,String> groupLeaderEndpoints) extends Record
Wire payload for the PARTITION_TABLE_REQUEST / PARTITION_TABLE_RESPONSE opcodes introduced in BLK-2026-04-22-007 Day 2.

Carries the server's current partition ownership snapshot — the mapping from each partition id to the Raft group that owns it. Clients cache this snapshot and route keyed requests directly to the owning group instead of relying on server-side NOT_OWNER redirects.

Node-endpoint resolution (which TCP endpoint currently leads each group) is a follow-up: clients still consult their existing leader tracker for that. This payload is the minimum needed to replace the current "hash % active-node-count" routing with a partition-owner lookup.

Legacy wire format (fixed layout, big-endian):

  int        numPartitions            ≥ 1
  int × N    partitionToGroup[0..N-1] groupId per partition (≥ 0)
  long       revision                 monotonic snapshot revision

Peers that negotiate ProtocolFeatures.PARTITION_TABLE_ENDPOINTS may append endpoint metadata after revision. The default serializer intentionally emits the legacy layout so rolling upgrades do not break old strict decoders.

  • Constructor Details

    • PartitionTablePayload

      public PartitionTablePayload(int numPartitions, int[] partitionToGroup, long revision)
    • PartitionTablePayload

      public PartitionTablePayload(int numPartitions, int[] partitionToGroup, long revision, Map<Integer,String> groupLeaderEndpoints)
      Creates an instance of a PartitionTablePayload record class.
      Parameters:
      numPartitions - the value for the numPartitions record component
      partitionToGroup - the value for the partitionToGroup record component
      revision - the value for the revision record component
      groupLeaderEndpoints - the value for the groupLeaderEndpoints record component
  • Method Details

    • partitionToGroup

      public int[] partitionToGroup()
      Returns the value of the partitionToGroup record component.
      Returns:
      the value of the partitionToGroup record component
    • ownerGroupForHash

      public int ownerGroupForHash(int hash)
      Returns:
      the group id owning the partition that hash maps to
    • ownerEndpointForHash

      public String ownerEndpointForHash(int hash)
      Returns:
      the advertised leader/owner endpoint for the group owning hash, or null if this snapshot does not carry endpoint metadata for that group
    • serialize

      public static byte[] serialize(PartitionTablePayload payload)
      Serialize a payload to its wire bytes.
      Parameters:
      payload - the payload (non-null)
      Returns:
      big-endian wire bytes
    • serialize

      public static byte[] serialize(PartitionTablePayload payload, boolean includeEndpointMetadata)
      Serialize a payload to its wire bytes.
      Parameters:
      payload - the payload (non-null)
      includeEndpointMetadata - whether to append negotiated endpoint metadata
      Returns:
      big-endian wire bytes
    • deserialize

      public static PartitionTablePayload deserialize(byte[] bytes)
      Deserialize a payload from wire bytes.
      Parameters:
      bytes - the wire bytes (non-null)
      Returns:
      the parsed payload
      Throws:
      IllegalArgumentException - if the bytes are truncated or carry invalid fields
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • numPartitions

      public int numPartitions()
      Returns the value of the numPartitions record component.
      Returns:
      the value of the numPartitions record component
    • revision

      public long revision()
      Returns the value of the revision record component.
      Returns:
      the value of the revision record component
    • groupLeaderEndpoints

      public Map<Integer,String> groupLeaderEndpoints()
      Returns the value of the groupLeaderEndpoints record component.
      Returns:
      the value of the groupLeaderEndpoints record component