Repository navigation
Conversation
pjfanning
marked this pull request as ready for review
November 13, 2026 10:10
Motivation: TopicImpl only learns the other topic instances from its first receptionist Listing. A message published to a freshly created topic is processed before that reply arrives, so it never reached subscribers on other instances and went to dead letters when there were no local subscribers. Modification: Until the first TopicInstancesUpdated, deliver published messages to local subscribers right away and keep up to 1000 of them. When the first listing arrives, forward them to the other topic instances (excluding itself, whose local subscribers already got them), or drop them as Dropped if they reached nobody. Overflow is dropped as Dropped. After that the behaviour is unchanged. Result: The first messages published to a new topic reach subscribers already known to the receptionist. Tests: - sbt "actor-typed-tests/testOnly org.apache.pekko.actor.typed.pubsub.LocalPubSubSpec" - 7 passed - New test "deliver messages published to a new topic instance before its first listing" fails without the TopicImpl change References: Fixes apache#3761
…ndow Motivation: Flushing the kept messages at the first receptionist listing only helps with the local receptionist. The cluster receptionist's first listing only has what the node has seen so far, often nothing on a new node, so the messages were still lost. The tests also didn't reliably exercise the new code. Modification: - Keep published messages until the first listing has been seen and pekko.actor.typed.pubsub.startup-replay-window (default 3s) has elapsed. Each topic instance and local subscriber that becomes known in that time gets every kept message once. - Buffer size is pekko.actor.typed.pubsub.startup-replay-buffer-size (default 1000). Messages past it that reached a subscriber are no longer reported as Dropped. - Deliver to local subscribers directly and send MessagePublished only to the other instances, which merges the two Publish cases and removes the stale "listing not seen yet" path. - Replace the timing-dependent LocalPubSubSpec tests with deterministic BehaviorTestKit tests in TopicImplSpec. Result: Messages published right after a topic starts reach instances learnt from later listings, which covers the cluster receptionist case. Tests: - sbt "actor-typed-tests/testOnly ...TopicImplSpec ...LocalPubSubSpec": 13 passed References: Refs apache#3761
pjfanning
force-pushed
the
topic-buffer-before-listing
branch
from
November 13, 2026 14:45
a9f0203 to
ba21a69
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
TopicImplonly learns the other topic instances from the receptionist. A message published to a freshly created topic is processed before the firstListingarrives, so it never reaches subscribers on other instances, and goes to dead letters when there are no local subscribers. This happens every time a topic is created and published to straight away, e.g. pekko-persistence-r2dbc'sjournal.publish-events.With the cluster receptionist, the first listing only contains what the node has seen so far, which on a newly started node is often nothing. So keeping messages only until the first listing is not enough.
Modification
pekko.actor.typed.pubsub.startup-replay-window(default3s) has elapsed since it started.pekko.actor.typed.pubsub.startup-replay-buffer-size(default1000) messages are kept. Messages past that are still delivered to the instances and subscribers known at the time. They are only sent to dead letters asDroppedif they reached nobody.Dropped, as before.MessagePublishedgoes only to the other instances. This merges the twoPublishcases and fixes a gap where local subscribers missed messages when the listing didn't yet include the own instance.distributed-pub-sub.mdandreference.conf.Result
The first messages published to a new topic reach the subscribers on instances discovered during the startup window, including with the cluster receptionist, without duplicates.
Tests
TopicImplSpecusesBehaviorTestKitto drive receptionist listings and the window timer deterministically. It covers forwarding at the first listing, exactly-once local delivery, replay to instances and subscribers discovered later, waiting for the first listing, and buffer overflow. Real-system tests cover theDroppedcases.sbt "actor-typed-tests/testOnly org.apache.pekko.actor.typed.internal.pubsub.TopicImplSpec org.apache.pekko.actor.typed.pubsub.LocalPubSubSpec": 13 passedsbt "actor-typed/mimaReportBinaryIssues": passedcluster-typedPubSubSpecnot run locally; left to CIReferences
Fixes #3761