jaydoane commented on a change in pull request #3312:
URL: https://github.com/apache/couchdb/pull/3312#discussion_r555512963



##########
File path: src/weatherreport/src/weatherreport_check_safe_to_rebuild.erl
##########
@@ -0,0 +1,115 @@
+%% -------------------------------------------------------------------
+%%
+%% weatherreport - automated diagnostic tools for CouchDB
+%%
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License.  You may obtain
+%% a copy of the License at
+%%
+%%   http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied.  See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% -------------------------------------------------------------------
+
+%% @doc Diagnostic that checks whether the current node can be
+%% safely rebuilt (i.e. taken out of service).
+-module(weatherreport_check_safe_to_rebuild).
+-behaviour(weatherreport_check).
+
+-export([description/0,
+         valid/0,
+         check/1,
+         format/1]).
+
+-spec description() -> string().
+description() ->
+    "Check whether the node can safely be taken out of service".
+
+-spec valid() -> boolean().
+valid() ->
+    weatherreport_node:can_connect().
+
+%% @doc Check if rebuilding a node is safe. Safe in this context means
+%% that no shard would end up with N<Threshold when the node is offline
+-spec safe_to_rebuild(atom(), integer()) -> [list()].
+safe_to_rebuild(Node, RawThreshold) ->
+    Threshold = case config:get("couchdb", "maintenance_mode") of
+        "true" ->
+            RawThreshold - 1;
+        _ ->
+            RawThreshold
+    end,
+    BelowThreshold = fun
+        ({_, _, {_, C}}) when C =< Threshold -> true;
+        (_) -> false end,
+    ToKV = fun({Db, Range, Status}) -> {[Db, Range], Status} end,
+
+    ShardsInDanger = dict:from_list(
+        lists:map(
+            ToKV,
+            lists:filter(BelowThreshold, custodian:report())

Review comment:
       [Should be 
ok](https://github.com/apache/couchdb/blob/3.x/src/custodian/src/custodian.erl#L17-L18).




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to