janl commented on code in PR #5371:
URL: https://github.com/apache/couchdb/pull/5371#discussion_r2841461697
##########
src/fabric/src/fabric_doc_update.erl:
##########
@@ -350,6 +377,67 @@ validate_atomic_update(_DbName, AllDocs, true) ->
),
throw({aborted, PreCommitFailures}).
+start_leaders(#acc{} = Acc0) ->
+ #acc{dbname = DbName, grouped_docs = GroupedDocs} = Acc0,
+ {Workers, _} = lists:unzip(GroupedDocs),
+ LeaderRefs = lists:foldl(
+ fun({Worker, Docs}, RefAcc) ->
+ case is_leader(DbName, Worker, Workers) of
+ true ->
+ start_worker(Worker, Docs, Acc0),
+ [Worker#shard.ref | RefAcc];
+ false ->
+ RefAcc
+ end
+ end,
+ [],
+ GroupedDocs
+ ),
+ Acc0#acc{leaders = LeaderRefs, started = LeaderRefs}.
+
+start_followers(Ranges, #acc{} = Acc0) ->
+ Followers = [
+ {Worker, Docs}
+ || {Worker, Docs} <- Acc0#acc.grouped_docs,
+ lists:member(Worker#shard.range, Ranges),
+ not lists:member(Worker#shard.ref, Acc0#acc.started)
+ ],
+ lists:foreach(
+ fun({Worker, Docs}) ->
+ start_worker(Worker, Docs, Acc0)
+ end,
+ Followers
+ ),
+ Started = [Ref || {#shard{ref = Ref}, _Docs} <- Followers],
+ Acc0#acc{started = lists:append([Started, Acc0#acc.started])}.
+
+%% use 'lowest' node that hosts this shard range as leader
Review Comment:
would this mean `[email protected]` would become the de-facto leader
for all writes in a usual 3-node setup? Wouldn’t we want to try to balance this
across all nodes?
--
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]