-
Notifications
You must be signed in to change notification settings - Fork 579
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
fix(lru): correctly handle future cancellation #3911
Conversation
Signed-off-by: Alex Chi <[email protected]>
Need test before merging. |
@@ -766,25 +768,33 @@ impl<K: LruKey + Clone, T: LruValue> LruCache<K, T> { | |||
) -> Result<Result<CachableEntry<K, T>, E>, RecvError> | |||
where | |||
F: FnOnce() -> VC, |
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.
Seems async closure is unnecessary? We only need a future here. cc @Little-Wallace
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.
It's necessary. There's some variables that only need to be computed when cache miss. See other parts of the PR for more information.
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.
e.g. we need to call self.meta_path
to compute the meta path ONLY when cache miss. But &self
is not 'static
, so we can only compute it in this FnOnce closure and outside the Future + 'static
.
This would possibly fix TPC-H Q18. |
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.
Great work! Thanks!
ref #2580 |
Can you add some UTs for cancellation safety? |
Signed-off-by: Alex Chi <[email protected]>
You may add later. My test in #3907 cannot work because now block cache requires tokio runtime. |
Signed-off-by: Alex Chi <[email protected]>
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.
LGTM
} | ||
}, | ||
LookupResult::Miss => { | ||
let this = self.clone(); |
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.
could we rewrite it as
let ret = tokio::spawn(fetch_value).await;
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.
Nope. fetch_value itself is not 'static. The future it returns is 'static.
Signed-off-by: Alex Chi <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #3911 +/- ##
==========================================
+ Coverage 73.86% 73.88% +0.01%
==========================================
Files 818 818
Lines 115615 115638 +23
==========================================
+ Hits 85404 85441 +37
+ Misses 30211 30197 -14
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
* fix(lru): correctly handle future cancellation Signed-off-by: Alex Chi <[email protected]> * fix test blocking Signed-off-by: Alex Chi <[email protected]> * fix failpoints test Signed-off-by: Alex Chi <[email protected]> * fix clippy Signed-off-by: Alex Chi <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: Alex Chi [email protected]
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
As title.
lookup_dedup
will now spawn a task in the background, so that it won't deadlock.Example: We have two futures running.
If we run them in the following way:
Therefore, we spawn a tokio task in the background for every in-flight request, so that it won't be cancelled by users.
This PR also fixes some unit tests, so that they won't stuck in single-thread tokio runtime.
Checklist
./risedev check
(or alias,./risedev c
)Documentation
If your pull request contains user-facing changes, please specify the types of the changes, and create a release note. Otherwise, please feel free to remove this section.
Types of user-facing changes
Please keep the types that apply to your changes, and remove those that do not apply.
Release note
Please create a release note for your changes. In the release note, focus on the impact on users, and mention the environment or conditions where the impact may occur.
Refer to a related PR or issue link (optional)
close #3909
close #3907
close #2580