nickva commented on code in PR #5371:
URL: https://github.com/apache/couchdb/pull/5371#discussion_r1904462444
##########
src/fabric/src/fabric_doc_update.erl:
##########
@@ -292,18 +336,94 @@ group_docs_by_shard(DbName, Docs) ->
)
).
-append_update_replies([], [], DocReplyDict) ->
+%% use 'lowest' node that hosts this shard range as leader
+is_leader(Worker, Workers) ->
+ Worker == lists:min([W || W <- Workers, W#shard.range ==
Worker#shard.range]).
+
+start_leaders(#acc{} = Acc0) ->
+ #acc{grouped_docs = GroupedDocs} = Acc0,
+ {Workers, _} = lists:unzip(GroupedDocs),
+ Started = lists:foldl(
+ fun({Worker, Docs}, RefAcc) ->
+ case is_leader(Worker, Workers) of
+ true ->
+ start_worker(Worker, Docs, Acc0),
+ [Worker#shard.ref | RefAcc];
+ false ->
+ RefAcc
+ end
+ end,
+ [],
+ GroupedDocs
+ ),
+ Acc0#acc{started = lists:append([Started, Acc0#acc.started])}.
+
+start_followers(#shard{} = Leader, #acc{} = Acc0) ->
+ Followers = [
+ {Worker, _Docs}
Review Comment:
Tiny nit: since we're using `_Docs` variable to construct the result
element, don't use an underscore, use the plain name: `Docs`. I always think of
underscored variable as completely throw-away matches which they aren't in this
case
--
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]