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

Abort HTTP retry if we stop the peer #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 21 additions & 11 deletions src/onyx/plugin/http_output.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:exception (pr-str e)}]))))


(defn process-message [message success? post-process ack-fn async-exception-fn retry-params]
(defn process-message [message success? post-process ack-fn async-exception-fn retry-params run-state]
"Retry params:
- allow-retry? - if we will retry or not
- initial-request-time - time of first request
Expand All @@ -62,11 +62,15 @@
(ack-fn))

next-backoff-ms
(do
(log/debugf "Backing off HTTP request: %S %s %.30s next retry in %d ms"
(name method) url args next-backoff-ms)
(Thread/sleep next-backoff-ms)
(d/recur (inc attempt)))
(if @run-state
(do
(log/debugf "Backing off HTTP request: %S %s %.30s next retry in %d ms"
(name method) url args next-backoff-ms)
(Thread/sleep next-backoff-ms)
(d/recur (inc attempt)))
(do
(log/warnf "Aborting HTTP %s request to %s due to stopped peer" (name method) url)
(async-exception-fn response)))

:else
(async-exception-fn response))))))))
Expand All @@ -77,10 +81,16 @@

(deftype HttpOutput [success? post-process retry-params
^:unsynchronized-mutable async-exception-info
^:unsynchronized-mutable in-flight-writes]
^:unsynchronized-mutable in-flight-writes
run-state]
p/Plugin
(start [this event] this)
(stop [this event] this)
(start [this event]
(reset! run-state true)
this)

(stop [this event]
(reset! run-state false)
this)

p/BarrierSynchronization
(synced? [this epoch]
Expand Down Expand Up @@ -112,7 +122,7 @@
(run! (fn [message]
(swap! in-flight-writes inc)
(process-message message
success? post-process ack-fn async-exception-fn retry))
success? post-process ack-fn async-exception-fn retry run-state))
write-batch))
true))

Expand All @@ -132,4 +142,4 @@
::post-process-default))
retry-params (:http-output/retry-params task-map)
retry-params (assoc retry-params :allow-retry? (some? retry-params))]
(->HttpOutput success? post-process retry-params (atom nil) (atom 0))))
(->HttpOutput success? post-process retry-params (atom nil) (atom 0) (atom false))))