mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
## Motivation Currently, `tokio-trace-core` permits `Subscriber`s to indicate that they are "always", "sometimes", or "never" interested in a particular callsite. When "always" or "never" is returned, then the interest is cached and the subscriber will not be asked again about that callsite. This is much more efficient than requiring the filter to be re-evaluated every time the callsite is hit. However, if a subscriber wishes to change its filter configuration dynamically at runtime, it cannot benefit from this caching. Instead, it must always return `Interest::sometimes`. Even when filters change very infrequently, they must still always be re-evaluated every time. In order to support a use-case where subscribers may change their filter configuration at runtime (e.g. tokio-rs/tokio-trace-nursery#42), but do so infrequently, we should introducing a new function to invalidate the cached interest. ## Solution This branch adds a new function in the `callsite` module, called `rebuild_interest_cache`, that will invalidate and rebuild all cached interest. ## Breaking Change In order to fix a race condition that could occur when rebuilding interest caches using `clear_interest` and `add_interest`, these methods have been replaced by a new `set_interest` method. `set_interest` should have the semantics of atomically replacing the previous cached interest, so that the callsite does not enter a temporary state where it has no interest. Closes #1038 Co-Authored-By: yaahallo <[email protected]>