diff options
author | Garren Smith <garren.smith@gmail.com> | 2018-09-06 16:11:41 +0200 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-09-17 21:21:16 +0100 |
commit | 56c9c442622eb4fe2960f0157c00367f4b576af7 (patch) | |
tree | b504cf8668867f171a0be97e84bf5667d4d653a5 | |
parent | 9ccb6593abf274eabb90a3d7b4010debaa58f44d (diff) | |
download | couchdb-56c9c442622eb4fe2960f0157c00367f4b576af7.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 d6f27f44f..9dab4b5bd 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}]}); @@ -1628,6 +1631,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), |