Explorar el Código

chore(router): attempt to make code more readable

Andrew Mayorov hace 1 año
padre
commit
7c64630803
Se han modificado 1 ficheros con 7 adiciones y 2 borrados
  1. 7 2
      apps/emqx/src/emqx_router_helper.erl

+ 7 - 2
apps/emqx/src/emqx_router_helper.erl

@@ -336,20 +336,25 @@ choose_timeout(Baseline) ->
 
 
 %%
 %%
 
 
+-spec am_core() -> boolean().
 am_core() ->
 am_core() ->
     mria_config:whoami() =/= replicant.
     mria_config:whoami() =/= replicant.
 
 
+-spec cores() -> [node()].
 cores() ->
 cores() ->
     %% Include stopped nodes as well.
     %% Include stopped nodes as well.
     mria_membership:nodelist().
     mria_membership:nodelist().
 
 
+-spec pick_responsible(_Task) -> node().
 pick_responsible(Task) ->
 pick_responsible(Task) ->
     %% Pick a responsible core node.
     %% Pick a responsible core node.
     %% We expect the same node to be picked as responsible across the cluster (unless
     %% We expect the same node to be picked as responsible across the cluster (unless
     %% the cluster is highly turbulent).
     %% the cluster is highly turbulent).
     Nodes = lists:sort(mria_membership:running_core_nodelist()),
     Nodes = lists:sort(mria_membership:running_core_nodelist()),
-    N = length(Nodes),
-    N > 0 andalso lists:nth(1 + erlang:phash2(Task, N), Nodes).
+    case length(Nodes) of
+        0 -> node();
+        N -> lists:nth(1 + erlang:phash2(Task, N), Nodes)
+    end.
 
 
 %%
 %%