Skip to content

Commit

Permalink
Rename first adapter in the pool for backwards compatability (#169)
Browse files Browse the repository at this point in the history
Pubsub v2.0 expects there to be a single process for the process group
named `Elixir.my_pubsub.Adapter`.

v2.1 added pools, which means that the processes are supervised with a
supervisor called `Elixir.my_pubsub.Adapter` along with n processes
named `Elixir.my_pubsub.Adapter_n` where n is the pool size.

This commit changes the supervisor name to
`Elixir.my_pubsub.Adapter_supervisor`
and renames pool item 1 to be `Elixir.my_pubsub.Adapter`. This will
allow backwards compatability with v2.0 when the pool size is set to 1.
  • Loading branch information
Gazler authored Apr 5, 2022
1 parent a2138f5 commit 421ef02
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/phoenix/pubsub/pg2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ defmodule Phoenix.PubSub.PG2 do
name = Keyword.fetch!(opts, :name)
pool_size = Keyword.get(opts, :pool_size, 1)
adapter_name = Keyword.fetch!(opts, :adapter_name)
Supervisor.start_link(__MODULE__, {name, adapter_name, pool_size}, name: adapter_name)
Supervisor.start_link(__MODULE__, {name, adapter_name, pool_size}, name: :"#{adapter_name}_supervisor")
end

@impl true
def init({name, adapter_name, pool_size}) do
groups =
[_ | groups] =
for number <- 1..pool_size do
:"#{adapter_name}_#{number}"
end

# Use `adapter_name` for the first in the pool for backwards compatability
# with v2.0 when the pool_size is 1.
groups = [adapter_name | groups]

:persistent_term.put(adapter_name, List.to_tuple(groups))

children =
Expand Down

0 comments on commit 421ef02

Please sign in to comment.