Skip to content

Commit

Permalink
Fix case clause error in replicator _scheduler/docs response
Browse files Browse the repository at this point in the history
When a job is completing, there is a period of time when the document isn't
updated yet with the state, and it's also not present in the scheduler ets
table. In that case we return `nil`, but we don't account for that case in the
_scheduler/docs fabric calls.

To fix it, account for `nil` whenever we get the doc state.
  • Loading branch information
nickva committed Mar 17, 2024
1 parent b964a84 commit 77c5418
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/couch_replicator/src/couch_replicator_fabric.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

-include_lib("fabric/include/fabric.hrl").
-include_lib("mem3/include/mem3.hrl").
-include_lib("couch/include/couch_db.hrl").
-include_lib("couch_mrview/include/couch_mrview.hrl").

docs(DbName, Options, QueryArgs, Callback, Acc) ->
Expand Down Expand Up @@ -167,6 +166,9 @@ maybe_fetch_and_filter_doc(Id, undecided, State) ->
{ok, {Props} = DocInfo} ->
DocState = couch_util:get_value(state, Props),
couch_replicator_utils:filter_state(DocState, FilterStates, DocInfo);
{ok, nil} ->
% could have just completed
skip;
{error, not_found} ->
% could have been deleted
skip
Expand Down
5 changes: 4 additions & 1 deletion src/couch_replicator/src/couch_replicator_fabric_rpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
]).

-include_lib("fabric/include/fabric.hrl").
-include_lib("couch/include/couch_db.hrl").
-include_lib("couch_mrview/include/couch_mrview.hrl").

docs(DbName, Options, Args0) ->
Expand Down Expand Up @@ -80,6 +79,10 @@ rep_doc_state(Shard, Id, {[_ | _]} = Doc, States, HealthThreshold) ->
HealthThreshold
)
of
{ok, nil} ->
% Could have been just completed. Let the coordinator
% try to refetch it.
undecided;
{ok, EtsInfo} ->
State = get_doc_state(EtsInfo),
couch_replicator_utils:filter_state(State, States, EtsInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ t_scheduler_docs_total_rows({_Ctx, {RepDb, Source, Target}}) ->
case req(get, SchedulerDocsUrl) of
{200, #{<<"docs">> := [_ | _]} = Decoded} ->
Decoded;
{_, #{<<"error">> := Error, <<"reason">> := Reason}} ->
?debugVal(Error, 100),
?debugVal(binary_to_list(Reason), 100);
{_, #{}} ->
{200, #{<<"docs">> := []}} ->
wait
end
end,
Expand Down

0 comments on commit 77c5418

Please sign in to comment.