You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2022/01/16 16:00:46 UTC
[couchdb] branch nonzero_instance_start_time updated: Non-zero instance_start_time
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch nonzero_instance_start_time
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/nonzero_instance_start_time by this push:
new 6b4e5e5 Non-zero instance_start_time
6b4e5e5 is described below
commit 6b4e5e5552d1cf073c5b87782e87610051daaf44
Author: Robert Newson <rn...@apache.org>
AuthorDate: Sun Jan 16 15:58:55 2022 +0000
Non-zero instance_start_time
Set instance_start_time to the creation time of the database to
restore the ability for the replicator to detect a db recreation event
during a replication. Without this, a replication can fail to notice
the db was deleted and recreated, write the checkpoint document for
the in-progress replication and keep going, whereas what should happen
is the replication should reset from sequence 0.
---
src/chttpd/src/chttpd_db.erl | 3 ++-
src/fabric/src/fabric_db_info.erl | 5 +++--
src/mem3/include/mem3.hrl | 2 ++
src/mem3/src/mem3_util.erl | 3 +++
4 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 875df6e..ff2203a 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -554,12 +554,13 @@ db_req(
%% for missing databases that'd return error 404 from chttpd
%% get_security used to prefer shards on the same node over other nodes
fabric:get_security(DbName, [{user_ctx, Ctx}]),
+ #shard{suffix = Suffix} = hd(mem3:shards(DbName)),
send_json(
Req,
201,
{[
{ok, true},
- {instance_start_time, <<"0">>}
+ {instance_start_time, Suffix}
]}
);
db_req(#httpd{path_parts = [_, <<"_ensure_full_commit">>]} = Req, _Db) ->
diff --git a/src/fabric/src/fabric_db_info.erl b/src/fabric/src/fabric_db_info.erl
index 2366420..1f49958 100644
--- a/src/fabric/src/fabric_db_info.erl
+++ b/src/fabric/src/fabric_db_info.erl
@@ -19,6 +19,7 @@
go(DbName) ->
Shards = mem3:shards(DbName),
+ #shard{suffix = Suffix} = hd(mem3:shards(DbName)),
Workers = fabric_util:submit_jobs(Shards, get_db_info, []),
RexiMon = fabric_util:create_monitors(Shards),
Fun = fun handle_message/3,
@@ -28,7 +29,7 @@ go(DbName) ->
try
case fabric_util:recv(Workers, #shard.ref, Fun, Acc0) of
{ok, Acc} ->
- {ok, Acc};
+ {ok, [{instance_start_time, Suffix} | Acc]};
{timeout, {WorkersDict, _, _}} ->
DefunctWorkers = fabric_util:remove_done_workers(
WorkersDict,
@@ -117,7 +118,7 @@ merge_results(Info) ->
(_K, _V, Acc) ->
Acc
end,
- [{instance_start_time, <<"0">>}],
+ [],
Dict
).
diff --git a/src/mem3/include/mem3.hrl b/src/mem3/include/mem3.hrl
index d97b254..97dbca5 100644
--- a/src/mem3/include/mem3.hrl
+++ b/src/mem3/include/mem3.hrl
@@ -22,6 +22,7 @@
dbname :: binary() | 'undefined',
range :: [non_neg_integer() | '$1' | '$2'] | '_' | 'undefined',
ref :: reference() | '_' | 'undefined',
+ suffix :: binary(),
opts :: list() | 'undefined'
}).
@@ -33,6 +34,7 @@
range :: [non_neg_integer() | '$1' | '$2'] | '_',
ref :: reference() | 'undefined' | '_',
order :: non_neg_integer() | 'undefined' | '_',
+ suffix :: binary(),
opts :: list()
}).
diff --git a/src/mem3/src/mem3_util.erl b/src/mem3/src/mem3_util.erl
index 8547fc0..b39d365 100644
--- a/src/mem3/src/mem3_util.erl
+++ b/src/mem3/src/mem3_util.erl
@@ -228,6 +228,7 @@ build_shards_by_node(DbName, DocProps) ->
dbname = DbName,
node = to_atom(Node),
range = [Beg, End],
+ suffix = list_to_binary(Suffix),
opts = get_shard_opts(DocProps)
},
Suffix
@@ -255,6 +256,7 @@ build_shards_by_range(DbName, DocProps) ->
node = to_atom(Node),
range = [Beg, End],
order = Order,
+ suffix = list_to_binary(Suffix),
opts = get_shard_opts(DocProps)
},
Suffix
@@ -370,6 +372,7 @@ downcast(#ordered_shard{} = S) ->
dbname = S#ordered_shard.dbname,
range = S#ordered_shard.range,
ref = S#ordered_shard.ref,
+ suffix = S#ordered_shard.suffix,
opts = S#ordered_shard.opts
};
downcast(Shards) when is_list(Shards) ->