Skip to content

dbsp: keep the compaction test below the level-0 merge trigger - #6760

Merged
ryzhyk merged 1 commit into
mainfrom
fix-compaction-test-flake
Jul 30, 2026
Merged

dbsp: keep the compaction test below the level-0 merge trigger#6760
ryzhyk merged 1 commit into
mainfrom
fix-compaction-test-flake

Conversation

@ryzhyk

@ryzhyk ryzhyk commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes the test_is_compaction_complete flake that failed the merge queue in run 30493031729 (PR #6756, docs-only, unrelated to the failure):

expected at least one spine with >1 batch before compaction, got [1, 1]

Root cause

The test fed 30 transactions and then asserted that some spine still held more than one batch, so that the compaction request it makes next has real merging to do. That assertion raced the background merger.

Level 0 starts a merge once 8 loose batches accumulate and then takes every loose batch (MERGE_COUNTS[0] = 8..=128), and each 500-record transaction adds exactly one level-0 batch per spine (250 records per worker, far below MAX_LEVEL0_BATCH_SIZE_RECORDS = 14,999). So the steady-state batch count per spine is a pure function of the transaction count:

transactions fed 8 9 15 22 28 30 31 36
batches per spine 1 2 1 1 7 2 3 1

30 sits exactly one batch past the merge trigger at 29, so the test's whole margin was a single input batch: when the level-0 merger task wakes late enough for batch 30 to arrive before it grabs the loose set, the sweep absorbs all nine batches and the spine collapses to one. It hit 2 of the last 200 merge-queue runs, both on arm64, where 20 libtest threads oversubscribe the runner.

No product bug: collapsing a spine to a single batch is the merge policy doing its job.

Fix

Feed one batch fewer than the trigger. A spine below MIN_LEVEL0_MERGE_BATCHES merges nothing on its own, so all seven batches wait for the explicit compaction request and the pre-condition holds by construction rather than by luck. The level-0 minimum gets a name so the test depends on the constant instead of restating 8.

Describe Manual Test Plan

Release build, aarch64-apple-darwin, crates/dbsp lib tests:

check result
fixed test, 200 runs, idle machine 200 pass, pre-compaction count [7, 7] every run
fixed test, 200 runs, 2x CPU oversubscription 200 pass, pre-compaction count [7, 7] every run
negative control: SharedState::is_compaction_complete hardcoded to true fails 3/3 with expected all spines to have <=1 batch after compaction, got [7, 7]
spine and trace:: test subsets (117 tests) pass
cargo fmt --check -p dbsp pass

The negative control matters here: when the old test collapsed to [1, 1], its post-condition passed trivially, which is what the pre-check was guarding against. For reference, the old test produced [9, 9] idle and scattered across [2, 2], [9, 4], [30, 30] under load.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

None.

🤖 Generated with Claude Code

`test_is_compaction_complete` fed 30 transactions and then asserted that some
spine still held more than one batch, so that the compaction request it makes
next has real merging to do. That assertion raced the background merger. Level 0
starts a merge once 8 loose batches accumulate and then takes every loose batch,
and each 500-record transaction adds one level-0 batch per spine, so 30
transactions leave the spine exactly one batch past the trigger at 29. When the
merger task wakes late enough for batch 30 to arrive first, the sweep absorbs all
nine batches and the spine collapses to a single one, and the test fails with
`expected at least one spine with >1 batch before compaction, got [1, 1]`. It hit
2 of the last 200 merge-queue runs, both on arm64, where 20 libtest threads
oversubscribe the runner.

Feed one batch fewer than the trigger instead. A spine below
`MIN_LEVEL0_MERGE_BATCHES` merges nothing on its own, so all seven batches wait
for the explicit compaction request and the pre-condition holds by construction.

Signed-off-by: Leonid Ryzhyk <ryzhyk@gmail.com>
@ryzhyk
ryzhyk enabled auto-merge July 29, 2026 23:13
@ryzhyk
ryzhyk added this pull request to the merge queue Jul 29, 2026

@mythical-fred mythical-fred left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Merged via the queue into main with commit d792b60 Jul 30, 2026
1 check passed
@ryzhyk
ryzhyk deleted the fix-compaction-test-flake branch July 30, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants