summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-08-01 10:14:32 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-08-01 10:19:12 -0500
commitd6e856d45c64ee52560f40ee055d1b94d3f80e82 (patch)
treef191f0d4a35411355ab738f43b1a5f9ab46dce54
parent9ff8fa1fad512b3ecfa867db6a9c82e16446f8b0 (diff)
downloadcouchdb-d6e856d45c64ee52560f40ee055d1b94d3f80e82.tar.gz
Fix job handling to halt on errors
If the indexing job has timed out and has been requed we need to exit the current indexer. This ensures the errors are logged so that we can keep an eye on failing jobs.
-rw-r--r--src/couch_views/src/couch_views_indexer.erl28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/couch_views/src/couch_views_indexer.erl b/src/couch_views/src/couch_views_indexer.erl
index a3179369c..edee332f3 100644
--- a/src/couch_views/src/couch_views_indexer.erl
+++ b/src/couch_views/src/couch_views_indexer.erl
@@ -72,7 +72,7 @@ init() ->
update(#{} = Db, Mrst0, State0) ->
- {Mrst2, State3} = fabric2_fdb:transactional(Db, fun(TxDb) ->
+ {Mrst2, State4} = fabric2_fdb:transactional(Db, fun(TxDb) ->
% In the first iteration of update we need
% to populate our db and view sequences
State1 = case State0 of
@@ -107,8 +107,8 @@ update(#{} = Db, Mrst0, State0) ->
report_progress(State2, finished),
{Mrst1, finished};
false ->
- report_progress(State2, update),
- {Mrst1, State2#{
+ State3 = report_progress(State2, update),
+ {Mrst1, State3#{
tx_db := undefined,
count := 0,
doc_acc := [],
@@ -117,11 +117,11 @@ update(#{} = Db, Mrst0, State0) ->
end
end),
- case State3 of
+ case State4 of
finished ->
couch_query_servers:stop_doc_map(Mrst2#mrst.qserver);
_ ->
- update(Db, Mrst2, State3)
+ update(Db, Mrst2, State4)
end.
@@ -229,7 +229,7 @@ start_query_server(#mrst{} = Mrst) ->
report_progress(State, UpdateType) ->
#{
tx_db := TxDb,
- job := Job,
+ job := Job1,
job_data := JobData,
last_seq := LastSeq
} = State,
@@ -251,9 +251,21 @@ report_progress(State, UpdateType) ->
case UpdateType of
update ->
- couch_jobs:update(TxDb, Job, NewData);
+ case couch_jobs:update(TxDb, Job1, NewData) of
+ {ok, Job2} ->
+ State#{job := Job2};
+ {error, halt} ->
+ couch_log:error("~s job halted :: ~w", [?MODULE, Job1]),
+ exit(normal)
+ end;
finished ->
- couch_jobs:finish(TxDb, Job, NewData)
+ case couch_jobs:finish(TxDb, Job1, NewData) of
+ ok ->
+ State;
+ {error, halt} ->
+ couch_log:error("~s job halted :: ~w", [?MODULE, Job1]),
+ exit(normal)
+ end
end.