test(tables): stale-base concurrent-commit regression tests
Summary
Concurrency regression tests (StaleBaseLostUpdateTest, H2-backed, single-JVM) for committing a snapshot set against a stale base version: a writer that still declares an older base must not silently drop a snapshot another writer committed concurrently.
Scenarios
Each test loads a table at version L1, lets a second writer commit a new snapshot (advancing the catalog to L2), then commits a writer that still declares L1 as its base with a snapshot set computed at L1 — which omits the second writer's snapshot. The concurrently added snapshot must survive, and the stale commit must be rejected.
testStaleInsertDropsConcurrentDataCommitOnFreshTable— two writers race the first insert into a fresh table.testExpireSnapshotsDropsConcurrentDataCommit— an expiration (keep only the current head) races a concurrent insert.testStaleMetadataUpdateDropsConcurrentDataCommit— a metadata change that adds no snapshot races a concurrent insert.testConcurrentInsertOnPopulatedTableIsRejected— two writers insert into a table that already holds data.
Results across commits
| Test | before #406 ff9a40c1 |
#406 14fe4603 |
before #612 d4fc9fe7 |
#612 |
|---|---|---|---|---|
| fresh-table insert | FAIL | FAIL | FAIL | PASS |
| expire vs insert | PASS | FAIL | FAIL | PASS |
| metadata-update vs insert | PASS | FAIL | FAIL | PASS |
| populated-table insert | PASS | PASS | PASS | PASS |
Why the results differ
Before #406, the catalog rejected a stale commit that deletes the latest snapshot only when the commit adds no snapshot of its own (SnapshotInspector.validateSnapshotsUpdate, which exempts snapshot-adding commits). So:
- expire and metadata-update add no snapshot → caught before #406, then lost from #406 onward when that check was removed; #612 restores rejection. Regressions introduced by #406.
- fresh-table insert adds a snapshot → exempted by that check, so it was never caught and lost data on every commit before #612. Pre-existing, not a #406 regression.
- populated-table insert never loses data: the stale writer's appended snapshot shares a sequence number with the concurrent insert, so Iceberg's sequence-number validation rejects it on every version.
The single check that covers all of these is #612's base-divergence abort: it rejects any commit whose declared base no longer matches the catalog.
Testing
./gradlew :services:tables:test --tests "*StaleBaseLostUpdateTest"
All four pass with #612. Each test asserts the stale commit is rejected (throws) and that the table holds exactly the prior snapshots plus the concurrently committed snapshot. Test-only; no production changes.
🤖 Generated with Claude Code