Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bec37ef
v2: rename module to github.com/PowerDNS/lmdb-go/v2
wojas Aug 27, 2026
d3ce13c
v2: two-stream vendoring tooling with rename generation and patch series
wojas Aug 27, 2026
c7264d7
v2: vendor LMDB 0.9.35 and 1.0.0 side by side behind rename headers
wojas Aug 27, 2026
6ddc901
v2: C dispatch layer (lmdbgo2_*) and Go call-site conversion
wojas Aug 27, 2026
603c0e9
v2: keep Cursor at 16 bytes; guard closed-cursor ops in Go
wojas Aug 27, 2026
55678e6
v2: per-Env engine selection with Go-side buffering, sniffing, versio…
wojas Aug 27, 2026
69a9e88
v2: patch LMDB 1.0 cursor-close-after-txn use-after-free; 1.0 error c…
wojas Aug 27, 2026
3816ef5
v2: dual-engine test coverage, v1+v2 coexistence test, CI matrix
wojas Aug 27, 2026
d969f63
v2: keep Txn at 64 bytes by packing ver into the bools' padding
wojas Aug 27, 2026
f8e65a2
v2: documentation for the dual-engine release
wojas Aug 27, 2026
8b06f03
v2: Version() reports both bundled engines; docs corrections
wojas Aug 28, 2026
1c1f70a
v2: audit assumptions inherited from the anylmdb experiment
wojas Aug 27, 2026
519a795
v2: expose the MDB_PREVSNAPSHOT open flag as lmdb.PrevSnapshot
wojas Aug 28, 2026
0b7c04b
v2: rename LMDBVersion to Format; fix CopyFD doc attachment
wojas Aug 28, 2026
6587ece
v2: doc-comment audit after the Format rename
wojas Aug 28, 2026
7d65840
v2: portable mktemp invocation in scripts
wojas Aug 28, 2026
c0f1bcc
v2: rewrite README intro for users coming from v1
wojas Sep 3, 2026
0f5cd02
v2: ReaderCheck on an unopened Env returns the not-open error
wojas Sep 3, 2026
b006be6
v2: update the LMDB 1.0 stream to 1.0.1
wojas Sep 3, 2026
50d74ac
v2: enable the LMDB 1.0 engine on Windows
wojas Sep 3, 2026
0836ff1
v2: fix TestResize helper binary name on Windows
wojas Sep 3, 2026
489f43d
v2: reject Cursor.Renew with a transaction from another Env
wojas Sep 3, 2026
1ffd17d
v2: CI: run the C checks and the full suite on macOS
wojas Sep 3, 2026
3e9cb00
v2: fix TestCursor_Renew_crossEnv temp-dir cleanup order on Windows
wojas Sep 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- master

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1 will become the "v1" branch
v2 will be the new master branch

- v2-dual-lmdb-versions
pull_request:
branches:
- master
Expand All @@ -21,7 +22,7 @@ jobs:
- '1.22'
- '1.23'
- '1.x'

name: Go ${{ matrix.go }} tests
steps:
- uses: actions/checkout@v3
Expand All @@ -33,6 +34,80 @@ jobs:
run: go install golang.org/x/lint/golint@latest
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
# `make all` runs the full suite against BOTH bundled LMDB engines
# (0.9 default and LMDBGO_DEFAULT_FORMAT=10), the C-level checks
# (shared-define parity, ASan cursor-close reproducer), and -race.
- name: Build and test
run: make all
- name: Symbol hygiene
run: |
go test -c -o /tmp/lmdb.test ./lmdb
# No unprefixed mdb_* global may be defined: both engines are
# renamed (mdb09_*/mdb10_*) so v2 can coexist with lmdb-go v1.
if nm /tmp/lmdb.test | grep -E ' [TDSBC] _?mdb' | grep -vE 'mdb(09|10)_'; then
echo "ERROR: unprefixed mdb symbols found"; exit 1
fi

