summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jay.s.doane@gmail.com>2017-07-04 12:10:20 -0700
committerNick Vatamaniuc <nickva@users.noreply.github.com>2017-07-04 15:30:37 -0400
commit409ea971d8272adbc3d4d51b42df698d0dfb9d32 (patch)
tree83d48757675804d340544517fde9f289cb207c39
parenta5b87955287a8ebf4c81d9bfbbfaff6091e53f58 (diff)
downloadcouchdb-409ea971d8272adbc3d4d51b42df698d0dfb9d32.tar.gz
Also enable node decom using string "true"
To decom a node, one normally inserts {"decom":true} into that node's document via the admin /nodes endpoint. However, it's easy to accidentally insert {"decom":"true"} instead, in which case the current mem3 allowed_nodes logic will include that node as allowed, which is probably not what was intended, and ultimately result in "500 badard" errors sent to the client. This changes the allowed_nodes algorithm to also accept {"decom":"true"} to decom a node. Thanks to Nick Vatamaniuc for discovering this shortcoming.
-rw-r--r--src/mem3/src/mem3.erl35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl
index 405d7e5fa..41278025b 100644
--- a/src/mem3/src/mem3.erl
+++ b/src/mem3/src/mem3.erl
@@ -249,7 +249,10 @@ range(<<"shards/", Start:8/binary, "-", End:8/binary, "/", _/binary>>) ->
httpd_util:hexlist_to_integer(binary_to_list(End))].
allowed_nodes() ->
- [Node || Node <- mem3:nodes(), mem3:node_info(Node, <<"decom">>) =/= true].
+ lists:filter(fun(Node) ->
+ Decom = mem3:node_info(Node, <<"decom">>),
+ (Decom =/= true) andalso (Decom =/= <<"true">>)
+ end, mem3:nodes()).
nodes_in_zone(Nodes, Zone) ->
[Node || Node <- Nodes, Zone == mem3:node_info(Node, <<"zone">>)].
@@ -306,3 +309,33 @@ name(#shard{name=Name}) ->
Name;
name(#ordered_shard{name=Name}) ->
Name.
+
+
+-ifdef(TEST).
+
+-include_lib("eunit/include/eunit.hrl").
+
+-define(ALLOWED_NODE, 'node1@127.0.0.1').
+
+allowed_nodes_test_() ->
+ {"allowed_nodes test", [{
+ setup,
+ fun () ->
+ Props = [
+ {?ALLOWED_NODE, []},
+ {'node2@127.0.0.1', [{<<"decom">>,<<"true">>}]},
+ {'node3@127.0.0.1', [{<<"decom">>,true}]}],
+ ok = meck:expect(mem3_nodes, get_nodelist,
+ fun() -> proplists:get_keys(Props) end),
+ ok = meck:expect(mem3_nodes, get_node_info,
+ fun(Node, Key) ->
+ couch_util:get_value(Key, proplists:get_value(Node, Props))
+ end)
+ end,
+ fun (_) -> meck:unload() end,
+ [
+ ?_assertMatch([?ALLOWED_NODE], allowed_nodes())
+ ]
+ }]}.
+
+-endif.