GeezerVison is showing github.com — [fix][broker] Don't share the dispatcher's FilterContext with analyzeBacklog by lifepuzzlefun · Pull Request #20246 · apache/pulsar
Conversation
lifepuzzlefun
commented
May 7, 2023
•
edited by merlimat
Loading
Uh oh!
There was an error while loading. Please reload this page.
Motivation
PersistentSubscription.analyzeBacklog reuses the subscription's dispatcher as its EntryFilterSupport,
and so it reuses the dispatcher's single FilterContext. The scan runs on the cursor read-callback thread,
while the dispatcher fills the same object on the dispatch thread
(EntryFilterSupport.runFiltersForEntry calls reset(), then the setters, then the filters). When the two
overlap, an entry filter can see another entry's metadata or a null consumer. A wrong REJECT during
dispatch is acked by the dispatcher (AbstractBaseDispatcher.filterEntriesForConsumer adds the entry to
entriesToFiltered), so the message is lost.
// PersistentSubscription.analyzeBacklog (before)
final EntryFilterSupport entryFilterSupport = dispatcher != null
? (EntryFilterSupport) dispatcher : new EntryFilterSupport(this);
...
entryFilterSupport.runFiltersForEntry(entry, messageMetadata, null); // dispatcher's filterContext
Modifications
- Add an
EntryFilterSupport.runFiltersForEntry(FilterContext, Entry, MessageMetadata, Consumer) overload.
The existing 3-arg method delegates to it with the dispatcher's own context and stays public.
analyzeBacklog still uses the dispatcher's filters, so the analysis matches what dispatch would do.
It now passes a FilterContext created for that scan. The scan tests one batch at a time
(OpScan.readEntriesComplete → find()), so one context per scan is enough.
- Replaces this PR's original
runFiltersForAnalyzeBacklog plus @NotThreadSafe. jcip is not a dependency
on master. It also drops the change that made runFiltersForEntry protected.
final FilterContext filterContext = new FilterContext();
...
entryFilterSupport.runFiltersForEntry(filterContext, entry, messageMetadata, null);
Verifying this change
FilterEntryTest.testAnalyzeBacklogDoesNotShareDispatcherFilterContext: a topic-level filter records the
FilterContext instances it is given during dispatch and during analyzeSubscriptionBacklog, and the test
asserts the two sets don't share an instance. The existing FilterEntryTest cases, which inject filters into
the dispatcher and check analyzeSubscriptionBacklog results, still hold.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…torImpl` to avoid iterate interceptors only to find AppendIndexMetadataInterceptor
lifepuzzlefun
changed the title
[fix] [broker] Avoid EntryFilterContext being reuse by dispatcher and analyzeBacklog ops
[fix] [broker] Avoid EntryFilterContext misreuse by Dispatcher and analyzeBacklog
May 7, 2023
|
The pr had no activity for 30 days, mark with Stale label.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Keep the dispatcher's entry filters, but don't share its FilterContext
with the analyzeBacklog scan. Replace runFiltersForAnalyzeBacklog and the
jcip annotation with a runFiltersForEntry overload taking the context, and
keep runFiltersForEntry public. Add a regression test.
merlimat
changed the title
[fix] [broker] Avoid EntryFilterContext misreuse by Dispatcher and analyzeBacklog
[fix][broker] Don't share the dispatcher's FilterContext with analyzeBacklog
Oct 23, 2026
|
@lifepuzzlefun thanks for finding this. It's still a real race on master, and a wrong REJECT during dispatch
gets acked. I merged master and reworked the change on your branch: there's now a runFiltersForEntry overload
that takes a caller-owned FilterContext, and analyzeBacklog uses one per scan. That keeps the dispatcher's
filter list, drops the jcip annotation (not on master's classpath), and leaves runFiltersForEntry public.
I also added a regression test. PTAL.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 21, 2026
Reviewers
merlimat
merlimat approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|