Skip to content

Conversation

@shibd
Copy link
Member

@shibd shibd commented Oct 29, 2025

Motivation

The topic stats have a metric: oldestBacklogMessageAgeSeconds, which represents the age in seconds of the earliest backlogged message's AgeSeconds in the topic.

The broker will periodically check each topic to update these metics, and it decides whether to use a precise check or an estimated check based on the PreciseTimeBasedBacklogQuotaCheck configuration.

When PreciseTimeBasedBacklogQuotaCheck=false, the broker will calculate its age based on the close time of the ledger corresponding to the old position.

Because the time can only be obtained when the ledger is closed, if an oldPosition was obtained initially, but afterward, the subscription in the topic is always caught up to the currently open ledger, then it will be skipped every time this oldPosition is updated. (The broker's default interval for updating the oldPosition is 60S, and it is very likely to hit this situation on every check.)

EstimateTimeBasedBacklogQuotaCheckResult checkResult =
estimatedTimeBasedBacklogQuotaCheck(oldestMarkDeletePosition);
if (checkResult.getEstimatedOldestUnacknowledgedMessageTimestamp() != null) {
updateResultIfNewer(
new OldestPositionInfo(
oldestMarkDeleteCursorInfo.getPosition(),
oldestMarkDeleteCursorInfo.getCursor().getName(),
checkResult.getEstimatedOldestUnacknowledgedMessageTimestamp(),
oldestMarkDeleteCursorInfo.getVersion()));
}

This can be very confusing for users using this metric, as the subscription's MarkDeletePosition is at the latest position, but the oldestBacklogMessageAgeSeconds metric keeps increasing.

You can run the backlogsAgeMetricsNoPreciseWithoutBacklogQuota test in this PR to reproduce this situation.

Modifications

When PreciseTimeBasedBacklogQuotaCheck is false, if the oldPosition is on a ledger that is currently open, we should consider that there is no oldPosition at this time and set it to -1.

Verifying this change

  • Added backlogsAgeMetricsNoPreciseWithoutBacklogQuota to cover it.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@shibd shibd self-assigned this Oct 29, 2025
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 29, 2025
@shibd shibd changed the title [fix][broker] BacklogMessageAge is not reset when backlog is on an open ledger [fix][broker] BacklogMessageAge is not reset when cursor mdPosition is on an open ledger Oct 29, 2025
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.26%. Comparing base (5e59d0e) to head (990851f).
⚠️ Report is 42 commits behind head on master.

Files with missing lines Patch % Lines
...sar/broker/service/persistent/PersistentTopic.java 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #24915       +/-   ##
=============================================
+ Coverage     38.45%   74.26%   +35.81%     
- Complexity    13176    33844    +20668     
=============================================
  Files          1855     1913       +58     
  Lines        144926   149329     +4403     
  Branches      16814    17334      +520     
=============================================
+ Hits          55735   110905    +55170     
+ Misses        81668    29574    -52094     
- Partials       7523     8850     +1327     
Flag Coverage Δ
inttests 26.42% <0.00%> (+0.03%) ⬆️
systests 22.83% <0.00%> (+0.07%) ⬆️
unittests 73.79% <0.00%> (+39.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...sar/broker/service/persistent/PersistentTopic.java 79.11% <0.00%> (+26.33%) ⬆️

... and 1414 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Technoboy- Technoboy- added this to the 4.2.0 milestone Oct 29, 2025
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhotari lhotari merged commit 54da0c8 into apache:master Oct 31, 2025
99 of 101 checks passed
lhotari pushed a commit that referenced this pull request Oct 31, 2025
lhotari pushed a commit that referenced this pull request Oct 31, 2025
lhotari pushed a commit that referenced this pull request Oct 31, 2025
lhotari pushed a commit that referenced this pull request Oct 31, 2025
ganesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 3, 2025
…s on an open ledger (apache#24915)

(cherry picked from commit 54da0c8)
(cherry picked from commit f97f365)
manas-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 3, 2025
…s on an open ledger (apache#24915)

(cherry picked from commit 54da0c8)
(cherry picked from commit 60ea33a)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 4, 2025
…s on an open ledger (apache#24915)

(cherry picked from commit 54da0c8)
(cherry picked from commit 60ea33a)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 6, 2025
…s on an open ledger (apache#24915)

(cherry picked from commit 54da0c8)
(cherry picked from commit f97f365)
nodece pushed a commit to nodece/pulsar that referenced this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants