Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-zero instance start time #3901

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/chttpd/src/chttpd_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}]),
CreationTime = mem3:shard_creation_time(DbName),
send_json(
Req,
201,
{[
{ok, true},
{instance_start_time, <<"0">>}
{instance_start_time, CreationTime}
]}
);
db_req(#httpd{path_parts = [_, <<"_ensure_full_commit">>]} = Req, _Db) ->
Expand Down
9 changes: 3 additions & 6 deletions src/couch_replicator/src/couch_replicator_scheduler_job.erl
Original file line number Diff line number Diff line change
Expand Up @@ -846,18 +846,15 @@ do_checkpoint(State) ->
end;
{SrcInstanceStartTime, _NewTgtInstanceStartTime} ->
{checkpoint_commit_failure, <<
"Target database out of sync. "
"Try to increase max_dbs_open at the target's server."
"instance_start_time on target database has changed since last checkpoint."
>>};
{_NewSrcInstanceStartTime, TgtInstanceStartTime} ->
{checkpoint_commit_failure, <<
"Source database out of sync. "
"Try to increase max_dbs_open at the source's server."
"instance_start_time on source database has changed since last checkpoint."
>>};
{_NewSrcInstanceStartTime, _NewTgtInstanceStartTime} ->
{checkpoint_commit_failure, <<
"Source and target databases out of "
"sync. Try to increase max_dbs_open at both servers."
"instance_start_time on source and target database has changed since last checkpoint."
>>}
end.

Expand Down
5 changes: 3 additions & 2 deletions src/fabric/src/fabric_db_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

go(DbName) ->
Shards = mem3:shards(DbName),
CreationTime = mem3:shard_creation_time(DbName),
Workers = fabric_util:submit_jobs(Shards, get_db_info, []),
RexiMon = fabric_util:create_monitors(Shards),
Fun = fun handle_message/3,
Expand All @@ -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, CreationTime} | Acc]};
{timeout, {WorkersDict, _, _}} ->
DefunctWorkers = fabric_util:remove_done_workers(
WorkersDict,
Expand Down Expand Up @@ -117,7 +118,7 @@ merge_results(Info) ->
(_K, _V, Acc) ->
Acc
end,
[{instance_start_time, <<"0">>}],
[],
Dict
).

Expand Down
15 changes: 15 additions & 0 deletions src/mem3/src/mem3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
-export([get_placement/1]).
-export([ping/1, ping/2]).
-export([db_is_current/1]).
-export([shard_creation_time/1]).

%% For mem3 use only.
-export([name/1, node/1, range/1, engine/1]).
Expand Down Expand Up @@ -198,6 +199,20 @@ shard_suffix(DbName0) when is_binary(DbName0) ->
shard_suffix(Db) ->
shard_suffix(couch_db:name(Db)).

shard_creation_time(DbName0) ->
Shard = hd(shards(DbName0)),
case Shard#shard.name of
<<"shards/", _:8/binary, "-", _:8/binary, "/", DbName/binary>> ->
case filename:extension(DbName) of
<<".", Time/binary>> ->
Time;
_ ->
<<"0">>
end;
_ ->
<<"0">>
end.

fold_shards(Fun, Acc) ->
mem3_shards:fold(Fun, Acc).

Expand Down