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: Key_Shared Draining Hashes for Improved Message Ordering by lhotari · Pull Request #23352 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Sep 25, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Fixes #23307
Fixes #21199
Fixes #15705
Fixes #21656
Fixes #20899
Fixes #20885

Implementation for PIP-379: Key_Shared Draining Hashes for Improved Message Ordering

Mailing list discussion about this PR

4.0.x docs for the implementation: https://pulsar.apache.org/docs/4.0.x/concepts-messaging/#preserving-order-of-message-delivery-by-key

Motivation

See PIP-379: Key_Shared Draining Hashes for Improved Message Ordering

PIP-379 aims to address several issues with the current implementation and introduce a more efficient mechanism for managing message ordering.

Problem:
The current Key_Shared implementation faces challenges including:

  1. Complex management of "recently joined consumers"
  2. Incomplete fulfillment of ordering guarantees
  3. Unnecessary message blocking
  4. Poor observability

PIP-379 introduces a "draining hashes" concept to efficiently manage
message ordering by tracking affected hashes when consumer assignments
change.

Benefits:

  1. Improved message ordering guarantees
  2. Reduced unnecessary message blocking
  3. Better scalability and performance
  4. Enhanced observability

This proposal would replace the existing "recently joined consumers"
mechanism, addressing its limitations while providing a more robust
solution.

Modifications

See PIP-379: Key_Shared Draining Hashes for Improved Message Ordering for high level design with simplified code examples.

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 lhotari added the category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost label Sep 25, 2024
@lhotari lhotari added this to the 4.0.0 milestone Sep 25, 2024
@lhotari
lhotari requested review from codelipenghui, dao-jun, dlg99, eolivelli, equanz, hrsakai, merlimat, poorbarcode and shibd September 25, 2024 16:34
@lhotari lhotari self-assigned this Sep 25, 2024
@github-actions github-actions Bot added the doc-required Your PR changes impact docs and you will update later. label Sep 25, 2024
@lhotari lhotari mentioned this pull request Sep 27, 2024
[improve][pip] PIP-379: Key_Shared Draining Hashes for Improved Message Ordering #23309
Merged
1 of 4 tasks
@lhotari
lhotari force-pushed the lh-pip-379-implementation branch 2 times, most recently from 923f379 to 48b2022 Compare October 1, 2024 11:40
@lhotari
lhotari marked this pull request as ready for review October 1, 2024 11:41
@lhotari lhotari added the ready-to-test label Oct 1, 2024
@lhotari
lhotari force-pushed the lh-pip-379-implementation branch 2 times, most recently from 1855f33 to a6d9bf3 Compare October 1, 2024 23:51
lhotari added 10 commits October 2, 2024 11:14
@lhotari
Remove PIP-282 solution
1fef930
@lhotari
Implement PIP-379 draining hashes solution
989fa25
@lhotari
Handle TTL case for replay queue where the mark delete position moves…
aa66c2d
… forward
@lhotari
Revisit TTL test
a391306
@lhotari
Join ranges with single consumer
23a8126
@lhotari
Fix getting impacted hashes
5ee3da2
@lhotari
Improve
3d19279
@lhotari
Add more logging
9e4991d
@lhotari
merge overlapping ranges
f024921
@lhotari
Fix condition for overlapping ranges
38ebadf
lhotari added 5 commits October 8, 2024 00:12
@lhotari
Revisit RescheduleReadHandler used for the Key_Shared implementation
ead7bce
@lhotari
Remove unused field
bf1e89c
@lhotari
Revisit removeConsumer method
186dc30
@lhotari
Rename parameter
fbd7695
@lhotari
Polish
22e1709
codelipenghui
codelipenghui reviewed Oct 7, 2024
View reviewed changes

@codelipenghui codelipenghui 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.

The change looks good.
Just left a few minor comments.

Sorry, something went wrong.

Uh oh!

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

lhotari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedCursor.java Resolved

Uh oh!

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

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java Resolved

Uh oh!

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

Comment thread ...c/main/java/org/apache/pulsar/broker/service/ConsistentHashingStickyKeyConsumerSelector.java Resolved

Uh oh!

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

@lhotari
Add some tests for RescheduleReadHandlerTest
58bddf7
codelipenghui
codelipenghui approved these changes Oct 8, 2024
View reviewed changes
lhotari added 5 commits October 8, 2024 05:11
@lhotari
Add test for adding 1000 consumers
fb7a8ea
@lhotari
Optimize snapshotting by assuming that entries are sorted
92f9a29
@lhotari
Optimize snapshotting step by assuming sorted order as input
640b48a
@lhotari
Disable perf test by default since there's no validation to be performed
a81393e
- it's used for quick profiling
@lhotari
Remove invalid test case that makes assumptions about the implementation
34f925d
nicoloboschi
nicoloboschi approved these changes Oct 8, 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, nice work

Sorry, something went wrong.

Uh oh!

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

lhotari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lhotari
lhotari merged commit 3d0625b into apache:master Oct 8, 2024
poorbarcode
poorbarcode reviewed Oct 8, 2024
View reviewed changes
Comment thread .../apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java Resolved

Uh oh!

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

Comment thread .../apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java Resolved

Uh oh!

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

