Remove maintenace modes from ushards
Maintenance mode nodes were being served for ushards and this lead to
nodedown errors. We now only serve non-maintenance mode nodes.
COUCHDB-2953
diff --git a/src/mem3.erl b/src/mem3.erl
index 405d7e5..85093cd 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -13,7 +13,7 @@
-module(mem3).
-export([start/0, stop/0, restart/0, nodes/0, node_info/2, shards/1, shards/2,
- choose_shards/2, n/1, n/2, dbname/1, ushards/1]).
+ choose_shards/2, n/1, n/2, dbname/1, ushards/1, get_maintenance_mode/0]).
-export([get_shard/3, local_shards/1, shard_suffix/1, fold_shards/2]).
-export([sync_security/0, sync_security/1]).
-export([compare_nodelists/0, compare_shards/1]).
@@ -80,6 +80,11 @@
node_info(Node, Key) ->
mem3_nodes:get_node_info(Node, Key).
+-spec get_maintenance_mode() -> {node(), Mode::list()}.
+get_maintenance_mode() ->
+ Mode = config:get("couchdb", "maintenance_mode", "false"),
+ {node(), Mode}.
+
-spec shards(DbName::iodata()) -> [#shard{}].
shards(DbName) ->
shards_int(DbName, []).
@@ -126,7 +131,7 @@
-spec ushards(DbName::iodata()) -> [#shard{}].
ushards(DbName) ->
- Nodes = [node()|erlang:nodes()],
+ Nodes = non_maintenance_nodes(),
ZoneMap = zone_map(Nodes),
Shards = ushards(DbName, live_shards(DbName, Nodes, [ordered]), ZoneMap),
mem3_util:downcast(Shards).
@@ -254,6 +259,10 @@
nodes_in_zone(Nodes, Zone) ->
[Node || Node <- Nodes, Zone == mem3:node_info(Node, <<"zone">>)].
+non_maintenance_nodes() ->
+ {Modes, _} = rpc:multicall(mem3, get_maintenance_mode, []),
+ [N || {N, Mode} <- Modes, Mode =:= "false"].
+
live_shards(DbName, Nodes) ->
live_shards(DbName, Nodes, []).
diff --git a/test/mem3_ushards_test.erl b/test/mem3_ushards_test.erl
new file mode 100644
index 0000000..4ee2854
--- /dev/null
+++ b/test/mem3_ushards_test.erl
@@ -0,0 +1,57 @@
+% Licensed 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.
+
+-module(mem3_ushards_test).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("mem3/include/mem3.hrl").
+
+-define(TIMEOUT, 10000).
+
+setup() ->
+ DbName = ?tempdb(),
+ ok = fabric:create_db(DbName, [?ADMIN_CTX]),
+ DbName.
+
+teardown(DbName) ->
+ ok = fabric:delete_db(DbName, [?ADMIN_CTX]).
+
+ushard_test_() ->
+ {
+ "Maintenance node test",
+ {
+ setup,
+ fun() -> test_util:start_couch([mem3]) end,
+ fun test_util:stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun maintenance_mode_true/1,
+ fun maintenance_mode_nolb/1
+ ]
+ }
+ }
+ }.
+
+maintenance_mode_true(DbName) ->
+ config:set("couchdb", "maintenance_mode", "true"),
+ UShards = mem3:ushards(DbName),
+ Nodes = [Node || #shard{node=Node} <- UShards, Node =:= node()],
+ ?_assertEqual([], Nodes).
+
+maintenance_mode_nolb(DbName) ->
+ config:set("couchdb", "maintenance_mode", "nolb"),
+ UShards = mem3:ushards(DbName),
+ Nodes = [Node || #shard{node=Node} <- UShards, Node =:= node()],
+ ?_assertEqual([], Nodes).