Skip to content

Conversation

@poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Jan 20, 2023

Motivation

In the PR #9302, the property backlog size of each subscription returned in the response of the API topics stats, by default this property is always equal to 0 in response, and this will confuse users. Since the calculation of backlog size is done in broker memory, there is no significant overhead(the process is described in the following section), so I think the correct values should be displayed by default.

Discuss in mail list

The following two APIs should be affected:

In Pulsar admin API

pulsar-admin topics stats persistent://test-tenant/ns1/tp1
--get-subscription-backlog-size
pulsar-admin topics stats persistent://test-tenant/ns1/tp1 -sbs

the default value of parameter --get-subscription-backlog-size will be true

In Pulsar Rest API

curl GET "http://127.0.0.1:8080/test-tenant/ns1/tp1/stats?subscriptionBacklogSize=true"

the default value of the parameter subscriptionBacklogSize will be true

The following is the process of calculating backlog size:

  • Divide PersistentTopc.ledgers into two parts according to the ledgerId of the mark delete position of the cursor. The second part is ledgers indicating the messages still need to be consumed, aka backlogSizeInLedgers.
  • Find the LedgerInfo whose ledgerId is the same as the ledgerId of the mark delete position of the cursor, and we can also divide the ledger into two parts, the second part is entries indicating the messages still need to be consumed, multiply the average size of each entry in metrics by the number of still need to be consumed entries we can get the backlog size in this ledger. aka backlogSizeInEntries.
  • backlogSizeInLedgers + backlogSizeInEntries

Modifications

  • Make the default value of param "--get-subscription-backlog-size" of admin API "topics stats" true
  • Make the attribute 'backlogSize' in the response to be -1 when -sbs is false, for distinguish whether --get-subscription-backlog-size is set to true

Documentation

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

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jan 20, 2023
Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

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

LGTM, the calculation uses the data in memory, no IO operations, and maybe we can return -1 when the option param --get-subscription-backlog-size is false.

@poorbarcode poorbarcode force-pushed the discuss/get_subscription_backlog_size branch from a11a246 to 7f572b3 Compare January 23, 2023 05:22
@poorbarcode
Copy link
Contributor Author

@gaoran10

the calculation uses the data in memory, no IO operations, and maybe we can return -1 when the option param --get-subscription-backlog-size is false.

Good idea. Already make the attribute 'backlogSize' in the response to be -1 when if -sbs is false. Please take a look again

@poorbarcode poorbarcode requested a review from gaoran10 January 23, 2023 05:26
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2023

Codecov Report

Merging #19302 (7f572b3) into master (457a0d5) will increase coverage by 1.40%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #19302      +/-   ##
============================================
+ Coverage     63.54%   64.94%   +1.40%     
- Complexity     3615    26379   +22764     
============================================
  Files          1895     1818      -77     
  Lines        137475   133776    -3699     
  Branches      15091    14692     -399     
============================================
- Hits          87355    86885     -470     
+ Misses        42240    39107    -3133     
+ Partials       7880     7784      -96     
Flag Coverage Δ
inttests 24.91% <100.00%> (+0.73%) ⬆️
systests 25.68% <100.00%> (-0.18%) ⬇️
unittests 62.28% <100.00%> (+0.70%) ⬆️

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

Impacted Files Coverage Δ
...pache/pulsar/broker/admin/v2/PersistentTopics.java 75.44% <ø> (-0.08%) ⬇️
...in/java/org/apache/pulsar/admin/cli/CmdTopics.java 82.33% <ø> (+1.96%) ⬆️
...mon/policies/data/stats/SubscriptionStatsImpl.java 74.74% <ø> (ø)
...ker/service/persistent/PersistentSubscription.java 69.93% <100.00%> (+1.33%) ⬆️
...g/apache/pulsar/client/api/ServiceUrlProvider.java 0.00% <0.00%> (-100.00%) ⬇️
.../apache/pulsar/websocket/data/ConsumerCommand.java 0.00% <0.00%> (-100.00%) ⬇️
...lsar/websocket/admin/v1/WebSocketProxyStatsV1.java 0.00% <0.00%> (-100.00%) ⬇️
...apache/pulsar/broker/web/MaxRequestSizeFilter.java 0.00% <0.00%> (-82.36%) ⬇️
...pache/pulsar/broker/tools/GenerateDocsCommand.java 0.00% <0.00%> (-77.28%) ⬇️
...ava/org/apache/pulsar/broker/tools/BrokerTool.java 0.00% <0.00%> (-71.43%) ⬇️
... and 262 more

@codelipenghui codelipenghui merged commit e417fe7 into apache:master Jan 28, 2023
poorbarcode added a commit that referenced this pull request Feb 27, 2023
…backlog-size of admin API topics stats true (#19302)

(cherry picked from commit e417fe7)
@eolivelli
Copy link
Contributor

@poorbarcode this is a breaking change.
We should not commit it to released branches.

@eolivelli
Copy link
Contributor

cc @codelipenghui

@michaeljmarshall
Copy link
Member

I agree, this is a change in a default, we should not cherry pick it.

michaeljmarshall added a commit that referenced this pull request Feb 27, 2023
…ription-backlog-size of admin API topics stats true (#19302)"

This reverts commit 3095b6a.
michaeljmarshall added a commit that referenced this pull request Feb 27, 2023
…ription-backlog-size of admin API topics stats true (#19302)"

This reverts commit a863e7d.
@poorbarcode
Copy link
Contributor Author

@eolivelli @michaeljmarshall

Thanks for checking my mistakes

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.

8 participants