Просмотр исходного кода

Move broadcasting to cluster to single process to avoid issues with ordering guarantees.

Roberto Ostinelli 3 лет назад
Родитель
Сommit
a9c2045b91
1 измененных файлов с 8 добавлено и 14 удалено
  1. 8 14
      src/syn_gen_scope.erl

+ 8 - 14
src/syn_gen_scope.erl

@@ -33,8 +33,8 @@
     call/3, call/4
 ]).
 -export([
-    broadcast/2, broadcast/3,
-    broadcast_all_cluster/2,
+    broadcast/2,
+    broadcast/3,
     send_to_node/3
 ]).
 
@@ -121,10 +121,6 @@ broadcast(Message, State) ->
 broadcast(Message, ExcludedNodes, #state{multicast_pid = MulticastPid} = State) ->
     MulticastPid ! {broadcast, Message, ExcludedNodes, State}.
 
--spec broadcast_all_cluster(Message :: term(), #state{}) -> any().
-broadcast_all_cluster(Message, #state{multicast_pid = MulticastPid} = State) ->
-    MulticastPid ! {broadcast_all_cluster, Message, State}.
-
 -spec send_to_node(RemoteNode :: node(), Message :: term(), #state{}) -> any().
 send_to_node(RemoteNode, Message, #state{process_name = ProcessName}) ->
     {ProcessName, RemoteNode} ! Message.
@@ -296,10 +292,14 @@ handle_info(Info, #state{handler = Handler} = State) ->
     {stop, Reason :: term(), #state{}}.
 handle_continue(after_init, #state{
     handler = Handler,
-    scope = Scope
+    scope = Scope,
+    process_name = ProcessName
 } = State) ->
     error_logger:info_msg("SYN[~s<~s>] Discovering the cluster", [Handler, Scope]),
-    broadcast_all_cluster({'3.0', discover, self()}, State),
+    %% broadcasting is done in the scope process to avoid issues with ordering guarantees
+    lists:foreach(fun(RemoteNode) ->
+        {ProcessName, RemoteNode} ! {'3.0', discover, self()}
+    end, nodes()),
     {noreply, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -333,12 +333,6 @@ multicast_loop() ->
             end, maps:keys(NodesMap) -- ExcludedNodes),
             multicast_loop();
 
-        {broadcast_all_cluster, Message, #state{process_name = ProcessName}} ->
-            lists:foreach(fun(RemoteNode) ->
-                {ProcessName, RemoteNode} ! Message
-            end, nodes()),
-            multicast_loop();
-
         terminate ->
             terminated
     end.