coexist:
runs-on: ubuntu-22.04
name: v1+v2 coexistence
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.x'
# Links lmdb-go v1 (unprefixed LMDB 0.9 + lmdbgo_* helpers) and v2
# into one test binary and cross-reads database files between them.
- name: Coexistence test
run: make coexist-test

windows-build:
runs-on: ubuntu-22.04
name: Windows cross-build
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.x'
- name: Install mingw
run: sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64
# Catches Windows compile and link breakage cheaply on every push;
# the windows-test job runs the actual suite.
- name: Cross-build for windows/amd64
run: CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build ./...

windows-test:
runs-on: windows-2022
name: Windows tests
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.x'
# cgo needs a C compiler; the runner image ships mingw-w64 gcc on PATH.
# Mirrors the Makefile "test" target: the full suite once per engine,
# selected via the process-wide default format.
- name: Test (0.9 default)
run: go test ./...
- name: Test (1.0 default)
run: go test -count=1 ./...
env:
LMDBGO_DEFAULT_FORMAT: "10"

macos-test:
runs-on: macos-latest
name: macOS tests
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.x'
# Apple clang is the cgo compiler here. Runs the C-level checks (the
# ASan cursor-close reproducer builds with clang's sanitizer) and the
# full suite once per engine, plain and with -race.
- name: C checks and tests (both engines, -race)
run: make check-c full-test
16 changes: 16 additions & 0 deletions CHANGES.lmdb.txt → CHANGES.lmdb09.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
LMDB 0.9 Change Log

LMDB 0.9.35 Release (2026/01/27)
ITS#10434 - Fix typo affecting Mac OSX

LMDB 0.9.34 Release (2026/01/26)
ITS#9564 - fix race condition freeing spilled pages at end of transaction
ITS#10222 - Update mdb_dump(1) and mdb_load(1) man pages for append (-a) option
ITS#10275 - mdb_load: add -Q option to use NOSYNC
ITS#10296 - fix fdatasync on MacOS
ITS#10342 - fix memleak in mdb_txn_begin for nested txns
ITS#10346 - fix mdb_env_copy2 with values > (2GB-16)
ITS#10355 - fix mplay build on musl
ITS#10396 - fix mdb_cursor_del0 with multiple DUPSORT cursors
ITS#10419 - add support for NetBSD
ITS#10420 - add support for Haiku
ITS#10421 - mdb_load: check for malicious input

LMDB 0.9.33 Release (2024/05/21)
ITS#9037 mdb_page_search: fix error code when DBI record is missing
ITS#10198 For win32, stop passing ignored parameter
Expand Down
15 changes: 15 additions & 0 deletions CHANGES.lmdb10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LMDB 1.0 Change Log

LMDB 1.0.1 Release (2026/08/06)
ITS#10529 - invalidate DBIs in rollback
ITS#10534 - update mdb_env_get_maxkeysize() doc
ITS#10536 - re-fix mdb_drop(MAIN_DBI)
ITS#10538 - fix large writes on Windows
ITS#10539 - Windows build fixes
ITS#10540 - cleanup outdated license notices
ITS#10542 - Windows buffered/writethru write behavior
ITS#10551 - fix mdb_page_split nodesize calculation
ITS#10553 - Another Windows build fix

LMDB 1.0.0 Release (2026/06/30)
Many fixes/enhancements
116 changes: 116 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,121 @@
# Release Change Log

## v2.0.0 (unreleased)

lmdb-go v2 ships **both LMDB 0.9 (0.9.35) and LMDB 1.0 (1.0.1)** in one
module. LMDB 1.0 introduced a new on-disk format that 0.9 cannot read, and a
C program can normally link only one of the two libraries; v2 bundles both
and picks one per environment when it is opened. An existing database is
opened with the engine matching its format, detected from the file header.
A new database uses the 0.9 format unless you ask for 1.0 with
`Env.SetFormat(lmdb.V10)`, `SetDefaultFormat`, or `LMDBGO_DEFAULT_FORMAT=10`.
Databases of both formats can be open in the same process.

