From commits-return-35102-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Sun Nov 4 17:20:37 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0DFCB180789 for ; Sun, 4 Nov 2018 17:20:36 +0100 (CET) Received: (qmail 30893 invoked by uid 500); 4 Nov 2018 16:20:36 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 30661 invoked by uid 99); 4 Nov 2018 16:20:36 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Nov 2018 16:20:36 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 5F3A8829CF; Sun, 4 Nov 2018 16:20:35 +0000 (UTC) Date: Sun, 04 Nov 2018 16:20:38 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 03/03: MOAR TMP WIP TMP MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: davisp@apache.org In-Reply-To: <154134843513.23215.6979358405685717645@gitbox.apache.org> References: <154134843513.23215.6979358405685717645@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/feature/user-partitioned-databases-davisp X-Git-Reftype: branch X-Git-Rev: 6b7ea3a1b7ad944d9c8df13630d6cc1fd91ca522 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20181104162035.5F3A8829CF@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch feature/user-partitioned-databases-davisp in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 6b7ea3a1b7ad944d9c8df13630d6cc1fd91ca522 Author: Paul J. Davis AuthorDate: Sun Nov 4 10:20:23 2018 -0600 MOAR TMP WIP TMP --- src/couch/src/couch_partition.erl | 32 ++++++++++++++++++++++++++++++++ src/couch/src/couch_server.erl | 5 +++++ src/fabric/src/fabric_db_create.erl | 1 + 3 files changed, 38 insertions(+) diff --git a/src/couch/src/couch_partition.erl b/src/couch/src/couch_partition.erl index e9a7880..7b8e711 100644 --- a/src/couch/src/couch_partition.erl +++ b/src/couch/src/couch_partition.erl @@ -18,6 +18,7 @@ from_docid/1, is_member/2, + validate_dbname/1, validate_docid/1, validate_partition/1, @@ -25,6 +26,9 @@ ]). +-include_lib("couch/include/couch_db.hrl"). + + extract(Value) when is_binary(Value) -> case binary:split(Value, <<":">>) of [Partition, Rest] -> @@ -55,6 +59,34 @@ is_member(DocId, Partition) -> end. +validate_dbname(DbName) when is_list(DbName) -> + validate_dbname(?l2b(DbName)); +validate_dbname(DbName) when is_binary(DbName) -> + DbsDbName = config:get("mem3", "shards_db", "_dbs"), + NodesDbName = config:get("mem3", "nodes_db", "_nodes"), + UsersDbSuffix = config:get("couchdb", "users_db_suffix", "_users"), + Suffix = couch_db:dbname_suffix(DbName), + + SysDbNames = [ + iolist_to_binary(DbsDbName), + iolist_to_binary(NodesDbName) + | ?SYSTEM_DATABASES + ], + + Suffices = [ + <<"_replicator">>, + <<"_users">>, + iolist_to_binary(UsersDbSuffix) + ], + + IsSysDb = lists:member(DbName, SysDbNames) + orelse lists:member(Suffix, Suffices), + + if not IsSysDb -> ok; true -> + throw({bad_request, <<"Cannot partition a system database">>}) + end. + + validate_docid(<<"_design/", _/binary>>) -> ok; validate_docid(<<"_local/", _/binary>>) -> diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl index 95892fc..6defbb1 100644 --- a/src/couch/src/couch_server.erl +++ b/src/couch/src/couch_server.erl @@ -116,6 +116,11 @@ close_lru() -> create(DbName, Options0) -> Options = maybe_add_sys_db_callbacks(DbName, Options0), + Props = couch_util:get_value(props, Options, []), + Partitioned = couch_util:get_value(partitioned, Props, false), + if not Partitioned -> ok; true -> + couch_partition:validate_dbname(DbName) + end, case gen_server:call(couch_server, {create, DbName, Options}, infinity) of {ok, Db0} -> Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}), diff --git a/src/fabric/src/fabric_db_create.erl b/src/fabric/src/fabric_db_create.erl index 2ea3d7b..ff45b33 100644 --- a/src/fabric/src/fabric_db_create.erl +++ b/src/fabric/src/fabric_db_create.erl @@ -23,6 +23,7 @@ go(DbName, Options) -> case validate_dbname(DbName, Options) of ok -> + couch_partition:validate_dbname(DbName), case db_exists(DbName) of true -> {error, file_exists};