Skip to content

Commit ec47ecf

Browse files
MB-50712: Correct max possible replica count for bucket
If we are rack aware, i.e. have more than one rack configured, the max replicas possible are the minimum number of nodes each node in a server-group can replicate to. A node 'n1' in a server-group 'sg1' can replicate to (NumTotalNodes - NumServerGroupNodes) Nodes. Where NumServerGroupNodes are the number of nodes in server-group sg1. Change-Id: Ic6aeee71a69bd3ed4105e6424d21e287d06baae5 Reviewed-on: https://review.couchbase.org/c/ns_server/+/175371 Well-Formed: Restriction Checker Well-Formed: Build Bot <[email protected]> Tested-by: Hareen Kancharla <[email protected]> Reviewed-by: Steve Watanabe <[email protected]>
1 parent b3810da commit ec47ecf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/menelaus_web_buckets.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ init_bucket_validation_context(IsNew, BucketName, AllBuckets,
476476
MaxReplicas =
477477
case ns_cluster_membership:rack_aware(KvServerGroups) of
478478
true ->
479-
min(length(KvServerGroups), NumKvNodes) - 1;
479+
ns_cluster_membership:get_max_replicas(NumKvNodes,
480+
KvServerGroups);
480481
false ->
481482
NumKvNodes - 1
482483
end,

src/ns_cluster_membership.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
should_run_service/2,
8181
should_run_service/3,
8282
user_friendly_service_name/1,
83-
json_service_name/1]).
83+
json_service_name/1,
84+
get_max_replicas/2]).
8485

8586
fetch_snapshot(Txn) ->
8687
Snapshot =
@@ -198,6 +199,12 @@ get_nodes_server_groups(Nodes, Groups) ->
198199
end
199200
end, Groups).
200201

202+
get_max_replicas(NumKvNodes, KvServerGroups) ->
203+
lists:foldl(fun (Group, MaxReplicas) ->
204+
NumGroupNodes = length(proplists:get_value(nodes, Group)),
205+
min(MaxReplicas, NumKvNodes - NumGroupNodes)
206+
end, NumKvNodes - 1, KvServerGroups).
207+
201208
system_joinable() ->
202209
nodes_wanted() =:= [node()].
203210

0 commit comments

Comments
 (0)