Record Class ReplicatedTransactionCommand

java.lang.Object
java.lang.Record
com.loomcache.server.transaction.ReplicatedTransactionCommand

public record ReplicatedTransactionCommand(Transaction transaction, Map<Integer, Set<String>> mapNamesByGroup, @Nullable String senderId) extends Record
Serialized cross-group transaction payload replicated through Raft.

The Transaction model intentionally carries only keys/operations, so the replicated command also includes the logical map name(s) bound to each Raft group touched by the transaction. Followers use that metadata to resolve the correct sharded DistributedMap for state-machine apply.

Cross-group atomic BATCH (ESC-14)

Before ESC-14 each Raft group mapped to at most one logical map (Map<Integer, String>). Cross-group atomic BATCH_EXECUTE however lets every operation target a different logical map — which means a single Raft group can hold slices for multiple maps in the same transaction. The shape is therefore Map<Integer, Set<String>>. The legacy "one map per group" call sites continue to work via mapNameForGroup(int) which returns the single entry when the set has exactly one element, or throws otherwise so callers cannot silently drop a map.
  • Constructor Details

    • ReplicatedTransactionCommand

      public ReplicatedTransactionCommand(Transaction transaction, Map<Integer, Set<String>> mapNamesByGroup, @Nullable String senderId)
      Creates an instance of a ReplicatedTransactionCommand record class.
      Parameters:
      transaction - the value for the transaction record component
      mapNamesByGroup - the value for the mapNamesByGroup record component
      senderId - the value for the senderId record component
    • ReplicatedTransactionCommand

      public ReplicatedTransactionCommand(Transaction transaction, Map<Integer, Set<String>> mapNamesByGroup)
  • Method Details

    • ofSingleMapPerGroup

      public static ReplicatedTransactionCommand ofSingleMapPerGroup(Transaction transaction, Map<Integer,String> mapNameByGroup, @Nullable String senderId)
      Convenience factory for the legacy "one map per group" shape. Every group maps to a single-element Set. Used by the single-map cross-group TX commit path and by tests that were written against the pre-ESC-14 wire format.
    • ofSingleMapPerGroup

      public static ReplicatedTransactionCommand ofSingleMapPerGroup(Transaction transaction, Map<Integer,String> mapNameByGroup)
    • mapNameForGroup

      public String mapNameForGroup(int groupId)
      Returns the group's single logical map name, or throws if the group has multiple maps (cross-group atomic BATCH case — callers must use mapNamesForGroup(int) and the per-op Transaction.Operation.mapName() instead).
    • mapNamesForGroup

      public Set<String> mapNamesForGroup(int groupId)
      Returns all logical map names touched by this transaction in groupId. Never null; never empty when the group is present in mapNamesByGroup().
    • hasConditions

      public boolean hasConditions()
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • transaction

      public Transaction transaction()
      Returns the value of the transaction record component.
      Returns:
      the value of the transaction record component
    • mapNamesByGroup

      public Map<Integer, Set<String>> mapNamesByGroup()
      Returns the value of the mapNamesByGroup record component.
      Returns:
      the value of the mapNamesByGroup record component
    • senderId

      public @Nullable String senderId()
      Returns the value of the senderId record component.
      Returns:
      the value of the senderId record component