summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Touzet <wohali@apache.org>2017-07-10 13:52:45 -0700
committerJoan Touzet <wohali@apache.org>2017-07-10 13:52:45 -0700
commit18314a6daa56a13f4b4e6f71ce61224a8940f925 (patch)
treebfeb41c4ab7a9bfe12bddf7ad2cd22810aac078c
parentc38d7aab035bce5f88ed772de59187a39da2768f (diff)
downloadcouchdb-18314a6daa56a13f4b4e6f71ce61224a8940f925.tar.gz
Add support for new ensure_dbs_exist option to GET, POST/finish_cluster
Addresses apache/couchdb:593
-rw-r--r--.gitignore2
-rw-r--r--src/setup.erl24
-rw-r--r--src/setup_httpd.erl9
3 files changed, 23 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 1dbfa4bce..f84f14c93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
ebin
.rebar
+*~
+*.swp
diff --git a/src/setup.erl b/src/setup.erl
index 5a7100491..dd7410aa1 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -12,8 +12,8 @@
-module(setup).
--export([enable_cluster/1, finish_cluster/0, add_node/1, receive_cookie/1]).
--export([is_cluster_enabled/0, has_cluster_system_dbs/0]).
+-export([enable_cluster/1, finish_cluster/1, add_node/1, receive_cookie/1]).
+-export([is_cluster_enabled/0, has_cluster_system_dbs/1, cluster_system_dbs/0]).
-include_lib("../couch/include/couch_db.hrl").
@@ -54,9 +54,6 @@ cluster_system_dbs() ->
["_users", "_replicator", "_global_changes"].
-has_cluster_system_dbs() ->
- has_cluster_system_dbs(cluster_system_dbs()).
-
has_cluster_system_dbs([]) ->
ok;
has_cluster_system_dbs([Db|Dbs]) ->
@@ -172,12 +169,19 @@ set_admin(Username, Password) ->
config:set("admins", binary_to_list(Username), binary_to_list(Password)).
-finish_cluster() ->
- finish_cluster_int(has_cluster_system_dbs()).
-finish_cluster_int(ok) ->
+finish_cluster(Options) ->
+ Dbs = proplists:get_value(ensure_dbs_exist, Options),
+ case Dbs of
+ undefined ->
+ finish_cluster_int(cluster_system_dbs(), has_cluster_system_dbs(cluster_system_dbs()));
+ Dbs ->
+ finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs))
+ end.
+
+finish_cluster_int(_Dbs, ok) ->
{error, cluster_finished};
-finish_cluster_int(no) ->
- lists:foreach(fun fabric:create_db/1, cluster_system_dbs()).
+finish_cluster_int(Dbs, no) ->
+ lists:foreach(fun fabric:create_db/1, Dbs).
add_node(Options) ->
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index a23a3e21d..59ed5c7cd 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -29,11 +29,12 @@ handle_setup_req(#httpd{method='POST'}=Req) ->
end;
handle_setup_req(#httpd{method='GET'}=Req) ->
ok = chttpd:verify_is_server_admin(Req),
+ Dbs = chttpd:qs_json_value(Req, "ensure_dbs_exist", setup:cluster_system_dbs()),
case setup:is_cluster_enabled() of
no ->
chttpd:send_json(Req, 200, {[{state, cluster_disabled}]});
ok ->
- case setup:has_cluster_system_dbs() of
+ case setup:has_cluster_system_dbs(Dbs) of
no ->
chttpd:send_json(Req, 200, {[{state, cluster_enabled}]});
ok ->
@@ -74,7 +75,11 @@ handle_action("enable_cluster", Setup) ->
handle_action("finish_cluster", Setup) ->
couch_log:notice("finish_cluster: ~p~n", [Setup]),
- case setup:finish_cluster() of
+
+ Options = get_options([
+ {ensure_dbs_exist, <<"ensure_dbs_exist">>}
+ ], Setup),
+ case setup:finish_cluster(Options) of
{error, cluster_finished} ->
{error, <<"Cluster is already finished">>};
Else ->