Route one aggregate id's commands to one node on a cluster (evoq#8) #9

Closed
venus wants to merge 0 commits from venus/8-route-one-node into main
Member

Refs #8

On a cluster, all commands for one aggregate id run on one node, its owner. Each registry joins the pg group evoq_nodes, and the owner is picked from the live nodes by rendezvous hashing. When the owner's node is lost, the id moves, and the retry does not apply the command twice. One node owns every id, so standalone runs the path it always did.

  • evoq_aggregate_registry: owner/1, owner_of/2, live_nodes/0. get_or_start/3 answers the owner's aggregate and starts it there if needed, with at most one hop.
  • evoq_command_router: an owner node that went away ({nodedown, _}, or a remote aggregate's shutdown) is retried within retry_attempts and marked owner_lost.
  • evoq_aggregate:execute_command_with_state/3: an owner_lost retry first reads the stream's last events (owner_lost_lookback, default 100). A command that one of them names as its causation_id is answered {ok, Version, [], State} with nothing appended. No other command makes that read.

Tests: evoq_aggregate_nodes_SUITE, real peers with one shared store stand-in, 2 and 3 nodes: the owner is the same on every node, one runner per id with zero store conflicts, an owner halted or stopped mid-traffic, and an owner that appended and died before replying. Unit: evoq_aggregate_owner_tests, evoq_aggregate_seen_command_tests. Five mutants on the routing choice are each killed by the peer suite.

Local, OTP 28: compile, lint, eunit 376/376, ct 71/71, proper, and the dialyzer ratchet (no finding outside the baseline). The peer suite passed 3 runs out of 3.

Refs #8 On a cluster, all commands for one aggregate id run on one node, its owner. Each registry joins the pg group `evoq_nodes`, and the owner is picked from the live nodes by rendezvous hashing. When the owner's node is lost, the id moves, and the retry does not apply the command twice. One node owns every id, so standalone runs the path it always did. - `evoq_aggregate_registry`: `owner/1`, `owner_of/2`, `live_nodes/0`. `get_or_start/3` answers the owner's aggregate and starts it there if needed, with at most one hop. - `evoq_command_router`: an owner node that went away (`{nodedown, _}`, or a remote aggregate's `shutdown`) is retried within `retry_attempts` and marked `owner_lost`. - `evoq_aggregate:execute_command_with_state/3`: an `owner_lost` retry first reads the stream's last events (`owner_lost_lookback`, default 100). A command that one of them names as its `causation_id` is answered `{ok, Version, [], State}` with nothing appended. No other command makes that read. Tests: `evoq_aggregate_nodes_SUITE`, real peers with one shared store stand-in, 2 and 3 nodes: the owner is the same on every node, one runner per id with zero store conflicts, an owner halted or stopped mid-traffic, and an owner that appended and died before replying. Unit: `evoq_aggregate_owner_tests`, `evoq_aggregate_seen_command_tests`. Five mutants on the routing choice are each killed by the peer suite. Local, OTP 28: compile, lint, eunit 376/376, ct 71/71, proper, and the dialyzer ratchet (no finding outside the baseline). The peer suite passed 3 runs out of 3.
Each node's registry joins the pg group evoq_nodes; the owner of an id is
chosen from the live nodes by rendezvous hashing, so every node names the
same owner and losing a node moves only its ids. get_or_start answers the
owner's aggregate, starting it there when needed (one hop at most). One
node owns every id, so standalone runs the path it always did.

The router retries a dispatch whose owner node went away (nodedown, or a
remote aggregate's shutdown) and marks it owner_lost. Such a retry reads
the stream's tail first and answers a command the stream already holds
(causation_id = command_id) as done, so a command the lost node appended
before it went is not applied twice. Other commands never pay that read.

Refs #8
test: count reads only after the aggregate's load has run
All checks were successful
docs / doc snippets (erlang) (pull_request) Successful in 9s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (pull_request) Successful in 9m5s
docs / doc snippets (erlang) (push) Successful in 17s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Successful in 7m1s
9ee5943f51
Member

Landed by fast-forward: main is 9ee5943f51 (from 56755af1). This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is 9ee5943f5161bd6fb48fb111e7135000d3ab6f69 (from 56755af1). This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-02 06:56:06 +00:00
All checks were successful
docs / doc snippets (erlang) (pull_request) Successful in 9s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (pull_request) Successful in 9m5s
docs / doc snippets (erlang) (push) Successful in 17s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Successful in 7m1s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
reckon-db-org/evoq!9
No description provided.