This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-6
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit a2f460cab9597949bba4824f1538b9dc7c4b4725
Author: Garren Smith <[email protected]>
AuthorDate: Thu Sep 6 16:11:41 2018 +0200

    validate that a system db cannot be partitioned
---
 src/chttpd/src/chttpd_db.erl | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 7707d12..0bfe040 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -346,6 +346,9 @@ create_db_req(#httpd{}=Req, DbName) ->
         {initial_props, [{partitioned, Partitioned}]}
     ] ++ EngineOpt,
     DocUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)),
+
+    ok = validate_partition_database_create(DbName, Partitioned),
+
     case fabric:create_db(DbName, Options) of
     ok ->
         send_json(Req, 201, [{"Location", DocUrl}], {[{ok, true}]});
@@ -1622,6 +1625,18 @@ extract_header_rev(Req, ExplicitRev) ->
     end.
 
 
+% cannot partition a system database
+validate_partition_database_create(DbName, Partitioned) ->
+    SystemId = DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) orelse
+        lists:member(DbName, ?SYSTEM_DATABASES),
+    case {Partitioned, SystemId} of
+        {true, true} ->
+            throw({bad_request, <<"Cannot partition a system database">>});
+        {_, _} ->
+            ok
+    end.
+
+
 validate_attachment_names(Doc) ->
     lists:foreach(fun(Att) ->
         Name = couch_att:fetch(name, Att),

Reply via email to