Skip to content

WIP: Upgrade to lmdb-go v2 (dual-engine LMDB 0.9 + 1.0) - #3

Draft
wojas wants to merge 8 commits into
masterfrom
lmdb-go-v2
Draft

wojas wants to merge 8 commits into
masterfrom
lmdb-go-v2

Conversation

@wojas

@wojas wojas commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Status: WIP — do not merge

Depends on the unreleased lmdb-go v2 (PowerDNS/lmdb-go#42). Until v2 is published, go.mod carries a temporary replace directive pointing at the development fork:

replace github.com/PowerDNS/lmdb-go/v2 => github.com/wojas/lmdb-go/v2 v2.0.0-20260828152212-7d658404dccc

While the replace is present, remote go install of this branch is not possible; install from a source checkout (the README notes this). Before this can merge: lmdb-go v2 must be tagged, the replace dropped, and the requirement pinned to the released version.

Changes

  • Upgrade to github.com/PowerDNS/lmdb-go/v2 — drop-in apart from the import path. With v2, lmdbnav transparently opens both LMDB 0.9- and 1.0-format databases (engine selected per environment by sniffing the data file). Also bumps go 1.17 → go 1.21 (required by v2).
  • Show the LMDB engine version in the footer (via the new Env.EngineVersion), e.g. LMDB 1.0.0 | MapSize …, so it's always visible which engine is driving the opened database.
  • Handle LMDB 1.0 root DBI keys — the 1.0 format stores a database name's terminating null byte in the root DBI key (0.9 stores the bare name). Names are now derived via a format-aware helper (Env.Format), which doubles as an extra validity filter on 1.0. Verified that the 48-byte MDB_db record check remains valid for both formats (identical struct layout).
  • Fix a latent bug in the total-used-space scan — it ignored OpenDBI errors (accidentally including free-list stats via DBI handle 0) and had no record filter; it now skips non-DBI entries like the databases view does.
  • New --prev-snapshot flag (LMDB 1.0 only) — opens the environment one commit back via the new lmdb.PrevSnapshot, for inspecting databases whose latest transaction is corrupted. The footer shows (prev snapshot); a 0.9 database fails with a clear error. Safe by construction: lmdbnav always opens readonly, so the rollback never becomes permanent.
  • README: installation instructions for users unfamiliar with Go development (Go + C compiler prerequisites, go install, PATH/GOBIN), with a note that installs must come from a source checkout while the replace directive is in place.
  • Fix a go vet warning (%w in log.Printf).

Testing

Verified against generated 0.9- and 1.0-format test databases: database listing, browsing, footer stats, engine version display, and --prev-snapshot (previous state shown, footer indicator, 0.9 error path). Install from a source checkout verified.

🤖 Generated with Claude Code

wojas and others added 8 commits August 28, 2026 21:47
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
LMDB 1.0 stores a database name's terminating null byte in the root
DBI key, while 0.9 stores the bare name. Strip it (and require it as
a validity check) when listing databases.

The total-used-space scan now also skips non-DBI records and OpenDBI
errors instead of accidentally including free list stats via DBI 0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Opens the environment with lmdb.PrevSnapshot to inspect the state as
of the previous commit, e.g. when the latest transaction is corrupted.
The footer indicates when the previous snapshot is shown. Since
lmdbnav always opens readonly, the rollback never becomes permanent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This makes remote 'go install' work again. Also document installation
for users unfamiliar with Go development.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Restores the installation instructions, now noting that remote
'go install' does not work while the replace directive is present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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