Skip to content

[fix][ml] Fix eviction trigger race that cleared the in-progress marker - #25988

Merged
lhotari merged 1 commit into
apache:masterfrom
merlimat:mmerli/fix-eviction-trigger-race
Jun 10, 2026
Merged

[fix][ml] Fix eviction trigger race that cleared the in-progress marker#25988
lhotari merged 1 commit into
apache:masterfrom
merlimat:mmerli/fix-eviction-trigger-race

Conversation

@merlimat

@merlimat merlimat commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Motivation

RangeEntryCacheManagerImpl.triggerEvictionWhenNeeded() uses updateAndGet with a lambda that returns null when another eviction is already in progress. Since updateAndGet stores the lambda's result, a thread losing the race overwrites the running eviction's in-progress marker with null. On its next loop iteration that thread installs its own future and submits a duplicate eviction task, while the first cycle's cleanup then clears the second cycle's marker.

With the cache sitting at the eviction trigger threshold and many managed-ledger threads inserting concurrently, this happens routinely: redundant tasks are queued on the single eviction executor (each re-checks the size, so the wasted work is bounded, but timer-driven eviction passes get delayed behind the no-op tasks), and the marker no longer reliably reflects whether an eviction is running.

Modifications

Use compareAndSet(null, newEvictionFuture) so only the winning thread installs the in-progress marker; losing threads loop and pick up the owner's future via get(). The owner remains the only one clearing the marker in triggerEvictionToMakeSpace's finally block.

triggerEvictionWhenNeeded used updateAndGet with a lambda returning null
when another eviction was already in progress, which overwrote the running
eviction's marker with null. The looping thread would then install its own
future and submit a duplicate eviction task, while the first cycle's
cleanup cleared the second's marker. Use compareAndSet so only the winning
thread installs the marker and losers re-read the current owner's future.
@merlimat
merlimat requested a review from lhotari June 9, 2026 23:17

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhotari lhotari added this to the 5.0.0-M1 milestone Jun 10, 2026
@lhotari
lhotari merged commit fbcfacf into apache:master Jun 10, 2026
44 checks passed
lhotari pushed a commit that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants