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

Refactor cache_filter to expect caches to post cb #36184

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ravenblackx
Copy link
Contributor

@ravenblackx ravenblackx commented Sep 17, 2024

Commit Message: Refactor cache_filter to expect caches to post cb
Additional Description: This is a bit of an unintuitive change in that it moves some work from the common class to the plugin, meaning that work will be duplicated. However, there's a good reason for this - if the cache class needs to use a dispatcher to get back onto its own thread, having cache_filter also post means that actions end up being queued in the dispatcher twice.

A different possible solution would be to have the cache_filter callbacks only post if the callback comes in on the wrong thread, but there's a wrinkle in that model too - if the callback executes immediately, on the same thread, as was the case with the simple_http_cache, it executes too soon, trying to resume a connection that hasn't yet stopped, which is an error. That, too, could be covered with another workaround, either intercepting when that happens and posting the resume, or intercepting when that happens and replacing the resume with returning Continue instead, but both of those options make the cache filter itself more complicated (and therefore error prone).

Having just one consistent path, where the cache implementation always posts the callback (and never calls it if cancelled), and the cache always performs the callback outside of the initial call's context and on its own thread, is the least complexity, and avoids the performance impact of posting twice, at a cost of a bit more verbosity in the simple cache implementation.

This PR also wraps the UpdateHeadersCallback into a declared type, and makes it an AnyInvocable instead of a std::function, which enforces that callbacks are called only once and that they're moved not copied, avoiding accidental performance drains.

Risk Level: Low; WIP filter, existing tests still pass.
Testing: Existing tests should be covering all cases. Added tests to enforce that all cache implementations' LookupContext correctly posts callback actions, and correctly cancels calling the callback if the context is deleted before the post resolves.
Docs Changes: Code-comments only.
Release Notes: Maybe?
Platform Specific Features: n/a

Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #36184 was opened by ravenblackx.

see: more, trace.

@ravenblackx
Copy link
Contributor Author

/coverage

Copy link

Coverage for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-pr/36184/coverage/index.html

The coverage results are (re-)rendered each time the CI envoy-presubmit (check linux_x64 coverage) job completes.

🐱

Caused by: a #36184 (comment) was created by @ravenblackx.

see: more, trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants