Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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
  • Loading branch information
Tony Sun committed Feb 25, 2016
1 parent f208437 commit deed2f0eb15d634a643312e71e343c1e19e1b07e
Showing 2 changed files with 68 additions and 2 deletions.
@@ -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, []).

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

0 comments on commit deed2f0

Please sign in to comment.