summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@gmail.com>2022-07-01 17:00:05 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2022-07-05 15:28:54 -0400
commite41465ec852be4f97685309b4644e796395ada74 (patch)
tree122b6203aa2c87a217df3f38adb48279c1e88902
parenteb2f8d998779246b3847d2ba4341837926ec9f4b (diff)
downloadcouchdb-e41465ec852be4f97685309b4644e796395ada74.tar.gz
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_expected_n = true` can help detect cases 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.
-rw-r--r--rel/overlay/etc/default.ini10
-rw-r--r--src/custodian/src/custodian_util.erl9
2 files changed, 18 insertions, 1 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index cefd9e493..71c0d59d9 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_expected_n = false
diff --git a/src/custodian/src/custodian_util.erl b/src/custodian/src/custodian_util.erl
index 866bcacb1..41f51507d 100644
--- a/src/custodian/src/custodian_util.erl
+++ b/src/custodian/src/custodian_util.erl
@@ -87,7 +87,11 @@ 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_expected_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 +175,9 @@ get_n_rings(N, Ranges, Rings) ->
cluster_n() ->
config:get_integer("cluster", "n", 3).
+cluster_n_is_expected_n() ->
+ config:get_boolean("custodian", "use_cluster_n_as_expected_n", false).
+
maintenance_nodes(Nodes) ->
{Modes, _} = rpc:multicall(Nodes, config, get, ["couchdb", "maintenance_mode"]),
[N || {N, Mode} <- lists:zip(Nodes, Modes), Mode =:= "true"].