GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@lifepuzzlefun lifepuzzlefun commented May 7, 2023 •
edited by merlimat
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
lifepuzzlefun added 7 commits April 16, 2023 00:34
@lifepuzzlefun
Pin AppendIndexMetadataInterceptor to field in `ManagedLedgerIntercep…
684cf02
…torImpl` to avoid iterate interceptors only to find AppendIndexMetadataInterceptor
@lifepuzzlefun
Merge branch 'master' of https://github.com/apache/pulsar
f20f5a4
@lifepuzzlefun
Merge branch 'master' of https://github.com/apache/pulsar
c052c1e
@lifepuzzlefun
Merge branch 'master' of https://github.com/apache/pulsar
f7d3de0
@lifepuzzlefun
Merge branch 'master' of https://github.com/apache/pulsar
5fd8aa6
@lifepuzzlefun
Merge branch 'master' of https://github.com/apache/pulsar
c9a7078
@lifepuzzlefun
fix analyzeBacklog will miss reset dispatcher's entryFilterContext.
eb70a22
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label May 7, 2023
@lifepuzzlefun 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
@github-actions

github-actions Bot commented Jun 7, 2023

Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the Stale label Jun 7, 2023
@Technoboy- Technoboy- added this to the 3.2.0 milestone Jul 31, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 14, 2024
@coderzc coderzc modified the milestones: 4.1.0, 4.2.0 Sep 1, 2025
merlimat added 2 commits October 22, 2026 20:11
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/adopt-20246-pr
867a350
@merlimat
Use a dedicated FilterContext for the backlog analysis
4dc6365
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 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
@merlimat

merlimat commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

merlimat
merlimat approved these changes Oct 23, 2026
View reviewed changes
@merlimat merlimat modified the milestones: 4.2.0, 5.1.0 Oct 23, 2026
@merlimat
merlimat merged commit 4a2dafb into apache:master Oct 23, 2026
119 of 124 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat merlimat mentioned this pull request Oct 24, 2026
[Bug] EntryFilter seems wrongly filter entry #18178
Closed
2 tasks done
lhotari pushed a commit that referenced this pull request Oct 26, 2026
@lifepuzzlefun @merlimat @lhotari
[fix][broker] Don't share the dispatcher's FilterContext with analyze…
de18aed
…Backlog (#20246)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 4a2dafb)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Oct 26, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lifepuzzlefun @merlimat @lhotari
[fix][broker] Don't share the dispatcher's FilterContext with analyze…
5c52166
…Backlog (apache#20246)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 4a2dafb)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lifepuzzlefun @merlimat @lhotari
[fix][broker] Don't share the dispatcher's FilterContext with analyze…
053405d
…Backlog (apache#20246)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 4a2dafb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 doc-not-needed Your PR changes do not impact docs release/4.0.15 release/4.2.6 release/5.0.2 Stale

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@lifepuzzlefun @merlimat @lhotari @Technoboy- @coderzc
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.