diff options
author | Garren Smith <garren.smith@gmail.com> | 2018-09-06 16:11:41 +0200 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-09-07 16:37:33 +0100 |
commit | a2f460cab9597949bba4824f1538b9dc7c4b4725 (patch) | |
tree | 3e521274e240f617330b0920ff9ab9655df5e5cc | |
parent | ab7e854d68d8981aac3d91f50ef43eeb83afda20 (diff) | |
download | couchdb-a2f460cab9597949bba4824f1538b9dc7c4b4725.tar.gz |
validate that a system db cannot be partitioned
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 15 |
1 files changed, 15 insertions, 0 deletions
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), |