**Upgrading from v1** is an import path change: `github.com/PowerDNS/lmdb-go/...`
becomes `github.com/PowerDNS/lmdb-go/v2/...`. The Go API is otherwise
drop-in compatible, and existing databases keep working unchanged. The edge
cases that behave differently are listed under "Behavior differences vs v1"
below; the README has a walkthrough. v1 and v2 can be linked into the same
binary. v1 continues on its own branch with `v1.x.y` releases.

### New API

* `Env.SetFormat` / `Env.Format` / `Env.EngineVersion` — per-env
engine selection (new databases only; an explicit request conflicting with
an existing database's format fails with `ErrFormatConflict`) and
introspection.
* `SetDefaultFormat`, `LMDBGO_DEFAULT_FORMAT` environment variable —
process-wide default for new databases (`V09` unless changed).
* `SniffFormat` — detect a database's format without opening it (safe: a
wrong-version `mdb_env_open` can clobber the lock file). lmdb-js prerelease
files are rejected with `ErrFormatUnsupported`.
* LMDB 1.0 error constants (`Problem`, `BadChecksum`, `CryptoFail`,
`EnvEncryption`, `TxnPending`, `CantRollback`, `DBIsBusy`, `ShortWrite`,
`EnvBusy`, `IsReadonly`, `AddrBusy`), always defined; the 0.9 engine never
returns them.
* `PrevSnapshot` open flag (`MDB_PREVSNAPSHOT`): open the environment with
the previous snapshot rather than the latest one, losing the latest
transaction — useful for working around some types of corruption. LMDB
1.0 engine only; the 0.9 engine rejects it with `EINVAL`.

### Internals

* Both vendored trees are compiled behind generated symbol-rename headers
(`mdb09_*` / `mdb10_*`); every LMDB call dispatches through a thin C shim
on a per-environment engine selector. Overhead vs v1 is one `int` argument
plus a predicted branch per call: running the full benchmark suite against
v1 on the same (0.9) engine, v2 is on average slightly *faster* (1.9% less
time per op, geometric mean across the suite — i.e. within noise plus the
0.9.33 → 0.9.35 upstream delta), no benchmark got more than 2.5% slower,
and allocations are byte-identical (Txn and Cursor keep their v1
allocation size classes, pinned by a test).
* Engine choice itself has a performance profile (upstream characteristics,
not dispatch): on the 1.0 engine, *creating* a readonly transaction is
substantially more expensive than on 0.9 (reader page cache setup;
+15–47% on per-op-allocating readonly benchmarks), while renewed/pooled
readonly transactions and write paths stay within a few percent and
sub-transactions are 13–18% faster. Readonly-heavy workloads on the 1.0
engine benefit from `Txn.Renew`/pooling, as the docs already recommend.
* All v2 C symbols are namespaced (`lmdbgo2_*` glue), so **v1 and v2 can be
linked into the same binary**; `tests/coexist/` verifies this in CI.
* The vendored trees can carry local patches (`lmdb/patches/`, applied by
`update-lmdb.sh`, documented in `PATCH-STATUS.md`). v2 ships
`cursor-close-after-txn.patch`: pristine LMDB 1.0.x has a use-after-free
when a read-only cursor is closed after its transaction ended (a sequence
LMDB documents as legal, and that lmdb-go finalizers rely on).

### Behavior differences vs v1

