diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2020-05-29 16:59:35 -0400 |
---|---|---|
committer | Nick Vatamaniuc <vatamane@apache.org> | 2020-05-29 16:59:35 -0400 |
commit | fda2f45c74d963cb38738e98c1add6725c60e1ce (patch) | |
tree | 6429ac143172d4758e4cba491373e284009d3b8d | |
parent | b9aa2c6b1d2ded7fa1920551b747758e5eebc7bb (diff) | |
download | couchdb-guard-job-accept-against-timeouts.tar.gz |
Guard couch_jobs:accept_loop timing outguard-job-accept-against-timeouts
And also against too many conflicts during overload
-rw-r--r-- | src/couch_jobs/src/couch_jobs.erl | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/couch_jobs/src/couch_jobs.erl b/src/couch_jobs/src/couch_jobs.erl index d9ea0fbfa..adc1b464e 100644 --- a/src/couch_jobs/src/couch_jobs.erl +++ b/src/couch_jobs/src/couch_jobs.erl @@ -297,9 +297,17 @@ accept_loop(Type, NoSched, MaxSchedTime, Timeout) -> TxFun = fun(JTx) -> couch_jobs_fdb:accept(JTx, Type, MaxSchedTime, NoSched) end, - case couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(), TxFun) of + AcceptResult = try + couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(), TxFun) + catch + error:{erlfdb_error, Err} when Err =:= 1020 orelse Err =:= 1031 -> + retry + end, + case AcceptResult of {ok, Job, Data} -> {ok, Job, Data}; + retry -> + accept_loop(Type, NoSched, MaxSchedTime, Timeout); {not_found, PendingWatch} -> case wait_pending(PendingWatch, MaxSchedTime, Timeout) of {error, not_found} -> |