Skip to content

Conversation

@massakam
Copy link
Contributor

@massakam massakam commented Mar 9, 2023

Motivation

Topic stats have a msgRateExpired field. Once this value is greater than 0, it may never return to 0, even though no messages have expired. This is because PersistentMessageExpiryMonitor#updateRates() only runs when PersistentMessageExpiryMonitor#expireMessages() is executed, not periodically.

For example, if the number of messages in the backlog of a subscription is 0, the execution of PersistentMessageExpiryMonitor#expireMessages() will be skipped and msgRateExpired will not be updated.

public boolean expireMessages(int messageTTLInSeconds) {
if ((getNumberOfEntriesInBacklog(false) == 0) || (dispatcher != null && dispatcher.isConsumerConnected()
&& getNumberOfEntriesInBacklog(false) < MINIMUM_BACKLOG_FOR_EXPIRY_CHECK
&& !topic.isOldestMessageExpired(cursor, messageTTLInSeconds))) {
// don't do anything for almost caught-up connected subscriptions
return false;
}
this.lastExpireTimestamp = System.currentTimeMillis();
return expiryMonitor.expireMessages(messageTTLInSeconds);
}

As a result, the value of msgRateExpired may remain non-zero even though message expiration has not occurred recently.

Modifications

Call PersistentMessageExpiryMonitor#updateRates() in the PersistentTopic#updateRates() method that runs periodically to update the topic stats.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

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

@massakam massakam added type/bug The PR fixed a bug or issue reported a bug component/stats doc-not-needed Your PR changes do not impact docs ready-to-test labels Mar 9, 2023
@massakam massakam added this to the 3.0.0 milestone Mar 9, 2023
@massakam massakam self-assigned this Mar 9, 2023
@massakam massakam changed the title [fix][stats] Fix issue where msgRateExpired may not refresh forever [fix][broker] Fix issue where msgRateExpired may not refresh forever Mar 9, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #19759 (1db15cf) into master (e973388) will increase coverage by 29.95%.
The diff coverage is 29.16%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #19759       +/-   ##
=============================================
+ Coverage     32.05%   62.01%   +29.95%     
- Complexity     6409    25829    +19420     
=============================================
  Files          1674     1848      +174     
  Lines        126556   135887     +9331     
  Branches      13810    14953     +1143     
=============================================
+ Hits          40570    84264    +43694     
+ Misses        79992    43905    -36087     
- Partials       5994     7718     +1724     
Flag Coverage Δ
inttests 24.57% <25.00%> (+0.02%) ⬆️
systests 25.27% <20.83%> (+<0.01%) ⬆️
unittests 59.19% <25.00%> (+41.85%) ⬆️

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

Impacted Files Coverage Δ
...ker/service/persistent/PersistentSubscription.java 68.55% <15.78%> (+21.84%) ⬆️
...sar/broker/service/persistent/PersistentTopic.java 65.21% <50.00%> (+14.74%) ⬆️
...roker/service/persistent/PersistentReplicator.java 39.24% <100.00%> (+6.02%) ⬆️
...metadata/coordination/impl/LeaderElectionImpl.java 78.20% <100.00%> (+19.49%) ⬆️
...e/pulsar/proxy/server/BrokerDiscoveryProvider.java 76.00% <0.00%> (-8.00%) ⬇️
...sar/broker/resources/MetadataStoreCacheLoader.java 73.68% <0.00%> (-5.27%) ⬇️
...g/apache/pulsar/common/protocol/PulsarHandler.java 56.89% <0.00%> (-1.73%) ⬇️
...in/java/org/apache/pulsar/common/api/AuthData.java 71.42% <0.00%> (ø)
...ava/org/apache/pulsar/client/api/schema/Field.java 80.00% <0.00%> (ø)
...g/apache/pulsar/common/naming/NamespaceBundle.java 60.71% <0.00%> (ø)
... and 1205 more

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