This was referenced Oct 8, 2024
[PIP-379] lastNumberOfEntriesProcessed will be wrong when entries get filtered in addPendingAckIfAllowed #23420
Closed
[PIP-379] DrainingHashEntry.refCount will increase when hashes move between existing consumers #23421
Closed
[improve][broker] PIP-379: Snapshot hash range assignments only in AUTO_SPLIT ordered mode #23423
Merged
[improve][broker][PIP-379] Add observability stats for "draining hashes" #23429
Merged
equanz
equanz reviewed Oct 11, 2024
View reviewed changes
Comment thread .../apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java Resolved

Uh oh!

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

This was referenced Oct 11, 2024
[Bug][PIP-379] Hash ranges should not move from one consumer to another when a consumer joins #23439
Closed
key_shared subscription will get suck sometimes when add consumers #14902
Closed
hanmz pushed a commit to hanmz/pulsar that referenced this pull request Feb 12, 2025
@lhotari hanmz
[improve][broker] PIP-379: Key_Shared Draining Hashes for Improved Me…
8d12c5b
…ssage Ordering (apache#23352)
@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
3pacccccc
3pacccccc reviewed Aug 15, 2025
View reviewed changes
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
// deduplication for readMoreEntriesAsync calls
if (readMoreEntriesAsyncRequested.compareAndSet(false, true)) {
topic.getBrokerService().executor().execute(() -> {
readMoreEntriesAsyncRequested.set(false);

@3pacccccc 3pacccccc Aug 15, 2025

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.

Hi, Lari, sorry to bother you, But when I read the source code, I'm confused about this:

  • It uses an atomic flag readMoreEntriesAsyncRequested to "block" duplicate requests
  • But resets the flag right when the task starts, not after completion
  • Since topic.getBrokerService().executor() is a multi-threaded pool (has multiple core threads):
    This lets new requests jump in immediately
  • Multiple readMoreEntries() can run concurrently

could you explain how this work? I would be so much appreciate!

Sorry, something went wrong.

Uh oh!

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

All reactions

@lhotari lhotari Aug 15, 2025

Copy link
Copy Markdown
Member Author

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.

@3pacccccc The intention isn't to prevent concurrent execution. The short comment "deduplication for readMoreEntriesAsync calls" explains the intention. In Pulsar code, readMoreEntries and readMoreEntriesAsync is called in multiple locations to ensure that all entries that were made available in a way or another would get dispatched. That's why the deduplication makes sense since it will continue to provide that guarantee while reducing the extra overhead of unnecessary concurrent or subsequent calls to readMoreEntries.
Since in most (or all) dispatcher implementations the method "readMoreEntries" itself is a synchronous method, it will serialize the execution eventually. I agree that this isn't an optimal solution how this is handled in dispatchers, but changing it wasn't the intention when the deduplication was added in this PR.

Sorry, something went wrong.

Uh oh!

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

3pacccccc reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@3pacccccc 3pacccccc Aug 15, 2025

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.

@lhotari OK, I get it, thank you so much!

Sorry, something went wrong.

Uh oh!

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

All reactions
@poorbarcode poorbarcode mentioned this pull request Sep 17, 2025
[improve][broker] Part-1 of PIP-434: Expose Netty channel configuration WRITE_BUFFER_WATER_MARK to pulsar conf and pause receive requests when channel is unwritable #24423
Merged
1 of 4 tasks
@merlimat merlimat mentioned this pull request Oct 14, 2026
[fix][broker] Key-shared subscription must follow consumer redelivery as per shared sub semantic #21657
Closed
1 of 15 tasks
@merlimat merlimat mentioned this pull request Oct 24, 2026
[Bug] key_shared consumer with backlog cause pulsar broker read a huge amount data from bookkeeper but dispatch a little, cause network bandwith exhausted #23514
Closed
2 of 3 tasks
@lhotari lhotari mentioned this pull request Nov 6, 2026
[fix][broker] Release pending acks for fully acknowledged batches #27406
Merged
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@equanz equanz equanz left review comments
@codelipenghui codelipenghui codelipenghui approved these changes
@poorbarcode poorbarcode poorbarcode left review comments
@nicoloboschi nicoloboschi nicoloboschi approved these changes
@dlg99 dlg99 Awaiting requested review from dlg99
@dao-jun dao-jun Awaiting requested review from dao-jun
@hrsakai hrsakai Awaiting requested review from hrsakai
@shibd shibd Awaiting requested review from shibd
@rdhabalia rdhabalia Awaiting requested review from rdhabalia
@michaeljmarshall michaeljmarshall Awaiting requested review from michaeljmarshall
@merlimat merlimat Awaiting requested review from merlimat
@eolivelli eolivelli Awaiting requested review from eolivelli
@pdolif pdolif Awaiting requested review from pdolif
+1 more reviewer
@3pacccccc 3pacccccc 3pacccccc left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@lhotari lhotari

Labels

category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost 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.

[Bug] key-SHARED subscription is not performing redelivery and going in infinite while loop of reading messages from disk and not dispatching any messages [Bug] Subscription consumption stuck on consumer reconnect [Bug] Broker dispatch messages despite a message with the same key is unack [Bug][broker] no mesage receive for som partition New KeyShared consumers will not get any messages until a consumer that did get messages disconnects or acks/nacks some messages
[Bug] Message ordering isn't retained in Key_Shared AUTO_SPLIT mode in a rolling restart type of test scenario

Uh oh!

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

10 participants

@lhotari @codecov-commenter @merlimat @eolivelli @equanz @codelipenghui @nicoloboschi @poorbarcode @3pacccccc @pdolif
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.