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

Commit

Permalink
Make sure mem3_rep autocreates target shards
Browse files Browse the repository at this point in the history
The change to our fancier history entries introduced a regression that
internal replication wouldn't automatically create the target shards.
This fixes the issue by adding a get_or_create_db/2 in mem3_rep and
switches the use of couch_db:open_int/2 to that function.
  • Loading branch information
davisp authored and iilyak committed May 18, 2016
1 parent 8614279 commit 94ebe26
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mem3_rpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,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, [?ADMIN_CTX]) of
case get_or_create_db(DbName, [?ADMIN_CTX]) of
{ok, Db} ->
TargetUUID = couch_db:get_uuid(Db),
NewId = mem3_rep:make_local_id(SourceUUID, TargetUUID),
Expand All @@ -83,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, [?ADMIN_CTX]) of
case get_or_create_db(DbName, [?ADMIN_CTX]) of
{ok, #db{update_seq = TargetSeq} = Db} ->
NewEntry = {[
{<<"target_node">>, atom_to_binary(node(), utf8)},
Expand Down Expand Up @@ -113,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, [?ADMIN_CTX]) of
case get_or_create_db(DbName, [?ADMIN_CTX]) of
{ok, Db} ->
case couch_db:get_uuid(Db) of
SourceUUID ->
Expand Down Expand Up @@ -275,6 +275,10 @@ rexi_call(Node, MFA) ->
end.


get_or_create_db(DbName, Options) ->
couch_db:open_int(DbName, [{create_if_missing, true} | Options]).


-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

Expand Down

0 comments on commit 94ebe26

Please sign in to comment.