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 — [fix][test] Fix flaky EntryCacheManagerTest.simple by merlimat · Pull Request #27523 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Motivation

EntryCacheManagerTest.simple fails now and then in CI - Unit - Other with
AssertionError: expected [1] but found [0] and passes on its retry (5 retries between 2026-11-06 and 2026-11-08).

The assertion that fails is the eviction count, after the test's own stats refresh:

cache2.insert(EntryImpl.create(2, 3, new byte[1]));   // size 10 > trigger threshold 9: one eviction
factory2.waitForPendingCacheEvictions();
...
factory2.getMbean().refreshStats(1, TimeUnit.SECONDS);
...
assertEquals(factory2.getMbean().getNumberOfCacheEvictions(), 1);   // found 0

getNumberOfCacheEvictions() returns the count of the last period that Rate.calculateRate() closed, and
calculateRate() resets the counter (countAdder.sumThenReset()). The test is not the only one that closes periods:
ManagedLedgerFactoryImpl's constructor schedules its own refresh with an initial delay of 0:

this.statsTask = scheduledExecutor.scheduleWithFixedDelay(catchingAndLoggingThrowables(this::refreshStats),
        0, config.getStatsPeriodSeconds(), TimeUnit.SECONDS);

That first run is a task on a freshly started bookkeeper-ml-scheduler thread. When the thread starts late on a busy
runner and the run lands after the eviction is recorded and before the test's refreshStats() (and at least 1 ms after
construction, so it isn't skipped), it closes a period that holds the eviction. The test's refresh then closes an empty
period, and the count it reads is 0.

The race is old (the zero initial delay and the assertion both predate 2022); #27223 is not involved, as it only changed
ReadEntryUtils, which this test never reaches.

Modifications

Assert on the cumulative counter, which refreshes don't reset:

// The factory's own stats task also refreshes the per-period counters, and its first run may land after
// the eviction, so check the total count that refreshes don't reset
assertEquals(factory2.getMbean().getNumberOfCacheEvictionsTotal(), 1);

The other assertions after the refresh read live values (cache size, entry counters) or per-period rates that are 0 in
every interleaving (the test never reads, so there are no hits or misses).

Verifying this change

  • Reproduced deterministically with a temporary hook (not part of this PR) that holds the factory's first scheduled
    stats refresh until after waitForPendingCacheEvictions(): the test failed with expected [1] but found [0] at the
    getNumberOfCacheEvictions() assertion. With this change and the same hook, it passes.
  • ./gradlew :managed-ledger:test --tests 'org.apache.bookkeeper.mledger.impl.EntryCacheManagerTest': 9 tests passed.
  • ./gradlew quickCheck passes.

Note (not changed here): verifyHitsMisses in the same class reads per-period hit rates after manual refreshes too, so
the same first scheduled refresh could in principle interfere there; it runs only after opening a ledger, two cursors
and 10 adds, and it has not shown up in the retried-test reports.

Sorry, something went wrong.

Uh oh!

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

All reactions
merlimat added 2 commits November 9, 2026 08:39
@merlimat
[fix][test] Fix flaky EntryCacheManagerTest.simple
fc8cc26
ManagedLedgerFactoryImpl schedules its own stats refresh with an initial
delay of 0. When that first run lands after the cache eviction and before
the test's own refreshStats() call, it moves the eviction into a period the
test never reads, and getNumberOfCacheEvictions() returns 0.

Assert on getNumberOfCacheEvictionsTotal(), which refreshes don't reset.
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/entry-cache-…
2554458
…manager-test-simple-flake
@merlimat merlimat added the area/test label Nov 9, 2026
codelipenghui
codelipenghui approved these changes Nov 9, 2026
View reviewed changes
@merlimat
merlimat merged commit 8b5238d into apache:master Nov 9, 2026
46 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[fix][test] Fix flaky EntryCacheManagerTest.simple (#27523)
065bccc
(cherry picked from commit 8b5238d)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky EntryCacheManagerTest.simple (apache#27523)
bd42f79
(cherry picked from commit 8b5238d)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky EntryCacheManagerTest.simple (apache#27523)
25ac6a4
(cherry picked from commit 8b5238d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

area/test cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

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