Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Use ADMIN_CTX macro from couch_db.hrl
  • Loading branch information
kxepal committed Jan 26, 2015
1 parent 04345bd commit 3f229b2789587babc8d14db9cf79ad534dac257d
Showing 4 changed files with 9 additions and 18 deletions.
@@ -28,10 +28,6 @@
-include_lib("mem3/include/mem3.hrl").
-include_lib("couch/include/couch_db.hrl").


-define(CTX, #user_ctx{roles = [<<"_admin">>]}).


-record(acc, {
batch_size,
batch_count,
@@ -78,7 +74,7 @@ go(#shard{} = Source, #shard{} = Target, Opts) ->


go(#acc{source=Source, batch_count=BC}=Acc0) ->
case couch_db:open(Source#shard.name, [{user_ctx,?CTX}]) of
case couch_db:open(Source#shard.name, [?ADMIN_CTX]) of
{ok, Db} ->
Acc = Acc0#acc{db=Db},
Resp = try
@@ -271,7 +267,7 @@ find_missing_revs(Acc) ->
end, Infos),
mem3_rpc:get_missing_revs(Node, Name, IdsRevs, [
{io_priority, {internal_repl, Name}},
{user_ctx, ?CTX}
?ADMIN_CTX
]).


@@ -290,7 +286,7 @@ save_on_target(Node, Name, Docs) ->
mem3_rpc:update_docs(Node, Name, Docs, [
replicated_changes,
full_commit,
{user_ctx, ?CTX},
?ADMIN_CTX,
{io_priority, {internal_repl, Name}}
]),
ok.
@@ -35,9 +35,6 @@
-include_lib("couch/include/couch_db.hrl").


-define(CTX, #user_ctx{roles = [<<"_admin">>]}).


get_missing_revs(Node, DbName, IdsRevs, Options) ->
rexi_call(Node, {fabric_rpc, get_missing_revs, [DbName, IdsRevs, Options]}).

@@ -63,7 +60,7 @@ find_common_seq(Node, DbName, SourceUUID, SourceEpochs) ->

load_checkpoint_rpc(DbName, SourceNode, SourceUUID) ->
erlang:put(io_priority, {internal_repl, DbName}),
case couch_db:open_int(DbName, [{user_ctx, ?CTX}]) of
case couch_db:open_int(DbName, [?ADMIN_CTX]) of
{ok, Db} ->
TargetUUID = couch_db:get_uuid(Db),
NewId = mem3_rep:make_local_id(SourceUUID, TargetUUID),
@@ -86,7 +83,7 @@ load_checkpoint_rpc(DbName, SourceNode, SourceUUID) ->

save_checkpoint_rpc(DbName, Id, SourceSeq, NewEntry0, History0) ->
erlang:put(io_priority, {internal_repl, DbName}),
case couch_db:open_int(DbName, [{user_ctx, ?CTX}]) of
case couch_db:open_int(DbName, [?ADMIN_CTX]) of
{ok, #db{update_seq = TargetSeq} = Db} ->
NewEntry = {[
{<<"target_node">>, atom_to_binary(node(), utf8)},
@@ -116,7 +113,7 @@ save_checkpoint_rpc(DbName, Id, SourceSeq, NewEntry0, History0) ->

find_common_seq_rpc(DbName, SourceUUID, SourceEpochs) ->
erlang:put(io_priority, {internal_repl, DbName}),
case couch_db:open_int(DbName, [{user_ctx, ?CTX}]) of
case couch_db:open_int(DbName, [?ADMIN_CTX]) of
{ok, Db} ->
case couch_db:get_uuid(Db) of
SourceUUID ->
@@ -297,8 +297,7 @@ create_if_missing(Name) ->
true ->
ok;
false ->
Options = [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}],
case couch_server:create(Name, Options) of
case couch_server:create(Name, [?ADMIN_CTX]) of
{ok, Db} ->
couch_db:close(Db);
Error ->
@@ -214,12 +214,11 @@ shard_info(DbName) ->
ensure_exists(DbName) when is_list(DbName) ->
ensure_exists(list_to_binary(DbName));
ensure_exists(DbName) ->
Options = [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}],
case couch_db:open(DbName, [nologifmissing, sys_db | Options]) of
case couch_db:open(DbName, [nologifmissing, sys_db | [?ADMIN_CTX]]) of
{ok, Db} ->
{ok, Db};
_ ->
couch_server:create(DbName, Options)
couch_server:create(DbName, [?ADMIN_CTX])
end.


0 comments on commit 3f229b2

Please sign in to comment.