Skip to content

fix: settle couchbase seed before asserting unfiltered count - #720

Merged
babltiga merged 1 commit into
mainfrom
fix/AF-couchbase-count-flake
Aug 13, 2026
Merged

fix: settle couchbase seed before asserting unfiltered count#720
babltiga merged 1 commit into
mainfrom
fix/AF-couchbase-count-flake

Conversation

@babltiga

Copy link
Copy Markdown
Contributor

Problem

CouchbaseQueryEngineIntegrationTest.countAffectedRowsCountsUpdateWithoutWhereAsWholeCollection
is flaky: it asserts 3 seeded documents but intermittently reads 1 or 2. Because the couchbase
engine job runs on any backend/** change, this fails unrelated PRs — it took down
#717 (a Slack SDK bump) and the ArchUnit bump in the same CI wave, with different wrong values
(1 and 2 respectively).

Root cause

Not scan consistency — every executor path shares one options() helper and the test runs
REQUEST_PLUS throughout. The differentiator is the query shape.

CouchbaseCountRewriter turns the WHERE-less UPDATE _default SET bonus = 1 into a bare
SELECT COUNT(*) AS af_count FROM _default. Verified against a real 7.6.2 container:

statement plan operators
SELECT COUNT(*) FROM itest CountScan
SELECT COUNT(*) FROM itest WHERE team = "eng" PrimaryScan3 + Fetch + Filter

The CountScan fast path can read a just-committed INSERT as short even under request_plus;
driving that loop directly reproduced a stale COUNT=1, while the filtered shape never went
stale. That is exactly why this is the only count test in the class that flakes — every other one
carries a WHERE clause.

Fix

Settle the @BeforeEach seed on the same probe before any assertion runs, bounded at 30s with a
clear failure message. Since it sits in @BeforeEach it also removes the unsettled
DELETE-then-INSERT window for all 32 tests in the class, not just this one.

Deliberately test-only: the engine already requests the strongest consistency Couchbase
offers, and touching src/main/ — even a comment, which shifts the LineNumberTable — would
change the shaded jar bytes and force a connectors/couchbase/connector.json SHA-256 re-pin.

Verification

  • mvn -f engines/couchbase/pom.xml clean verify — green (32/32 IT, 2/2 failsafe)
  • IT re-run 3 further times on a clean tree — 4/4 green overall
  • node .github/scripts/check-engine-pins.mjs couchbase — pin unchanged, confirming the shaded
    jar is byte-identical

countAffectedRowsCountsUpdateWithoutWhereAsWholeCollection intermittently
read 1 or 2 of the 3 seeded documents in CI, failing unrelated PRs.

An unfiltered SELECT COUNT(*) — what CouchbaseCountRewriter emits for a
WHERE-less UPDATE/DELETE — is planned as a CountScan over the primary
index, and that fast path can read a just-committed INSERT as short even
under REQUEST_PLUS. EXPLAIN confirms the divergence: the bare count plans
to CountScan, every WHERE-bearing count to PrimaryScan3 + Fetch.

Settle the @beforeeach seed on the same probe before any assertion, which
also removes the unsettled DELETE-then-INSERT for all 32 tests. Test-only:
the shaded jar SHA-256 pin is unchanged.
@babltiga
babltiga merged commit 625e39e into main Aug 13, 2026
30 checks passed
@babltiga
babltiga deleted the fix/AF-couchbase-count-flake branch August 13, 2026 08: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.

1 participant