couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 03/03: MOAR TMP WIP TMP
Date Sun, 04 Nov 2018 16:20:38 GMT
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 <paul.joseph.davis@gmail.com>
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};


Mime
View raw message