[fix][client] Fix exclusive V5 scalable topic producer initial segment claim race condition#25778
Merged
Conversation
…t claim race condition
merlimat
approved these changes
May 14, 2026
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.
Fixes #25678
Motivation
The V5 scalable topic producer with exclusive access mode initially claims all active segments. The test
V5ProducerAccessModeTest.testExclusiveRejectsSecondProducerverifies that a second exclusive producer is rejected. Therefore, it starts two exclusive producers sequentially and asserts that the second producer creation fails. Currently, the test is flaky, and it happens that from the client perspective, both producers seem to be created successfully. The reason for that is a race condition betweeneagerAttachInitialAsyncandonLayoutChangeinScalableTopicProducer.For the second producer, the
ProducerBuilderV5creates theDagWatchClient, starts it, and callseagerAttachInitialAsynconce it receives the initial layout. Concurrently,onLayoutChangemay receive the initial layout. Both methods try to claim the active segments and there is a race condition between the two who first creates the segment producer(s).eagerAttachInitialAsync:onLayoutChange:Modifications
onLayoutChangefor the initial change. The initial claim is done byeagerAttachInitialAsync.getOrCreateSegmentProducercall ineagerAttachInitialAsyncto avoid issues if a second layout change is executed beforeeagerAttachInitialAsynccreated the producer(s).Verifying this change
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes