Skip to content

build(flags): preserve flag-value ABI by pinning new flags to high bits#31

Merged
gburd merged 1 commit into
masterfrom
fix/flag-abi-stability
Jun 23, 2026
Merged

build(flags): preserve flag-value ABI by pinning new flags to high bits#31
gburd merged 1 commit into
masterfrom
fix/flag-abi-stability

Conversation

@gburd

@gburd gburd commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

What

Preserve the public flag-constant ABI by pinning the two recently-added
flags to high, previously-unused bits instead of letting the api_flags
bit allocator repack their groups.

Why

Adding DB_MPOOL_AIO (AIO Stage 2, #24) and DB_TXN_SNAPSHOT_SAFE (SSI) to
their flag groups made the greedy bit allocator renumber the public values
of several existing flags:

flag was became
DB_NOFLUSH 0x1000 0x2000
DB_NOLOCKING 0x2000 0x4000
DB_NOPANIC 0x4000 0x8000
DB_OVERWRITE 0x8000 0x10000
DB_PANIC_ENVIRONMENT 0x10000 0x20000
DB_REGION_INIT 0x20000 0x40000
DB_TIME_NOTGRANTED 0x40000 0x80000
DB_YIELDCPU 0x80000 0x100000
DB_TXN_WAIT 0x80 0x100

Changing public flag values is an ABI break for the constants (a
precompiled application that baked in the old value and links a new libdb
would pass the wrong flag).

How

Add a __PIN=<value> annotation to dist/api_flags. A pinned flag's bit is
reserved in its APIs' masks before the greedy pass and skipped during
allocation, so it takes a fixed bit without disturbing any other flag.

Pin DB_MPOOL_AIO = 0x00100000 and DB_TXN_SNAPSHOT_SAFE = 0x00000800
both free in their respective APIs at the pre-change baseline.

Verification

  • src/dbinc_auto/api_flags.in now differs from the pre-AIO baseline
    (eae0c147e) by exactly the two added #defines — zero value changes to
    any existing flag.
  • Regenerated Java/C# DbConstants accordingly (they revert to baseline
    values).
  • Builds clean (autoconf); TCL test001, test012, and ssi001/ssi002
    (which exercise DB_TXN_SNAPSHOT_SAFE) pass.

Adding DB_MPOOL_AIO and DB_TXN_SNAPSHOT_SAFE to their set_flags/txn_begin
flag groups made the api_flags bit allocator repack those groups, which
renumbered the public values of several existing flags (DB_NOFLUSH,
DB_NOLOCKING, DB_NOPANIC, DB_OVERWRITE, DB_PANIC_ENVIRONMENT,
DB_REGION_INIT, DB_TIME_NOTGRANTED, DB_YIELDCPU, DB_TXN_WAIT).  That is an
ABI change for the public flag constants.

Add a __PIN=<value> annotation to dist/api_flags so a flag can be assigned
a fixed bit that the greedy allocator reserves up-front and skips.  Pin
DB_MPOOL_AIO to 0x00100000 and DB_TXN_SNAPSHOT_SAFE to 0x00000800 -- both
free in their APIs at the pre-change baseline -- so every pre-existing
public flag keeps its original value and the change is purely additive.

Verified: src/dbinc_auto/api_flags.in now differs from the pre-AIO baseline
by exactly the two added #defines, with zero value changes to existing
flags; regenerated Java/C# constants accordingly.  TCL test001/012 and
ssi001/002 (which exercise DB_TXN_SNAPSHOT_SAFE) pass.
@gburd gburd merged commit e186e8c into master Jun 23, 2026
36 of 39 checks passed
@gburd gburd deleted the fix/flag-abi-stability branch June 23, 2026 20:03
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