Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Make sure mem3_rep autocreates target shards
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 94ebe26b12374552bcd6b4b7b493bf66c8053d22
Showing 1 changed file with 7 additions and 3 deletions.
@@ -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),
@@ -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)},
@@ -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 ->
@@ -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").

0 comments on commit 94ebe26

Please sign in to comment.