summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-06-03 12:40:24 -0400
committerNick Vatamaniuc <vatamane@apache.org>2020-06-03 12:52:04 -0400
commitfe164850bd5ae25754be8a055e303e866aeb7947 (patch)
tree662ad54ceb3b06c8d7cc2e3b15fd519a29279adc
parentb417bc1ef75115f9766822559dec91ce43e21b74 (diff)
downloadcouchdb-fix-couch-jobs-no-sched-accept-timeout.tar.gz
Fix couch_jobs accept timeout when no_schedule option is usedfix-couch-jobs-no-sched-accept-timeout
When waiting to accept jobs and scheduling was used, timeout is limited based on the time scheduling parameter. When no_schedule option is used, time scheduling parameter is set to 0 always, and so in that case, we have to special-case the limit to return `infinity`. Later on when we wait for the watch to fire, the actual timeout can still be limited, by a separate user specified timeout option, but if user specifies `infinity` there and sets `#{no_schedule => true}` then we should respect and never return `{error, not_found}` in response.
-rw-r--r--src/couch_jobs/src/couch_jobs.erl19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/couch_jobs/src/couch_jobs.erl b/src/couch_jobs/src/couch_jobs.erl
index 5f79407c5..88b4bf470 100644
--- a/src/couch_jobs/src/couch_jobs.erl
+++ b/src/couch_jobs/src/couch_jobs.erl
@@ -311,7 +311,7 @@ accept_loop(Type, NoSched, MaxSchedTime, Timeout) ->
retry ->
accept_loop(Type, NoSched, MaxSchedTime, Timeout);
{not_found, PendingWatch} ->
- case wait_pending(PendingWatch, MaxSchedTime, Timeout) of
+ case wait_pending(PendingWatch, MaxSchedTime, Timeout, NoSched) of
{error, not_found} ->
{error, not_found};
retry ->
@@ -326,14 +326,14 @@ job(Type, JobId) ->
#{job => true, type => Type, id => JobId}.
-wait_pending(PendingWatch, _MaxSTime, 0) ->
+wait_pending(PendingWatch, _MaxSTime, _UserTimeout = 0, _NoSched) ->
erlfdb:cancel(PendingWatch, [flush]),
{error, not_found};
-wait_pending(PendingWatch, MaxSTime, UserTimeout) ->
+wait_pending(PendingWatch, MaxSTime, UserTimeout, NoSched) ->
NowMSec = erlang:system_time(millisecond),
Timeout0 = max(?MIN_ACCEPT_WAIT_MSEC, MaxSTime * 1000 - NowMSec),
- Timeout = min(limit_timeout(Timeout0), UserTimeout),
+ Timeout = min(limit_timeout(Timeout0, NoSched), UserTimeout),
try
erlfdb:wait(PendingWatch, [{timeout, Timeout}]),
ok
@@ -348,7 +348,7 @@ wait_pending(PendingWatch, MaxSTime, UserTimeout) ->
wait_any(Subs, Timeout0, ResendQ) when is_list(Subs) ->
- Timeout = limit_timeout(Timeout0),
+ Timeout = limit_timeout(Timeout0, false),
receive
{?COUCH_JOBS_EVENT, Ref, Type, Id, State, Data0} = Msg ->
case lists:keyfind(Ref, 2, Subs) of
@@ -365,7 +365,7 @@ wait_any(Subs, Timeout0, ResendQ) when is_list(Subs) ->
wait_any(Subs, State, Timeout0, ResendQ) when
is_list(Subs) ->
- Timeout = limit_timeout(Timeout0),
+ Timeout = limit_timeout(Timeout0, false),
receive
{?COUCH_JOBS_EVENT, Ref, Type, Id, MsgState, Data0} = Msg ->
case lists:keyfind(Ref, 2, Subs) of
@@ -385,10 +385,13 @@ wait_any(Subs, State, Timeout0, ResendQ) when
end.
-limit_timeout(Timeout) when is_integer(Timeout), Timeout < 16#FFFFFFFF ->
+limit_timeout(_Timeout, true) ->
+ infinity;
+
+limit_timeout(Timeout, false) when is_integer(Timeout), Timeout < 16#FFFFFFFF ->
Timeout;
-limit_timeout(_Timeout) ->
+limit_timeout(_Timeout, false) ->
infinity.