implement cluster stubs: cross-node routing, rebalancing, and actor migration #158

Open
HugoNijhuis wants to merge 3 commits from implement-cluster-stubs into main
Owner

What was implemented\n\nAll stub/placeholder implementations in the cluster package have been replaced with working code.\n\n### cluster/shard.go\n- ConsistentHashPlacement.PlaceActor() - Now builds a consistent hash ring from available nodes and uses it for deterministic actor placement (was: simple hash modulo)\n- ConsistentHashPlacement.RebalanceShards() - Now computes an entirely new shard map redistributing all shards across nodes using consistent hashing (was: returned unchanged map)\n- deriveReplicaCount() - New helper to extract replication factor from existing shard assignments\n\n### cluster/manager.go\n- handleRebalanceRequest() - Leader computes new shard map via ConsistentHashPlacement.RebalanceShards(), applies it locally, and broadcasts to cluster (was: only logged)\n- handleMigrationRequest() - Parses ActorMigration payload, detects if actor is local and initiates export (was: only logged)\n- triggerShardRebalancing() - Now actually computes new shard map and broadcasts it (was: only logged)\n- broadcastShardMap() - New method to publish shard map updates to aether.cluster.shard_map NATS subject\n- handleShardMapUpdate() - New method to apply received shard maps (applies only newer versions, ignores stale)\n- handleClusterMessage() - Now routes shard_map messages to handleShardMapUpdate()\n\n### cluster/distributed.go\n- SendMessage() - Now determines target node via consistent hash ring, sends locally if actor is on this node, otherwise routes via NATS route_message (was: always delegated to local runtime)\n- routeMessageToNode() - New method to send messages to other nodes\n- handleClusterMessage() route_message case - Now checks IsLocalActor() before delivering, relays to correct node if actor lives elsewhere (was: always delivered locally)\n- handleRebalanceRequest() - Now applies new shard maps from leader with version comparison (was: empty)\n\n### cluster/shard_test.go\n- TestConsistentHashPlacement_RebalanceShards - Updated to test actual rebalancing behavior (new version, correct shard assignments) instead of testing stub behavior\n\n## Summary\n\n| Stub | Status |\n|------|--------|\n| ConsistentHashPlacement.PlaceActor() | Fixed |\n| ConsistentHashPlacement.RebalanceShards() | Implemented |\n| ClusterManager.handleRebalanceRequest() | Implemented |\n| ClusterManager.handleMigrationRequest() | Implemented |\n| ClusterManager.triggerShardRebalancing() | Implemented |\n| DistributedVM.SendMessage() | Implemented |\n| DistributedVM.handleRebalanceRequest() | Implemented |\n| route_message handler | Fixed |\n\nAll tests pass. Build succeeds.

## What was implemented\n\nAll stub/placeholder implementations in the cluster package have been replaced with working code.\n\n### cluster/shard.go\n- **ConsistentHashPlacement.PlaceActor()** - Now builds a consistent hash ring from available nodes and uses it for deterministic actor placement (was: simple hash modulo)\n- **ConsistentHashPlacement.RebalanceShards()** - Now computes an entirely new shard map redistributing all shards across nodes using consistent hashing (was: returned unchanged map)\n- **deriveReplicaCount()** - New helper to extract replication factor from existing shard assignments\n\n### cluster/manager.go\n- **handleRebalanceRequest()** - Leader computes new shard map via ConsistentHashPlacement.RebalanceShards(), applies it locally, and broadcasts to cluster (was: only logged)\n- **handleMigrationRequest()** - Parses ActorMigration payload, detects if actor is local and initiates export (was: only logged)\n- **triggerShardRebalancing()** - Now actually computes new shard map and broadcasts it (was: only logged)\n- **broadcastShardMap()** - New method to publish shard map updates to aether.cluster.shard_map NATS subject\n- **handleShardMapUpdate()** - New method to apply received shard maps (applies only newer versions, ignores stale)\n- handleClusterMessage() - Now routes shard_map messages to handleShardMapUpdate()\n\n### cluster/distributed.go\n- **SendMessage()** - Now determines target node via consistent hash ring, sends locally if actor is on this node, otherwise routes via NATS route_message (was: always delegated to local runtime)\n- **routeMessageToNode()** - New method to send messages to other nodes\n- **handleClusterMessage() route_message case** - Now checks IsLocalActor() before delivering, relays to correct node if actor lives elsewhere (was: always delivered locally)\n- **handleRebalanceRequest()** - Now applies new shard maps from leader with version comparison (was: empty)\n\n### cluster/shard_test.go\n- TestConsistentHashPlacement_RebalanceShards - Updated to test actual rebalancing behavior (new version, correct shard assignments) instead of testing stub behavior\n\n## Summary\n\n| Stub | Status |\n|------|--------|\n| ConsistentHashPlacement.PlaceActor() | ✅ Fixed |\n| ConsistentHashPlacement.RebalanceShards() | ✅ Implemented |\n| ClusterManager.handleRebalanceRequest() | ✅ Implemented |\n| ClusterManager.handleMigrationRequest() | ✅ Implemented |\n| ClusterManager.triggerShardRebalancing() | ✅ Implemented |\n| DistributedVM.SendMessage() | ✅ Implemented |\n| DistributedVM.handleRebalanceRequest() | ✅ Implemented |\n| route_message handler | ✅ Fixed |\n\nAll tests pass. Build succeeds.
HugoNijhuis added 1 commit 2026-07-29 18:12:35 +00:00
- Fix ConsistentHashPlacement.PlaceActor() to use consistent hash ring
- Implement ConsistentHashPlacement.RebalanceShards() to redistribute shards
- Implement ClusterManager.handleRebalanceRequest() with actual rebalancing
- Implement ClusterManager.handleMigrationRequest() for actor state transfer
- Implement ClusterManager.triggerShardRebalancing() to compute and broadcast
- Implement DistributedVM.SendMessage() with cross-node NATS routing
- Implement DistributedVM.handleRebalanceRequest() to update shard map
- Fix route_message handler to check if actor is local before delivery
- Update ConsistentHashPlacement.RebalanceShards() test for new behavior
- Add handleShardMapUpdate() and broadcastShardMap() to ClusterManager
HugoNijhuis added 2 commits 2026-07-30 21:33:26 +00:00
- GetShardMap: copy Shards and Nodes map contents before returning
- hashRing: rebuild from shardMap.Nodes after every rebalance/shard_map update
- DistributedVM.handleRebalanceRequest: add leader check and self-broadcast guard
- route_message: add hop-count (MaxRouteHops=10) to prevent infinite loops
- handleMigrationRequest: broadcast migration updates instead of setting local copy
- Replace non-deterministic map range fallback with sorted node selection in PlaceActor and RebalanceShards
- Add Body field to MessagePayload to preserve message data during cross-node routing
- Forward actual message body in route_message handler instead of discarding it
- Add self-message guard to route_message handler to prevent loops
- Add nil guard for shardMap in handleRebalanceRequest
- Add self-message guard to handleRebalanceRequest in DistributedVM
All checks were successful
CI / build (pull_request) Successful in 40s
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin implement-cluster-stubs:implement-cluster-stubs
git checkout implement-cluster-stubs
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: flowmade-one/aether#158