Class ShardedDataStructureRegistry
java.lang.Object
com.loomcache.server.sharding.ShardedDataStructureRegistry
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 Summary
ConstructorsConstructorDescriptionShardedDataStructureRegistry(PartitionRouter router, int instanceNumber) Creates a new sharded registry backed by the given partition router.ShardedDataStructureRegistry(PartitionRouter router, int instanceNumber, int idGeneratorNodeId) -
Method Summary
Modifier and TypeMethodDescription<V> VexecuteOnGroup(int groupId, Function<DataStructureRegistry, V> operation) Executes an operation on the registry of a specific Raft group.intReturns the number of instantiated group registries.getRegistryForGroup(int groupId) Returns the registry for the specified Raft group, creating it if necessary.getRegistryForKey(String key) Returns the registry for the Raft group that owns the given key.booleanhasRegistryForGroup(int groupId) Checks whether a registry exists for the given group without creating one.@Nullable DataStructureRegistryremoveRegistry(int groupId) Removes and returns the registry for a specific group.scatterGather(Function<DataStructureRegistry, V> operation) Executes an operation on every instantiated group registry and collects results.voidsetDataConnectionConfigs(Map<String, DataConnectionConfig> configs) voidvoidsetGenericMapStoreConfigs(Map<String, GenericMapStoreConfig> configs) voidvoidsetMaxMemoryBytesPerMap(long maxBytes) voidsetPriorityQueueConfigs(Map<String, PriorityQueueConfig> configs) voidsetQueueConfigs(Map<String, QueueConfig> configs) voidshutdown()Shut down resources owned by all instantiated group registries.
-
Constructor Details
-
ShardedDataStructureRegistry
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
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
-
setMaxMemoryBytesPerMap
public void setMaxMemoryBytesPerMap(long maxBytes) -
setQueueConfigs
-
setPriorityQueueConfigs
-
setDataConnectionConfigs
-
setGenericMapStoreConfigs
-
setLocalWriterId
-
getRegistryForKey
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
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
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
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.
-