Home

Awesome

mdbx-go

Go bindings to the libmdbx: https://libmdbx.dqdkfa.ru

Notice: page ./mdbx contains only mdbx.h and mdbx.c - to minimize go build time/size. But full version of libmdbx (produced by it's make dist command) is in ./../mdbxdist/. License is also there.

Most of articles in internet about LMDB are applicable to MDBX. But mdbx has more features.

For deeper DB understanding please read through mdbx.h

Min Requirements

C language Compilers compatible with GCC or CLANG (mingw 10 on windows) Golang: 1.15

Packages

Functionality is logically divided into several packages. Applications will usually need to import mdbx but may import other packages on an as needed basis.

Packages in the exp/ directory are not stable and may change without warning. That said, they are generally usable if application dependencies are managed and pinned by tag/commit.

Developers concerned with package stability should consult the documentation.

mdbx GoDoc stable

import "github.com/torquem-ch/mdbx-go/mdbx"

Core bindings allowing low-level access to MDBX.

exp/mdbxpool GoDoc experimental

import "github.com/torquem-ch/mdbx-go/exp/mdbxpool"

A utility package which facilitates reuse of mdbx.Txn objects using a sync.Pool. Naively storing mdbx.Txn objects in sync.Pool can be troublesome. And the mdbxpool.TxnPool type has been defined as a complete pooling solution and as reference for applications attempting to write their own pooling implementation.

The mdbxpool package is relatively new. But it has a lot of potential utility. And once the mdbxpool API has been ironed out, and the implementation hardened through use by real applications it can be integrated directly into the mdbx package for more transparent integration. Please test this package and provide feedback to speed this process up.

Key Features

Idiomatic API

API inspired by BoltDB with automatic commit/rollback of transactions. The goal of mdbx-go is to provide idiomatic database interactions without compromising the flexibility of the C API.

NOTE: While the mdbx package tries hard to make MDBX as easy to use as possible there are compromises, gotchas, and caveats that application developers must be aware of when relying on MDBX to store their data. All users are encouraged to fully read the documentation so they are aware of these caveats. And even better if read through mdbx.h

High-Performance notices

Applications with high-performance requirements can opt-in to fast, zero-copy reads at the cost of runtime safety. Zero-copy behavior is specified at the transaction level to reduce instrumentation overhead.

err := mdbx.View(func(txn *mdbx.Txn) error {
    // RawRead enables zero-copy behavior with some serious caveats.
    // Read the documentation carefully before using.
    txn.RawRead = true

    val, err := txn.Get(dbi, []byte("largevalue"), 0)
    // ...
})

Use NoReadahead if Data > RAM

Advantages of BoltDB

Advantages of LMDB over BoltDB

Advantages of MDBX over LMDB

See in mdbx's readme.md

Build

On FreeBSD 10, you must explicitly set CC (otherwise it will fail with a cryptic error), for example:

CC=clang go test -v ./...

Update C code

In libmdbx repo: make dist && cp -R ./dist/* ./../mdbx-go/mdbxdist/. Then in mdbx-go repo: make cp

Build binaries

In mdbx-go repo: MDBX_BUILD_TIMESTAMP=unknown make tools

Or if use mdbx-go as a library:

go mod vendor && cd vendor/github.com/torquem-ch/mdbx-go && make tools 
rm -rf vendor

Documentation

Versioning and Stability

The mdbx-go project makes regular releases with IDs X.Y.Z. All packages outside of the exp/ directory are considered stable and adhere to the guidelines of semantic versioning.

Experimental packages (those packages in exp/) are not required to adhere to semantic versioning. However packages specifically declared to merely be "unstable" can be relied on more for long-term use with less concern.

The API of an unstable package may change in subtle ways between minor release versions. But deprecations will be indicated at least one release in advance and all functionality will remain available through some method.