summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-10-25 16:13:48 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-01-18 13:03:28 -0600
commit3ff043ec484f4d966c1eaa9eb60dd677a7e9ed36 (patch)
tree619337ffa9c4bd09568f3705097942a244a3fd59
parent24a36985498035e586a81ac8fd5035e5e1e98f07 (diff)
downloadcouchdb-3ff043ec484f4d966c1eaa9eb60dd677a7e9ed36.tar.gz
Implement `fabric_util:open_cluster_db`
This allows for more fine grained use of couch_db:clustered_db as well as chagnes the name to something more appropriate than `fake_db`.
-rw-r--r--src/fabric/src/fabric.erl2
-rw-r--r--src/fabric/src/fabric_doc_update.erl8
-rw-r--r--src/fabric/src/fabric_util.erl15
3 files changed, 18 insertions, 7 deletions
diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 9bc99c265..092553f2b 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -383,7 +383,7 @@ query_view(DbName, Options, DDoc, ViewName, Callback, Acc0, QueryArgs0) ->
Db = dbname(DbName), View = name(ViewName),
case fabric_util:is_users_db(Db) of
true ->
- FakeDb = fabric_util:fake_db(Db, Options),
+ FakeDb = fabric_util:open_cluster_db(DbName, Options),
couch_users_db:after_doc_read(DDoc, FakeDb);
false ->
ok
diff --git a/src/fabric/src/fabric_doc_update.erl b/src/fabric/src/fabric_doc_update.erl
index b7a27bb4a..c108c9a32 100644
--- a/src/fabric/src/fabric_doc_update.erl
+++ b/src/fabric/src/fabric_doc_update.erl
@@ -104,13 +104,13 @@ handle_message({request_entity_too_large, Entity}, _, _) ->
before_doc_update(DbName, Docs, Opts) ->
case {fabric_util:is_replicator_db(DbName), fabric_util:is_users_db(DbName)} of
{true, _} ->
- %% fake db is expensive to create so we only do it if we have to
- Db = fabric_util:fake_db(DbName, Opts),
+ %% cluster db is expensive to create so we only do it if we have to
+ Db = fabric_util:open_cluster_db(DbName, Opts),
[couch_replicator_docs:before_doc_update(Doc, Db, replicated_changes)
|| Doc <- Docs];
{_, true} ->
- %% fake db is expensive to create so we only do it if we have to
- Db = fabric_util:fake_db(DbName, Opts),
+ %% cluster db is expensive to create so we only do it if we have to
+ Db = fabric_util:open_cluster_db(DbName, Opts),
[couch_users_db:before_doc_update(Doc, Db, interactive_edit)
|| Doc <- Docs];
_ ->
diff --git a/src/fabric/src/fabric_util.erl b/src/fabric/src/fabric_util.erl
index cc1f1b622..f1bc23ad0 100644
--- a/src/fabric/src/fabric_util.erl
+++ b/src/fabric/src/fabric_util.erl
@@ -17,7 +17,8 @@
remove_down_workers/2, doc_id_and_rev/1]).
-export([request_timeout/0, attachments_timeout/0, all_docs_timeout/0]).
-export([log_timeout/2, remove_done_workers/2]).
--export([is_users_db/1, is_replicator_db/1, fake_db/2]).
+-export([is_users_db/1, is_replicator_db/1]).
+-export([open_cluster_db/1, open_cluster_db/2]).
-export([upgrade_mrargs/1]).
-compile({inline, [{doc_id_and_rev,1}]}).
@@ -214,7 +215,17 @@ is_users_db(DbName) ->
path_ends_with(Path, Suffix) ->
Suffix =:= couch_db:dbname_suffix(Path).
-fake_db(DbName, Opts) ->
+open_cluster_db(#shard{dbname = DbName, opts = Options}) ->
+ case couch_util:get_value(props, Options) of
+ Props when is_list(Props) ->
+ {ok, Db} = couch_db:clustered_db(DbName, [{props, Props}]),
+ Db;
+ _ ->
+ {ok, Db} = couch_db:clustered_db(DbName, []),
+ Db
+ end.
+
+open_cluster_db(DbName, Opts) ->
{SecProps} = fabric:get_security(DbName), % as admin
UserCtx = couch_util:get_value(user_ctx, Opts, #user_ctx{}),
{ok, Db} = couch_db:clustered_db(DbName, UserCtx, SecProps),