nickva commented on code in PR #5193:
URL: https://github.com/apache/couchdb/pull/5193#discussion_r1726003743
##########
src/mem3/src/mem3_sync.erl:
##########
@@ -302,12 +304,31 @@ sync_push(ShardName, N) ->
gen_server:call(mem3_sync, {push, #job{name = ShardName, node = N}},
infinity).
find_next_node() ->
- LiveNodes = [node() | nodes()],
- AllNodes0 = lists:sort(mem3:nodes()),
- AllNodes1 = [X || X <- AllNodes0, lists:member(X, LiveNodes)],
- AllNodes = AllNodes1 ++ [hd(AllNodes1)],
- [_Self, Next | _] = lists:dropwhile(fun(N) -> N =/= node() end, AllNodes),
- Next.
+ Self = node(),
+ LiveNodes = [Self | nodes()],
+ Mem3Nodes = mem3:nodes(),
+ find_next_node(Self, LiveNodes, Mem3Nodes).
+
+find_next_node(Self, LiveNodes, Mem3Nodes) ->
+ SortedMem3Nodes = lists:sort(Mem3Nodes),
+ LiveMem3Nodes = [N || N <- SortedMem3Nodes, lists:member(N, LiveNodes)],
+ case LiveMem3Nodes of
+ [] ->
+ % No live mem3 nodes. Strange. Return self as we can always
+ % replicate to ourselves, which is just a no-op.
+ Self;
+ [H | _] ->
+ % Append head to the end we have always have a "next"
Review Comment:
Oh definitely, I'll update it. It's very confusingly written.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]