This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch let-custodian-use-cluster-n in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit ad2dac1b7dfd252050d5445f2b47afd940c6a213 Author: Nick Vatamaniuc <[email protected]> AuthorDate: Fri Jul 1 17:00:05 2022 -0400 Add an option to let custodian always use [cluster] n value In cases when the application prevents creating dbs with non-default n values (n=1, n=2) setting `[custodian] use_cluster_n_as_max_n = true` can help detect case when the shard map itself was manpulated and by mistake ended up with less than `[cluster] n` copies for some ranges. By default the behavior is unchanged and n value will be deduced from the number of copies indicated in the shard map documents. --- rel/overlay/etc/default.ini | 10 ++++++++++ src/custodian/src/custodian_util.erl | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index cefd9e493..20da085bb 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -753,3 +753,13 @@ port = {{prometheus_port}} ; to disable this setting could be if the views need an upgrade but located on ; read-only file system. ;commit_on_header_upgrade = true + +[custodian] +; When set to `true`, force using `[cluster] n` values as the expected n value +; of of shard copies. In cases where the application prevents creating +; non-default n databases, this could help detect case where the shard map was +; altered by hand, or via an external tools, such that it doesn't have the +; necessary number of copies for some ranges. By default, when the setting is +; `false`, the expected n value is based on the number of available copies in +; the shard map. +;use_cluster_n_as_max_n = false \ No newline at end of file diff --git a/src/custodian/src/custodian_util.erl b/src/custodian/src/custodian_util.erl index 866bcacb1..0672d4885 100644 --- a/src/custodian/src/custodian_util.erl +++ b/src/custodian/src/custodian_util.erl @@ -87,7 +87,10 @@ fold_dbs(Id, Shards, State) -> IsLive = fun(#shard{node = N}) -> lists:member(N, State#state.live) end, LiveShards = lists:filter(IsLive, Shards), SafeShards = lists:filter(IsSafe, Shards), - TargetN = mem3_util:calculate_max_n(Shards), + TargetN = case cluster_n_is_max_n() of + true -> cluster_n(); + false -> mem3_util:calculate_max_n(Shards) + end, Acc0 = State#state.acc, Acc1 = case mem3_util:calculate_max_n(LiveShards) of @@ -171,6 +174,9 @@ get_n_rings(N, Ranges, Rings) -> cluster_n() -> config:get_integer("cluster", "n", 3). +cluster_n_is_max_n() -> + config:get_boolean("custodian", "use_cluster_n_as_max_n", false). + maintenance_nodes(Nodes) -> {Modes, _} = rpc:multicall(Nodes, config, get, ["couchdb", "maintenance_mode"]), [N || {N, Mode} <- lists:zip(Nodes, Modes), Mode =:= "true"].
