Class ShardedDataStructureRegistry

java.lang.Object
com.loomcache.server.sharding.ShardedDataStructureRegistry

public class ShardedDataStructureRegistry extends Object
Wraps DataStructureRegistry with per-Raft-group state isolation.

Each Raft group owns an independent DataStructureRegistry, ensuring that data structures in one group are fully isolated from those in another. Operations are routed to the correct group's registry based on key hashing via the PartitionRouter.

Design:

  • Lazy creation: registries are created on first access to a group
  • Thread-safe: uses ConcurrentHashMap for group registry storage
  • Cross-group queries use scatter-gather via scatterGather(Function)

Consistency: Each group's registry is managed by its own Raft group, so operations within a single group are linearizable. Cross-group operations provide eventual consistency unless coordinated externally.

Since:
2.0
  • Constructor Details

    • ShardedDataStructureRegistry

      public ShardedDataStructureRegistry(PartitionRouter router, int instanceNumber)
      Creates a new sharded registry backed by the given partition router.
      Parameters:
      router - the partition router for key-to-group mapping (must not be null)
      instanceNumber - the node instance number for logging (must be >= 0)
    • ShardedDataStructureRegistry

      public ShardedDataStructureRegistry(PartitionRouter router, int instanceNumber, int idGeneratorNodeId)
  • Method Details

    • getRegistryForGroup

      public DataStructureRegistry getRegistryForGroup(int groupId)
      Returns the registry for the specified Raft group, creating it if necessary.
      Parameters:
      groupId - the Raft group ID (must be >= 0)
      Returns:
      the registry for this group (never null)
    • setDefaultMapConfig

      public void setDefaultMapConfig(DistributedMapConfig config)
    • setMaxMemoryBytesPerMap

      public void setMaxMemoryBytesPerMap(long maxBytes)
    • setQueueConfigs

      public void setQueueConfigs(Map<String, QueueConfig> configs)
    • setPriorityQueueConfigs

      public void setPriorityQueueConfigs(Map<String, PriorityQueueConfig> configs)
    • setDataConnectionConfigs

      public void setDataConnectionConfigs(Map<String, DataConnectionConfig> configs)
    • setGenericMapStoreConfigs

      public void setGenericMapStoreConfigs(Map<String, GenericMapStoreConfig> configs)
    • setLocalWriterId

      public void setLocalWriterId(String id)
    • getRegistryForKey

      public DataStructureRegistry getRegistryForKey(String key)
      Returns the registry for the Raft group that owns the given key.
      Parameters:
      key - the data key to route (must not be null)
      Returns:
      the registry for the key's owning group (never null)
    • executeOnGroup

      public <V> V executeOnGroup(int groupId, Function<DataStructureRegistry, V> operation)
      Executes an operation on the registry of a specific Raft group.
      Type Parameters:
      V - the return type of the operation
      Parameters:
      groupId - the target Raft group ID (must be >= 0)
      operation - the operation to execute on the group's registry (must not be null)
      Returns:
      the operation result
    • scatterGather

      public <V> Map<Integer,V> scatterGather(Function<DataStructureRegistry, V> operation)
      Executes an operation on every instantiated group registry and collects results.

      This is the scatter phase of a scatter-gather pattern. Results are collected into a map keyed by group ID. Groups that have not been instantiated are skipped.

      Type Parameters:
      V - the return type of the operation
      Parameters:
      operation - the operation to execute on each group (must not be null)
      Returns:
      an unmodifiable map of groupId to operation result (never null)
    • getGroupCount

      public int getGroupCount()
      Returns the number of instantiated group registries.
      Returns:
      the count of active group registries (always >= 0)
    • hasRegistryForGroup

      public boolean hasRegistryForGroup(int groupId)
      Checks whether a registry exists for the given group without creating one.
      Parameters:
      groupId - the Raft group ID
      Returns:
      true if the group has an instantiated registry
    • removeRegistry

      public @Nullable DataStructureRegistry removeRegistry(int groupId)
      Removes and returns the registry for a specific group.

      Used during partition migration when a group is being drained from this node.

      Parameters:
      groupId - the Raft group ID to remove
      Returns:
      the removed registry, or null if no registry existed for this group
    • shutdown

      public void shutdown()
      Shut down resources owned by all instantiated group registries.