You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/07/04 19:30:39 UTC
[couchdb] branch master updated: Also enable node decom using
string "true"
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push:
new 409ea97 Also enable node decom using string "true"
409ea97 is described below
commit 409ea971d8272adbc3d4d51b42df698d0dfb9d32
Author: Jay Doane <ja...@gmail.com>
AuthorDate: Tue Jul 4 12:10:20 2017 -0700
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.
---
src/mem3/src/mem3.erl | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl
index 405d7e5..4127802 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.
--
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].