From 6f5b82a7765b24d3ecaf403bc6f06618eb0a80f0 Mon Sep 17 00:00:00 2001 From: Garren Smith Date: Thu, 6 Sep 2018 16:11:41 +0200 Subject: 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 7707d1203..0bfe0404e 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), -- cgit v1.2.1