You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2022/07/01 21:02:53 UTC

[couchdb] branch let-custodian-use-cluster-n created (now ad2dac1b7)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch let-custodian-use-cluster-n
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at ad2dac1b7 Add an option to let custodian always use [cluster] n value

This branch includes the following new commits:

     new ad2dac1b7 Add an option to let custodian always use [cluster] n value

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Add an option to let custodian always use [cluster] n value

Posted by va...@apache.org.
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 <va...@gmail.com>
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"].