Skip to content

Conversation

@lhotari
Copy link
Member

@lhotari lhotari commented Oct 10, 2025

Fix #24831

Motivation

The test ManagedCursorConcurrencyTest.testConcurrentReadOfSameEntry is flaky. In that case, the entries don't contain any message metadata. The broker cache will attempt to parse the message metadata each time the entry is cached. This results in a race condition since peekMessageMetadata changes the readerIndex of the cached ByteBuf while another thread is making a retained duplicate of the cached ByteBuf. Thanks for @pdolif for the analysis of the problem. It was helpful in locating the issue.

Modifications

  • increase invocation count and concurrency in the ManagedCursorConcurrencyTest.testConcurrentReadOfSameEntry test to reproduce the issue more often
  • eliminate race conditions in org.apache.bookkeeper.mledger.impl.EntryImpl#initializeMessageMetadataIfNeeded
  • eliminate race conditions in org.apache.bookkeeper.mledger.impl.cache.RangeCacheEntryWrapper#getValueInternal
  • copy MessageMetadata from the entry that is inserted into the cache. This optimization was missing.

Documentation

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

@lhotari lhotari added this to the 4.2.0 milestone Oct 10, 2025
@lhotari lhotari self-assigned this Oct 10, 2025
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 10, 2025
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.28%. Comparing base (cc5e479) to head (8545f44).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...per/mledger/impl/cache/RangeCacheEntryWrapper.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #24836       +/-   ##
=============================================
+ Coverage     38.36%   74.28%   +35.91%     
+ Complexity    13123     2494    -10629     
=============================================
  Files          1856     1913       +57     
  Lines        145070   149236     +4166     
  Branches      16836    17320      +484     
=============================================
+ Hits          55662   110861    +55199     
+ Misses        81843    29530    -52313     
- Partials       7565     8845     +1280     
Flag Coverage Δ
inttests 26.29% <87.50%> (-0.08%) ⬇️
systests 22.76% <87.50%> (-0.01%) ⬇️
unittests 73.81% <87.50%> (+39.27%) ⬆️

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

Files with missing lines Coverage Δ
.../org/apache/bookkeeper/mledger/impl/EntryImpl.java 90.34% <100.00%> (+40.34%) ⬆️
...keeper/mledger/impl/cache/RangeEntryCacheImpl.java 71.06% <100.00%> (+19.22%) ⬆️
...per/mledger/impl/cache/RangeCacheEntryWrapper.java 88.05% <75.00%> (+3.21%) ⬆️

... and 1416 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.

@lhotari lhotari merged commit 9737d03 into apache:master Oct 10, 2025
100 of 103 checks passed
lhotari added a commit that referenced this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: ManagedCursorConcurrencyTest.testConcurrentReadOfSameEntry

4 participants