You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2018/09/03 10:18:51 UTC
[couchdb] 01/01: disallow creation of partitioned system db
This is an automated email from the ASF dual-hosted git repository.
garren pushed a commit to branch no-system-db-partition
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 5e6d94d36abada6d1b1fa6d90bb4bf340745a7f0
Author: Garren Smith <ga...@gmail.com>
AuthorDate: Mon Sep 3 11:59:48 2018 +0200
disallow creation of partitioned system db
---
src/chttpd/src/chttpd_db.erl | 14 ++++++++------
src/couch/src/couch_db.erl | 2 ++
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 37289eb..c801252 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -338,7 +338,7 @@ create_db_req(#httpd{}=Req, DbName) ->
Q = chttpd:qs_value(Req, "q", config:get("cluster", "q", "8")),
P = chttpd:qs_value(Req, "placement", config:get("cluster", "placement")),
EngineOpt = parse_engine_opt(Req),
- Partitioned = parse_partitioned_opt(Req),
+ Partitioned = parse_partitioned_opt(Req, DbName),
Options = [
{n, N},
{q, Q},
@@ -1469,13 +1469,15 @@ parse_engine_opt(Req) ->
end.
-parse_partitioned_opt(Req) ->
- case chttpd:qs_value(Req, "partitioned") of
- undefined ->
+parse_partitioned_opt(Req, DbName) ->
+ case {chttpd:qs_value(Req, "partitioned"), couch_db:is_system_db(DbName)} of
+ {undefined, _ } ->
false;
- "true" ->
+ {"true", false} ->
true;
- _ ->
+ {"true", true} ->
+ throw({bad_request, <<"Cannot partition a system database">>});
+ {_, _} ->
throw({bad_request, <<"`partitioned` parameter can only be set to true.">>})
end.
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index a5c71d7..cc11d77 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -183,6 +183,8 @@ is_db(#db{}) ->
is_db(_) ->
false.
+is_system_db(DbName) when is_list(DbName); is_binary(DbName) ->
+ is_systemdb(DbName);
is_system_db(#db{options = Options}) ->
lists:member(sys_db, Options).