summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-02-17 11:39:28 -0500
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-02-17 15:37:21 -0500
commite18fe7c4a4e24a8e1efaea9cc2287c0c0aa5bd1b (patch)
tree760207f11fff32ff319ee8391ac1753172ffbd36
parent7408d8950a59a8c9e8577e71daae64c2daaf5107 (diff)
downloadcouchdb-e18fe7c4a4e24a8e1efaea9cc2287c0c0aa5bd1b.tar.gz
Handle possibly missing local _users db in mem3_sync:local_dbs()
After commit 27bb45043435828915bdcbdc130b685e5533bbd8 local _users is only created the first time it is used. So in most case it's expected to not exist. Update local_dbs to return it only if it is actually created.
-rw-r--r--src/mem3/src/mem3_sync.erl7
-rw-r--r--src/mem3/test/eunit/mem3_seeds_test.erl16
2 files changed, 20 insertions, 3 deletions
diff --git a/src/mem3/src/mem3_sync.erl b/src/mem3/src/mem3_sync.erl
index 8170f3c1a..cfed6a445 100644
--- a/src/mem3/src/mem3_sync.erl
+++ b/src/mem3/src/mem3_sync.erl
@@ -302,7 +302,12 @@ remove_entries(Dict, Entries) ->
end, Dict, Entries).
local_dbs() ->
- [nodes_db(), shards_db(), users_db()].
+ UsersDb = users_db(),
+ % users db might not have been created so don't include it unless it exists
+ case couch_server:exists(UsersDb) of
+ true -> [nodes_db(), shards_db(), UsersDb];
+ false -> [nodes_db(), shards_db()]
+ end.
nodes_db() ->
?l2b(config:get("mem3", "nodes_db", "_nodes")).
diff --git a/src/mem3/test/eunit/mem3_seeds_test.erl b/src/mem3/test/eunit/mem3_seeds_test.erl
index ba83b66be..ac32282bf 100644
--- a/src/mem3/test/eunit/mem3_seeds_test.erl
+++ b/src/mem3/test/eunit/mem3_seeds_test.erl
@@ -18,7 +18,8 @@ a_test_() ->
Tests = [
{"empty seedlist should set status ok", fun empty_seedlist_status_ok/0},
{"all seedlist nodes unreachable keeps status seeding", fun seedlist_misconfiguration/0},
- {"seedlist entries should be present in _nodes", fun check_nodelist/0}
+ {"seedlist entries should be present in _nodes", fun check_nodelist/0},
+ {"optional local _users db in mem3_sync:local_dbs()", fun check_local_dbs/0}
],
{setup, fun setup/0, fun teardown/1, Tests}.
@@ -57,10 +58,21 @@ check_nodelist() ->
cleanup()
end.
+check_local_dbs() ->
+ ?assertEqual([<<"_dbs">>, <<"_nodes">>],
+ lists:sort(mem3_sync:local_dbs())),
+ {ok, _} = couch_server:create(<<"_users">>, []),
+ ?assertEqual([<<"_dbs">>, <<"_nodes">>, <<"_users">>],
+ lists:sort(mem3_sync:local_dbs())).
+
cleanup() ->
application:stop(mem3),
Filename = config:get("mem3", "nodes_db", "_nodes") ++ ".couch",
- file:delete(filename:join([?BUILDDIR(), "tmp", "data", Filename])).
+ file:delete(filename:join([?BUILDDIR(), "tmp", "data", Filename])),
+ case config:get("couch_httpd_auth", "authentication_db") of
+ undefined -> ok;
+ DbName -> couch_server:delete(list_to_binary(DbName), [])
+ end.
setup() ->
test_util:start_couch([rexi]).