Conversation
PgRegistry 0.3+ replaced the Erlang :pg backend with a self-contained
Elixir port. This migrates stagehand off the old API:
- Replace :pg scope with a PgRegistry :stagehand scope
- Use PgRegistry.register/3 in init instead of :via tuples for cluster
group membership (producers and cron)
- Use local Registry names for producer addressing (consumer subscription)
- Replace :pg.monitor with PgRegistry.monitor/2 for join/leave events
- Replace get_members/2 with lookup/2 (returns [{pid, value}])
- Update tests for new API shapes
Follow the Elixir convention of module-style atoms for named processes (e.g. MyApp.Registry, MyApp.PubSub).
- Replace manual leader election in Cron with Highlander, which ensures a single cron process runs cluster-wide via :global - Remove cron's PgRegistry dependency entirely - Register cron in the local Registry for addressability - Rename PgRegistry scope from Stagehand.PgRegistry to Stagehand.ProducerRegistry since it is now only used for producer cluster discovery
Move PgRegistry scope startup from Stagehand.Supervisor (with idempotent case/match) to a proper Application module. The scope is now started once when the :stagehand application boots.
Producers are discovered cluster-wide via PgRegistry and addressed by pid (consumer subscribes via self(), router uses producers_for_queue). The local Registry name was unused. Producer still accepts an optional name: for direct unit tests.
Cron doesn't need a local name — it's a Highlander singleton found through :global. Test helper walks the Highlander supervision tree to find the cron pid.
Rendezvous (HRW) hashing needs only the member list and a key —
no separate ring structure to build and maintain. The implementation
is a single Enum.max_by over :erlang.phash2({node, key}).
Removes the libring dependency.
A pid's internal representation differs between the local node (where it shows as <0.N.C>) and remote nodes (where the first element is a node-specific identifier). Hashing on node(pid) ensures all nodes in the cluster compute the same winner for a given key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
~> 0.2.2to~> 0.4:pgscope with a PgRegistry-managed:stagehandscopePgRegistry.register/3ininitinstead of:viatuplesRegistrynames for consumer subscription addressing:pg.monitor/2withPgRegistry.monitor/2for cluster join/leave eventsget_members/2withlookup/2(extracts pids from[{pid, value}])Test plan
mix test— 82 tests, 0 failures