Mesh.Cluster.Rebalancing (Mesh v0.1.4)

View Source

Coordinates rebalancing when capabilities are registered or removed.

When a node registers capabilities, this module ensures a coordinated rebalancing process across all nodes with the same capabilities:

  1. Enter rebalancing mode (pause new actor creation)
  2. Gracefully stop actors for affected capabilities
  3. Synchronize shards across all participating nodes
  4. Exit rebalancing mode (resume normal operation)

This prevents race conditions and ensures consistent actor placement during topology changes.

Summary

Functions

Returns a specification to start this module under a supervisor.

Initiates coordinated rebalancing for the given capabilities.

Returns current rebalancing mode: :active or :rebalancing

Checks if a capability is currently rebalancing.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

coordinate_rebalancing(node, capabilities)

Initiates coordinated rebalancing for the given capabilities.

This function will:

  1. Calculate current shard ownership (before registration)
  2. Register capabilities (changes topology)
  3. Calculate new shard ownership (after registration)
  4. Put affected nodes into rebalancing mode
  5. Stop only actors on shards that changed ownership
  6. Sync shards
  7. Resume normal operation

Returns :ok or {:error, reason}

mode()

Returns current rebalancing mode: :active or :rebalancing

rebalancing?(capability)

Checks if a capability is currently rebalancing.

reset_state()

start_link(_)