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 — [improve][broker][PIP-379] Add observability stats for "draining hashes" by lhotari · Pull Request #23429 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Oct 10, 2024

Copy link
Copy Markdown
Member

Motivation

PIP-379: Key_Shared Draining Hashes for Improved Message Ordering was implemented in #23352.

One of the major benefits of PIP-379 is the easy-to-understand model of when a hash is blocked.

When a new consumer is added, hash range assignments move from existing consumers to the new consumer. (In some cases, hash range assignments can move between existing consumers after a consumer is added or removed.)

The PIP-379 implementation ensures that no new messages for the hash ranges that were moved can be delivered until all unacknowledged messages for a specific hash are cleared with acknowledgements or when the consumer disconnects.
This applies to the AUTO_SPLIT ordered mode of the Key_Shared subscription type.

There's a concept of "draining hashes" in PIP-379 which is now reflected in the consumer stats. This is an intentionally exposed internal detail since the user must have the information available for understanding why messages don't get delivered.

Since there's no mapping between external and internal concepts, the abstraction isn't leaky. The user doesn't need to know about the internal details of how the draining hashes are implemented, but they need to know that the consumer is blocked on unacknowledged messages for a specific hash range. This is all relevant information and doesn't contain unnecessary implementation details.

This PR contains the "consumer stats" changes that provide the information in a clear way.

Modifications

Added consumer-level stats:

  • drainingHashesCount - the current number of hashes in the draining state for this consumer
  • drainingHashesClearedTotal - the total number of hashes cleared from the draining state since the consumer connected
  • drainingHashesUnackedMessages - the total number of unacknowledged messages for all draining hashes for this consumer
  • drainingHashes - draining hashes information for this consumer
    • hash - the sticky key hash which is draining
    • unackMsgs - the number of unacknowledged messages for this hash
    • blockedAttempts - the number of times the hash has blocked an attempted delivery of a message

In addition:

  • keyHashRangeArrays - the consumer's hash range assignments in a list of lists where each item contains the start and end as elements.
    • example [ [ 2960, 5968 ], [ 22258, 43033 ], [ 49261, 54464 ], [ 55155, 61273 ] ]

It was necessary to add this field with a new name keyHashRangeArrays since there's already an existing keyHashRange field. Changing that isn't possible since it would break compatibility. A newer admin client couldn't read stats from an older broker and vice-versa.
The previous keyHashRange is now deprecated. The field format was different.

Example of both fields where the difference is visible:

{
        "keyHashRangeArrays" : [ [ 2960, 5968 ], [ 22258, 43033 ], [ 49261, 54464 ], [ 55155, 61273 ] ],
        "keyHashRanges" : [ "[2960, 5968]", "[22258, 43033]", "[49261, 54464]", "[55155, 61273]" ],
}

The field keyHashRanges contains the information as a list of string values, which isn't very usable for most use cases since it would need to be parsed before it can be used.

