Repository: couchdb-mem3 Updated Branches: refs/heads/master f20843714 -> deed2f0eb
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 Project: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/commit/deed2f0e Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/tree/deed2f0e Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/diff/deed2f0e Branch: refs/heads/master Commit: deed2f0eb15d634a643312e71e343c1e19e1b07e Parents: f208437 Author: Tony Sun <tony....@cloudant.com> Authored: Wed Feb 24 12:38:25 2016 -0800 Committer: Tony Sun <tony....@cloudant.com> Committed: Thu Feb 25 11:26:56 2016 -0800 ---------------------------------------------------------------------- src/mem3.erl | 13 ++++++++-- test/mem3_ushards_test.erl | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/deed2f0e/src/mem3.erl ---------------------------------------------------------------------- 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 @@ nodes() -> 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 @@ shards_int(DbName, DocId, Options) -> -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 @@ allowed_nodes() -> 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, []). http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/deed2f0e/test/mem3_ushards_test.erl ---------------------------------------------------------------------- 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).