-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Improve async cancellation safety of future::Cache
(v0.12.0-beta.X)
#309
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tatsuya6502
changed the title
Improve async cancellation safety of future::Cache (v0.12.0-beta.X)
Improve async cancellation safety of Aug 23, 2023
future::Cache
(v0.12.0-beta.X)
Update TODO comments.
Make it possible to resume an eviction notification in write operation after cancelling.
tatsuya6502
force-pushed
the
async-cancellation-safety
branch
from
August 26, 2023 11:23
54ab77b
to
4b85133
Compare
Reschedule write op after async cancel.
Refactoring on the `do_insert_with_hash` of `BaseCache`.
Refactoring on the `PendingOp` and `PendingOpGuard`.
Change back to use the same `ReadOp` between `future` and `sync` caches.
- Add unit tests for async cancellations. - Some refactoring.
- Update a unit tests for async cancellations.
tatsuya6502
commented
Aug 27, 2023
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.
Merging.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves async cancellation safety of cache write methods
insert
,get_with
,invalidate
andremove
. It is forfuture::Cache
in v0.12.0-beta.1.The Problem
#294 (comment)
You will be affected by the above if you use
async_eviction_listener
and do async cancellation. For example, some sever frameworks such as Axum do async cancellation for you; request handling will be cancelled when the client connection is dropped.The Solution
This PR addresses the above problem by saving the interrupted tasks to a mpmc channel when async cancellation happens on the following methods:
insert
,get_with
,invalidate
andremove
These interrupted tasks will be resumed/retried when one of the following methods is called:
get
methodrun_pending_tasks
methodThe following interrupted tasks will be saved and resumed/retried:
Future
should be saved.WriteOp
enum) to an internal channel but the channel is full, theWriteOp
should be saved.A Limitation
future::Cache
v0.12.0 or later doesImmediate
notification delivery mode, which guarantees to preserve the order of events on a key. However, if the eviction listener is interrupted by async cancellation and then resumed, the order may not be preserved.Testing the Solution
Added the following unit tests to verify those interrupted tasks are resumed/retried:
cancel_future_while_calling_eviction_listener
cancel_future_while_scheduling_write_op