Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Pass ADMIN_CTX when opening dbs
Browse files Browse the repository at this point in the history
COUCHDB-3016
  • Loading branch information
rnewson committed May 10, 2016
1 parent 0b70afb commit 8614279
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mem3_util.erl
Expand Up @@ -78,15 +78,15 @@ attach_nodes([S | Rest], Acc, [Node | Nodes], UsedNodes) ->

open_db_doc(DocId) ->
DbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
{ok, Db} = couch_db:open(DbName, []),
{ok, Db} = couch_db:open(DbName, [?ADMIN_CTX]),
try couch_db:open_doc(Db, DocId, [ejson_body]) after couch_db:close(Db) end.

write_db_doc(Doc) ->
DbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
write_db_doc(DbName, Doc, true).

write_db_doc(DbName, #doc{id=Id, body=Body} = Doc, ShouldMutate) ->
{ok, Db} = couch_db:open(DbName, []),
{ok, Db} = couch_db:open(DbName, [?ADMIN_CTX]),
try couch_db:open_doc(Db, Id, [ejson_body]) of
{ok, #doc{body = Body}} ->
% the doc is already in the desired state, we're done here
Expand All @@ -112,7 +112,7 @@ delete_db_doc(DocId) ->
delete_db_doc(DbName, DocId, true).

delete_db_doc(DbName, DocId, ShouldMutate) ->
{ok, Db} = couch_db:open(DbName, []),
{ok, Db} = couch_db:open(DbName, [?ADMIN_CTX]),
{ok, Revs} = couch_db:open_doc_revs(Db, DocId, all, []),
try [Doc#doc{deleted=true} || {ok, #doc{deleted=false}=Doc} <- Revs] of
[] ->
Expand Down

0 comments on commit 8614279

Please sign in to comment.