test(upgrade): cover per-version on-disk upgrade transforms via synthetic old-format fixtures - #73
Closed
gburd wants to merge 1 commit into
Closed
test(upgrade): cover per-version on-disk upgrade transforms via synthetic old-format fixtures#73gburd wants to merge 1 commit into
gburd wants to merge 1 commit into
Conversation
…-format fixtures
Extend test/db/run_upgrade.sh to exercise the on-disk-format upgrade code
(src/db/db_upg.c, src/btree/bt_upgrade.c, src/hash/hash_upgrade.c,
src/qam/qam_upgrade.c), which was almost entirely dead (0-14%) because this
fork ships only one current-format fixture and lacks upstream's per-version
Tcl upgrade fixture tree (test/tcl/upgrade/databases/).
The driver now:
- runs db_upgrade (DB->upgrade) + db_verify over the committed btree v9
fixture and freshly-created current-format dbs of every access method
(btree/hash/queue/recno + btree-with-dups + the -s DUPSORT flag and
salvage), covering the full magic/version dispatch and the
version-current no-op branch for each AM;
- manufactures old-format fixtures WITHOUT an old library, by rewriting a
current db's metadata page into the byte layout of an older release
(HASHHDR v5, HMETA30 v6, BTMETA2X v6, BTMETA30 v7, QMETA30 v1, QMETA31 v2
from dbinc/db_upgrade.h) with the version field set back, driving the real
per-version transform functions.
Coverage (line), before -> after:
db/db_upg.c 13.9% -> 57.2% (functions 40% -> 100%)
qam/qam_upgrade.c 0.0% -> 97.1% (functions 0% -> 100%)
btree/bt_upgrade.c 0.0% -> 82.4% (functions 0% -> 100%)
hash/hash_upgrade.c 0.0% -> 68.5% (functions 0% -> 66.7%)
db/db_upg_opd.c 0.0% -> 0.0% (still cold; see below)
Fixtures are generated at test time from current-format dbs, so no binary
fixtures are committed.
Two documented gaps (in test/coverage/README.md, engine NOT changed):
- db_upg_opd.c (__db_31_offdup, 3.0->3.1 off-page-dup conversion) needs a
genuine 3.0-era off-page-duplicate page chain (linked __P_DUPLICATE pages);
a rewritten current db can't produce it (current dups are already a Recno
tree), so it stays 0%.
- __db_set_lastpgno off-by-one: the btree v6/v7 path stores __db_lastpgno()'s
page COUNT into meta->last_pgno (a page NUMBER = count-1), so db_verify
rejects last_pgno on a page-aligned file ("last_pgno is not correct: N !=
N-1", under HAVE_FTRUNCATE). The hash path avoids it (its v8->v9 pass runs
through mpool, which recomputes last_pgno on close). The code is identical
to upstream BDB 4.7/4.8. The driver upgrades btree v6/v7 (covering the
transform) but skips db_verify on them, asserting the version bump instead.
Reported to confirm against a genuine old fixture; not fixed.
Coccinelle convention checksNo new violations. ✅ Resolved since baseline (2) -- update dist/cocci/baseline.txt to lock these in. |
ABI diff vs
|
Collaborator
Author
|
Superseded by coverage/upgrade-rebased (rebased onto master to pick up #72); reopening. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Raises coverage of libdb's on-disk-format upgrade code, which was almost
entirely dead (0–14%) because this fork ships only one current-format fixture
and lacks upstream's per-version Tcl upgrade fixture tree
(
test/tcl/upgrade/databases/).test/db/run_upgrade.sh(added in #70) is extended to drive the realper-version metadata/page transforms in
src/db/db_upg.c,src/btree/bt_upgrade.c,src/hash/hash_upgrade.c,src/qam/qam_upgrade.c.What the driver now does
db_upgrade(→DB->upgrade→__db_upgrade) +db_verifyover:test/csharp/bdb4.7.db);(btree / hash / queue / recno + btree-with-dups + the
-s/DB_DUPSORTflag path + salvage) — this covers the full magic/version dispatch and the
version-current no-op branch for each AM.
current db and rewrites only its metadata page into the byte layout of an
older release (HASHHDR v5, HMETA30 v6, BTMETA2X v6, BTMETA30 v7, QMETA30 v1,
QMETA31 v2 — from
dbinc/db_upgrade.h) with the version field set back. Sincethe old→new metadata transforms operate on the meta page in place, these are
legitimate inputs to
__db_upgradeand drive the real transform functions.No binary fixtures are committed — everything is generated at test time.
Coverage (line), before → after
db/db_upg.cqam/qam_upgrade.cbtree/bt_upgrade.chash/hash_upgrade.cdb/db_upg_opd.cMeasured with
CC=gcc --coverage, lcov captured from.libs, in the nix devshell.
Documented gaps (engine NOT changed)
db_upg_opd.c(__db_31_offdup, 3.0→3.1 off-page-dup conversion) needsa genuine 3.0-era off-page-duplicate page chain (linked
__P_DUPLICATEpages). Rewriting a current db can't produce it — current off-page dups are
already stored as a Recno tree (P_LRECNO/P_IRECNO), not a flat page chain. A
genuine pre-3.1 fixture is required.
__db_set_lastpgnooff-by-one (finding, not fixed). The btree v6/v7upgrade path calls
__db_set_lastpgno(), which stores__db_lastpgno()'sresult — the page count (
bytes/pagesize) — directly intometa->last_pgno, which is the last page number (count-1). On apage-aligned file that is off by exactly +1, and
db_verifythen reportslast_pgno is not correct: N != N-1(db_vrfy.c, underHAVE_FTRUNCATE).The hash path avoids it because its v8→v9 pass runs through mpool, which
recomputes
last_pgnocorrectly on close.__db_set_lastpgnois byte-for-byteidentical to upstream Berkeley DB 4.7/4.8, so this is likely a long-standing
latent defect. The fixtures here are synthetic, so the driver upgrades the
btree v6/v7 fixtures (to cover the transform) but skips
db_verifyon them,asserting the metadata version bumped instead — and this is reported to
confirm against a genuine old fixture rather than patched.
Validation
Built with
--enable-debug --enable-testin the nix dev shell; the driverpasses (all
db_upgrade/db_verifyruns undertimeout) and is idempotentacross re-runs. It is already wired into
test/coverage/run_coverage.shvia theCOV_XA_UPGblock (default on).