Skip to content

Conversation

@zjxxzjwang
Copy link
Contributor

@zjxxzjwang zjxxzjwang commented Nov 24, 2025

Motivation

Currently, Pulsar Broker lacks a metric to track instances where delayed messages exceed their TTL. This results in messages set with delayed delivery times exceeding the TTL expiring before being consumed by users, with no mechanism to detect this occurrence. Consequently, there is a significant risk of message loss.

Modifications

  1. Add a new member variable Rate exceedTTLDelayMessage = new Rate() to PersistentTopic to track the number of delayed messages exceeding the TTL.
  2. Within the message sending logic of handleSend, add a check specifically for delayed messages whose delay time exceeds the TTL. If exceeded, call exceedTTLDelayMessage.recordEvent().
  3. In TopicStatsImpl, add the exceedTTLDelayMessages variable to retrieve and display the count of delayed messages exceeding the TTL.

Documentation

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

@zjxxzjwang zjxxzjwang changed the title [improver][broker]Increase the number of delayed messages sent whose delay time exceeds the TTL statistical metric [improve][broker]Increase the number of delayed messages sent whose delay time exceeds the TTL statistical metric Nov 24, 2025
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 24, 2025
Copy link
Contributor

@Denovo1998 Denovo1998 left a comment

Choose a reason for hiding this comment

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

Left some comments.

@zjxxzjwang
Copy link
Contributor Author

@Denovo1998 Hello, could you please help me review again

@zjxxzjwang
Copy link
Contributor Author

@Denovo1998 Hello, could you please help me review again

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.

Please check the review comments.
In addition, please revisit the PR title. It's currently [improve][broker]Increase the number of delayed messages sent whose delay time exceeds the TTL statistical metric which is not very clear. Something like [improve][broker] Add counter to topic stats for delayed messages which exceed TTL at publish time would be more accurate.

@zjxxzjwang zjxxzjwang changed the title [improve][broker]Increase the number of delayed messages sent whose delay time exceeds the TTL statistical metric [improve][broker] Add counter to topic stats for delayed messages which exceed TTL at publish time Jan 13, 2026
@zjxxzjwang
Copy link
Contributor Author

@lhotari Hello, I have made the modifications. Can you help me review them

Comment on lines +4802 to +4804
headersAndPayload.markReaderIndex();
MessageMetadata msgMetadata = Commands.parseMessageMetadata(headersAndPayload);
headersAndPayload.resetReaderIndex();
Copy link
Member

Choose a reason for hiding this comment

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

One side-effect of this change is that the message metadata would get parsed when TTL is set. It has a small performance overhead compared to the previous behavior. Therefore, it would be useful to be able to disable this feature completely.

@lhotari
Copy link
Member

lhotari commented Jan 14, 2026

Currently, Pulsar Broker lacks a metric to track instances where delayed messages exceed their TTL. This results in messages set with delayed delivery times exceeding the TTL expiring before being consumed by users, with no mechanism to detect this occurrence. Consequently, there is a significant risk of message loss.

The implementation doesn't seem to match the goal of the change ("track instances where delayed messages exceed their TTL").
It currently target the case where the message has already been expired when it gets published. How common is that case? What TTL value are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants