-
Notifications
You must be signed in to change notification settings - Fork 190
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
[in-progress] Protect datalog cache from early cancellation #657
base: main
Are you sure you want to change the base?
Conversation
View Vercel preview at instant-www-js-dont-cancel-jsv.vercel.app. |
@@ -342,23 +347,112 @@ | |||
;; ------ | |||
;; datalog cache | |||
|
|||
(defn swap-datalog-cache-delay! [conn app-id datalog-query delayed-call] | |||
(defn swap-datalog-cache! [conn app-id datalog-query-fn ctx datalog-query] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 I salute you sir.
;; We added it, so we must execute it | ||
(let [stmt-tracker (sql/make-top-level-statement-tracker) | ||
result-promise (:promise @result-delay) | ||
work-fut (binding [ua/*child-vfutures* nil ;; Move future to a new "call-stack" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, bind + statement-tracker makes for a really powerful abstraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful work @dwwoelfel !
q))] | ||
@started | ||
(future-cancel f1) | ||
(is (instance? java.lang.InterruptedException (deref err 100 :timeout))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, so err
is taking more than 100ms to deliver. 🤔
This prevents in-progress datalog queries from getting cancelled when there are multiple sessions waiting on the query.
Previously, we could get into a situation like this:
This PR moves the query execution to a separate call stack where it won't get canceled if the parent is canceled.
To keep the behavior where we cancel queries that exceed the
handle-receive-timeout-ms
, we add another future that is in the call stack. If it gets canceled and there are no other threads waiting on the query, then it will cancel the query.