Skip to content

AllocationStrategy

Defined in: src/cluster/sharding/AllocationStrategy.ts:10

Instructs the ShardCoordinator how to place and rebalance shards.

allocate is called when a shard needs a new home — e.g. right after it is first requested. rebalance is called periodically so strategies can move shards away from busy nodes.

allocate(shardId, candidates, currentShards): NodeAddress

Defined in: src/cluster/sharding/AllocationStrategy.ts:12

Pick an owner for a newly-discovered shard.

number

readonly NodeAddress[]

ReadonlyMap<string, ReadonlySet<number>>

NodeAddress


rebalance(currentShards, candidates, rebalanceInProgress): Set<number>

Defined in: src/cluster/sharding/AllocationStrategy.ts:19

Return a set of shard ids that should be re-homed. The coordinator will send HandOff for each and then allocate() a new home once the handoff completes.

ReadonlyMap<string, ReadonlySet<number>>

readonly NodeAddress[]

ReadonlySet<number>

Set<number>