Skip to content

Commit f337ac6

Browse files
committed
Postpone joining cluster until Supervisor registers itself
1 parent 53f073d commit f337ac6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/nebulex_local_multilevel_adapter/sidecar.ex

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,29 @@ defmodule NebulexLocalMultilevelAdapter.Sidecar do
1616
# Trap exit signals to run cleanup job
1717
_ = Process.flag(:trap_exit, true)
1818

19+
{:ok, adapter_meta, {:continue, :join_cluster}}
20+
end
21+
22+
@impl true
23+
def handle_continue(:join_cluster, adapter_meta) do
24+
join_cluster(adapter_meta)
25+
end
26+
27+
@impl true
28+
def handle_info(:join_cluster, adapter_meta) do
29+
join_cluster(adapter_meta)
30+
end
31+
32+
def join_cluster(adapter_meta) do
33+
_ = Nebulex.Cache.Registry.lookup(adapter_meta.name)
34+
1935
# Ensure joining the cluster only when the cache supervision tree is started
2036
:ok = Cluster.join(adapter_meta.name)
21-
22-
{:ok, adapter_meta}
37+
{:noreply, adapter_meta}
38+
rescue
39+
ArgumentError ->
40+
Process.send_after(self(), :join_cluster, 50)
41+
{:noreply, adapter_meta}
2342
end
2443

2544
@impl true

test/clustered_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ defmodule NebulexLocalMultilevelAdapter.ClusteredTest do
1717
]}
1818
])
1919

20+
wait_until(fn ->
21+
Enum.all?([Cache.Isolated, Cache.Connected], fn cache ->
22+
[_, _, _] = Nebulex.Cache.Cluster.get_nodes(cache)
23+
end)
24+
end)
25+
2026
on_exit(fn ->
2127
:ok = Process.sleep(100)
2228
stop_caches(node_pid_list)

0 commit comments

Comments
 (0)