The stats will continue to contain keyHashRange and readPositionWhenJoining when the "classic" (3.3.x) implementation of Key_Shared is used by configuring subscriptionKeySharedUseClassicPersistentImplementation=true ("classic" support was added in #23424).
In the default configuration, the fields are removed from the topic stats output, but the client continues to support the fields for backward and forward compatibility.

Example of consumer stats for a subscription

{      
      "consumers" : [ {
        "msgRateOut" : 0.0,
        "msgThroughputOut" : 0.0,
        "bytesOutCounter" : 1560,
        "msgOutCounter" : 30,
        "msgRateRedeliver" : 0.0,
        "messageAckRate" : 0.0,
        "chunkedMessageRate" : 0.0,
        "consumerName" : "c1",
        "availablePermits" : 70,
        "unackedMessages" : 30,
        "avgMessagesPerEntry" : 1,
        "blockedConsumerOnUnackedMsgs" : false,
        "drainingHashesCount" : 5,
        "drainingHashesClearedTotal" : 0,
        "drainingHashesUnackedMessages" : 10,
        "drainingHashes" : [ {
          "hash" : 2862,
          "unackMsgs" : 2,
          "blockedAttempts" : 5
        }, {
          "hash" : 11707,
          "unackMsgs" : 2,
          "blockedAttempts" : 9
        }, {
          "hash" : 15786,
          "unackMsgs" : 2,
          "blockedAttempts" : 6
        }, {
          "hash" : 43539,
          "unackMsgs" : 2,
          "blockedAttempts" : 6
        }, {
          "hash" : 45436,
          "unackMsgs" : 2,
          "blockedAttempts" : 9
        } ],
        "address" : "/127.0.0.1:55829",
        "connectedSince" : "2024-10-10T05:39:39.077284+03:00",
        "clientVersion" : "Pulsar-Java-v4.0.0-SNAPSHOT",
        "lastAckedTimestamp" : 0,
        "lastConsumedTimestamp" : 1728527979411,
        "lastConsumedFlowTimestamp" : 1728527979106,
        "keyHashRangeArrays" : [ [ 2960, 5968 ], [ 22258, 43033 ], [ 49261, 54464 ], [ 55155, 61273 ] ],
        "metadata" : { },
        "lastAckedTime" : "1970-01-01T02:00:00+02:00",
        "lastConsumedTime" : "2024-10-10T05:39:39.411+03:00"
      }, {
        "msgRateOut" : 0.0,
        "msgThroughputOut" : 0.0,
        "bytesOutCounter" : 0,
        "msgOutCounter" : 0,
        "msgRateRedeliver" : 0.0,
        "messageAckRate" : 0.0,
        "chunkedMessageRate" : 0.0,
        "consumerName" : "c2",
        "availablePermits" : 1000,
        "unackedMessages" : 0,
        "avgMessagesPerEntry" : 0,
        "blockedConsumerOnUnackedMsgs" : false,
        "drainingHashesCount" : 0,
        "drainingHashesClearedTotal" : 0,
        "drainingHashesUnackedMessages" : 0,
        "drainingHashes" : [ ],
        "address" : "/127.0.0.1:55829",
        "connectedSince" : "2024-10-10T05:39:39.294216+03:00",
        "clientVersion" : "Pulsar-Java-v4.0.0-SNAPSHOT",
        "lastAckedTimestamp" : 0,
        "lastConsumedTimestamp" : 0,
        "lastConsumedFlowTimestamp" : 1728527979297,
        "keyHashRangeArrays" : [ [ 1, 2959 ], [ 5969, 22257 ], [ 43034, 49260 ], [ 54465, 55154 ], [ 61274, 65535 ] ],
        "metadata" : { },
        "lastAckedTime" : "1970-01-01T02:00:00+02:00",
        "lastConsumedTime" : "1970-01-01T02:00:00+02:00"
      } ]
}

Relevant information for consumer c1:

{
        "drainingHashesCount" : 5,
        "drainingHashesClearedTotal" : 0,
        "drainingHashesUnackedMessages" : 10,
        "drainingHashes" : [ {
          "hash" : 2862,
          "unackMsgs" : 2,
          "blockedAttempts" : 5
        }, {
          "hash" : 11707,
          "unackMsgs" : 2,
          "blockedAttempts" : 9
        }, {
          "hash" : 15786,
          "unackMsgs" : 2,
          "blockedAttempts" : 6
        }, {
          "hash" : 43539,
          "unackMsgs" : 2,
          "blockedAttempts" : 6
        }, {
          "hash" : 45436,
          "unackMsgs" : 2,
          "blockedAttempts" : 9
        } ],
}

Relevant information in this case about consumer c2:

{
        "keyHashRangeArrays" : [ [ 1, 2959 ], [ 5969, 22257 ], [ 43034, 49260 ], [ 54465, 55154 ], [ 61274, 65535 ] ],
}

The PIP-379 implementation will only block hashes that are necessary. For each hash, there's a way to get detailed information to find out why the delivery is blocked.
The major difference from the previous readPositionWhenJoining solution is that it's possible to automate and build CLI and web user interface tools to assist a user, making it very easy to troubleshoot issues when message delivery is blocked by unacknowledged messages in Key_Shared subscriptions.

Client-side tooling could already use the information provided in this PR to determine which consumer is blocked by a hash in the case that there would be multiple consumers.
In the above example, the hash 2862 is contained in the hash range [1, 2959], which means 2 unacknowledged messages for that hash are preventing further messages with hash 2862 from being delivered to consumer c2.
The blockedAttempts field contains a counter that increments each time the dispatcher skips delivery to a consumer due to this hash. Using this information alone, it's very convenient to observe Key_Shared AUTO_SPLIT subscriptions and find out the causes.

A future improvement will be to add a REST API for finding out the unacknowledged message ID information of the unacknowledged message for a hash. Using this information, it's possible to find out the details of the message that is blocking a particular hash.

Documentation

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

Sorry, something went wrong.

Uh oh!

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

All reactions
lhotari added 12 commits October 10, 2024 00:20
@lhotari
[improve][broker][PIP-379] Add observability stats for "draining hashes"
07bd620
@lhotari
Use keyHashRanges for classic dispatcher and add keyHashRangeArrays w…
16792f0
…ith array format

The String format is very inefficient. It's better to replace it for PIP-379
This is needed for tests
@lhotari
Add DrainingHash for stats
cd0be0a
@lhotari
Add deprecated to getReadPositionWhenJoining
efc877b
@lhotari
Add test utilities to log the topic stats in raw format
7186683
@lhotari
Add test for stats
1bda07e
@lhotari
Configure debug logging for PIP-379 core classes
d5795d2
@lhotari
Fix bug in stats
5f5db68
@lhotari
Improve test
9d00334
@lhotari
Validate counters
55db9c2
@lhotari
Fix bug in counter, don't remove stats for consumer
38c1b79
@lhotari
Fix test for checking allowed fields
7d5db1e
@lhotari lhotari added area/broker ready-to-test labels Oct 10, 2024
@lhotari lhotari added this to the 4.0.0 milestone Oct 10, 2024
@lhotari
lhotari requested review from codelipenghui, equanz, merlimat and poorbarcode October 10, 2024 03:37
@lhotari lhotari self-assigned this Oct 10, 2024
@github-actions github-actions Bot added the doc-required Your PR changes impact docs and you will update later. label Oct 10, 2024
lhotari added 2 commits October 10, 2024 06:58
@lhotari
Fix test
84c32c2
@lhotari
Fix test
73c97c8
@lhotari
lhotari requested review from eolivelli, nicoloboschi and nodece October 10, 2024 05:13
@lhotari
Use pinned trivy version
87af5f4
@codecov-commenter

codecov-commenter commented Oct 10, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.94958% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.33%. Comparing base (bbc6224) to head (87af5f4).
⚠️ Report is 1311 commits behind head on master.

Files with missing lines Patch % Lines
...e/pulsar/broker/service/DrainingHashesTracker.java 70.76% 12 Missing and 7 partials ⚠️
...oker/service/persistent/RescheduleReadHandler.java 11.11% 4 Missing and 4 partials ⚠️
...ersistentStickyKeyDispatcherMultipleConsumers.java 50.00% 2 Missing ⚠️
...ava/org/apache/pulsar/broker/service/Consumer.java 75.00% 1 Missing ⚠️
...r/common/policies/data/stats/DrainingHashImpl.java 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23429      +/-   ##
============================================
+ Coverage     73.57%   74.33%   +0.76%     
- Complexity    32624    34398    +1774     
============================================
  Files          1877     1950      +73     
  Lines        139502   146980    +7478     
  Branches      15299    16184     +885     
============================================
+ Hits         102638   109261    +6623     
- Misses        28908    29298     +390     
- Partials       7956     8421     +465     
Flag Coverage Δ
inttests 27.33% <24.36%> (+2.74%) ⬆️
systests 24.38% <28.57%> (+0.05%) ⬆️
unittests 73.71% <73.94%> (+0.86%) ⬆️

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

Files with missing lines Coverage Δ
...ker/service/persistent/PersistentSubscription.java 76.54% <100.00%> (-0.15%) ⬇️
.../common/policies/data/stats/ConsumerStatsImpl.java 98.14% <100.00%> (+0.52%) ⬆️
...mon/policies/data/stats/SubscriptionStatsImpl.java 94.69% <100.00%> (+0.57%) ⬆️
...apache/pulsar/common/util/ObjectMapperFactory.java 93.75% <100.00%> (+0.06%) ⬆️
...ava/org/apache/pulsar/broker/service/Consumer.java 85.44% <75.00%> (-1.23%) ⬇️
...r/common/policies/data/stats/DrainingHashImpl.java 75.00% <75.00%> (ø)
...ersistentStickyKeyDispatcherMultipleConsumers.java 83.78% <50.00%> (-1.86%) ⬇️
...oker/service/persistent/RescheduleReadHandler.java 80.00% <11.11%> (ø)
...e/pulsar/broker/service/DrainingHashesTracker.java 76.92% <70.76%> (ø)

... and 620 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.
All reactions

Sorry, something went wrong.

Uh oh!

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

nicoloboschi
nicoloboschi approved these changes Oct 10, 2024
View reviewed changes

@nicoloboschi nicoloboschi left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
Technoboy-
Technoboy- reviewed Oct 10, 2024
View reviewed changes
Comment thread ...broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java Resolved

Uh oh!

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

Technoboy-
Technoboy- approved these changes Oct 10, 2024
View reviewed changes

@Technoboy- Technoboy- left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
lhotari merged commit acac72e into apache:master Oct 10, 2024
@lhotari lhotari mentioned this pull request Oct 14, 2024
[feat] Add topic stats and metrics for observing message replay behavior and Key_Shared filtering/blocking behavior #23205
Closed
1 of 2 tasks
hanmz pushed a commit to hanmz/pulsar that referenced this pull request Feb 12, 2025
@lhotari hanmz
[improve][broker][PIP-379] Add observability stats for "draining hash…
668eb49
…es" (apache#23429)
@izumo27 izumo27 mentioned this pull request Apr 4, 2025
[fix][doc] Update Topic stats for PIP-379 apache/pulsar-site#998
Merged
2 tasks done
@lhotari lhotari mentioned this pull request Sep 22, 2026
[improve][broker] PIP-379: Remove the classic Shared and Key_Shared dispatcher implementations #26687
Merged
4 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Technoboy- Technoboy- Technoboy- approved these changes
@nicoloboschi nicoloboschi nicoloboschi approved these changes
@merlimat merlimat Awaiting requested review from merlimat
@equanz equanz Awaiting requested review from equanz
@codelipenghui codelipenghui Awaiting requested review from codelipenghui
@poorbarcode poorbarcode Awaiting requested review from poorbarcode
@nodece nodece Awaiting requested review from nodece
@eolivelli eolivelli Awaiting requested review from eolivelli

Uh oh!

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

Assignees

@lhotari lhotari

Labels

area/broker doc-required Your PR changes impact docs and you will update later. ready-to-test

Projects

Apache Pulsar / Key_Shared and Acknowledgement reliability and usability improvements
Status: Done

Milestone

4.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@lhotari @codecov-commenter @Technoboy- @nicoloboschi
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.