* `NewEnv` no longer creates the engine environment (the engine is only
known at `Open`); `mdb_env_create` errors are reported by `Open`. Pre-open
setters (`SetMapSize`, `SetMaxReaders`, `SetMaxDBs`, `SetFlags`,
`UnsetFlags`) buffer on the Go side and are replayed at `Open`; observable
behavior (including `EINVAL` for non-changeable flags and pre-open
`Flags`/`MaxReaders` reads) is preserved.
* Pre-open `Stat`, `Info`, `Sync`, `Copy*`, `BeginTxn`, `View`, `Update` now
return a clean error where v1 crashed or returned obscure errnos, and
pre-open `ReaderCheck` returns the same error where v1 reported 0 cleared
entries; a failed `Open` can be retried; `Close` is always safe, also
before `Open`.
* Cursor methods on a closed cursor return `EINVAL` errors (v1 panicked for
`Get`/`Del`/`Count`; `Put` already returned `EINVAL`). Nil handles never
reach the C engines.
* `Cursor.Renew` with a transaction from a different `Env` returns `EINVAL`.
v1 passed it to C, which only validates the DBI index and would silently
use the cursor in the wrong environment; with two engines whose cursor
layouts differ, it would also write past the cursor's allocation.
* With two bundled engines there is no single "the LMDB version", so
package `Version`/`VersionString` report the newest bundled engine —
numerically 1.0.x, matching the canonical header surface the bindings are
compiled against — with a release string naming both engines. Use
`Env.EngineVersion` for the engine driving a specific environment.
* `Txn.OpenDBI("")` fails with `BadValSize` on the 0.9 engine but `NotFound`
on 1.0. `Env.MaxKeySize` is engine-dependent post-open (511 on 0.9; the
1.0 engine derives it from the page size, 8122 for 4K pages) and 511
pre-open.
* Error codes −30779…−30769 (introduced by LMDB 1.0) now map to `Errno`
instead of `syscall.Errno`; error strings come from the 1.0 table.
* Like v1, v2 only supports statically linking the bundled LMDB sources;
dynamic linking against a system liblmdb is not supported and is not
planned for v2.
* Go 1.21 or newer is required.
* The vendored 0.9 stream was upgraded 0.9.33 → 0.9.35 (see
`CHANGES.lmdb09.txt`); LMDB 1.0.1 is vendored as the new 10 stream (see
`CHANGES.lmdb10.txt`).

LMDB C library changes in the 10 stream since the initial 1.0.0 vendoring:

LMDB 1.0.1 Release (2026/08/06)
ITS#10529 - invalidate DBIs in rollback
ITS#10534 - update mdb_env_get_maxkeysize() doc
ITS#10536 - re-fix mdb_drop(MAIN_DBI)
ITS#10538 - fix large writes on Windows
ITS#10539 - Windows build fixes
ITS#10540 - cleanup outdated license notices
ITS#10542 - Windows buffered/writethru write behavior
ITS#10551 - fix mdb_page_split nodesize calculation
ITS#10553 - Another Windows build fix

## v1.9.3 (2025-01-02)

## What's Changed
Expand Down
30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.PHONY: deps all test full-test bin
.PHONY: deps all test test-lmdb09 test-lmdb10 full-test bin bench check check-c coexist-test

deps:
go mod download
Expand All @@ -9,16 +9,38 @@ bin:
GOBIN=${PWD}/bin go install ./exp/cmd/...
GOBIN=${PWD}/bin go install ./cmd/...

all: deps check full-test bin
all: deps check check-c full-test bin

test:
# The full test suite runs once per bundled LMDB engine: the process-wide
# default version decides which engine drives the databases the tests create.
test: test-lmdb09 test-lmdb10

test-lmdb09:
go test -cover ./...

test-lmdb10:
LMDBGO_DEFAULT_FORMAT=10 go test -count=1 -cover ./...

full-test: test
go test -race ./...
LMDBGO_DEFAULT_FORMAT=10 go test -race -count=1 ./...

bench:
go test -run=NONE -bench=. -benchmem -count=6 ./lmdb

# C-level checks: shared-define parity between the two vendored headers, and
# the ASan reproducer for the patched LMDB 1.0 cursor-close use-after-free.
check-c:
scripts/check-defines.sh
scripts/test-cursor-close-asan.sh

# Verifies that lmdb-go v1 and v2 link and work together in one binary
# (requires network access to download v1).
coexist-test:
cd tests/coexist && go test -count=1 ./...

check:
which goimports > /dev/null
find . -name '*.go' | xargs goimports -d | tee /dev/stderr | wc -l | xargs test 0 -eq
find . -name '*.go' | grep -v '^\./\.claude/' | xargs goimports -d | tee /dev/stderr | wc -l | xargs test 0 -eq
which golint > /dev/null
golint ./... | tee /dev/stderr | wc -l | xargs test 0 -eq
Loading
Loading