Skip to content

Commit eea7f5a

Browse files
use as go module, win support (#21)
1 parent b811f2d commit eea7f5a

42 files changed

Lines changed: 36767 additions & 1476 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ jobs:
66
strategy:
77
matrix:
88
os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15 ] # list of os: https://github.com/actions/virtual-environments
9-
# os: [ubuntu-20.04, macos-10.15, windows-latest] # list of os: https://github.com/actions/virtual-environments
10-
go: [ '1.16', '1.13' ]
9+
go: [ '1.16', '1.15' ]
1110
runs-on: ${{ matrix.os }}
1211

1312
steps:
1413
- uses: actions/checkout@v2
1514

16-
- name: Add Msys64 to PATH # see https://github.com/actions/virtual-environments/issues/1613 and https://github.com/actions/virtual-environments/pull/1648
17-
if: matrix.os == 'windows-latest'
18-
run: echo "::add-path::/c/msys64/mingw64/bin:/c/msys64/usr/bin"
19-
shell: bash
20-
2115
- uses: actions/setup-go@v2
2216
with:
2317
go-version: ${{ matrix.go }}
@@ -27,8 +21,24 @@ jobs:
2721
path: ~/go/pkg/mod
2822
key: go-${{ matrix.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
2923

30-
- name: Test
31-
run: cc --version && make test
24+
- run: go test -v ./...
3225

3326
- name: Race
3427
run: make race
28+
29+
win:
30+
strategy:
31+
matrix:
32+
os: [ windows-2019 ] # list of os: https://github.com/actions/virtual-environments
33+
go: [ '1.16' ]
34+
runs-on: ${{ matrix.os }}
35+
36+
steps:
37+
- uses: actions/checkout@v2
38+
39+
- uses: actions/setup-go@v2
40+
with:
41+
go-version: ${{ matrix.go }}
42+
43+
- run: choco upgrade mingw cmake -y --no-progress
44+
- run: go test -v ./...

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# c repository for updating after each release
2-
/lmdb/lmdb
3-
/lmdb/openldap
1+
.idea
42

53
/bin/
64
/build

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ linters:
1313
- errcheck
1414
- goconst
1515
- gofmt
16-
- golint
17-
- interfacer
1816
- govet
1917
- structcheck
2018
- stylecheck
2119
- staticcheck
2220
# - goerr113
2321
- unconvert
2422
- unparam
25-
- scopelint
2623
- nakedret
2724
- prealloc
2825
- gosimple
@@ -31,7 +28,6 @@ linters:
3128
- depguard
3229
- typecheck
3330
- misspell
34-
- maligned
3531

3632
linters-settings:
3733
gofmt:

Makefile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)"
99
deps: lintci-deps
1010
go get -d ./...
1111

12-
all: deps check mdbx-build
12+
all: deps check
1313

14-
test: mdbx-build
14+
test:
1515
go test ./mdbx ./exp/mdbxpool
1616

17-
race: mdbx-build
17+
race:
1818
go test -race ./mdbx ./exp/mdbxpool
1919

20-
lint: mdbx-build
20+
lint:
2121
./build/bin/golangci-lint run --new-from-rev=$(MASTER_COMMIT) ./...
2222

2323
lintci-deps:
2424
rm -f ./build/bin/golangci-lint
25-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./build/bin v1.31.0
25+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./build/bin v1.41.0
2626

2727
check:
2828
which goimports > /dev/null
@@ -32,7 +32,3 @@ check:
3232

3333
clean:
3434
cd mdbx/dist/ && make clean
35-
36-
mdbx-build:
37-
echo "Building mdbx"
38-
cd mdbx/dist/ && make clean && make config.h && CFLAGS_EXTRA="-Wno-deprecated-declarations" make mdbx-static.o

README.md

Lines changed: 65 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
# mdbx-go
1+
# mdbx-go
22

3-
Go bindings to the libmdbx: https://github.com/erthink/libmdbx
3+
Go bindings to the libmdbx: https://erthink.github.io/libmdbx/
4+
5+
Most of articles in internet about LMDB are applicable to MDBX. But mdbx has more features.
6+
7+
For deeper DB understanding please read through [mdbx.h](https://github.com/erthink/libmdbx/blob/master/mdbx.h)
8+
9+
## Min Requirements
10+
11+
C language Compilers compatible with GCC or CLANG (mingw 10 on windows)
12+
Golang: 1.15
413

514
## Packages
615

7-
Functionality is logically divided into several packages. Applications will
8-
usually need to import **mdbx** but may import other packages on an as needed
9-
basis.
16+
Functionality is logically divided into several packages. Applications will usually need to import **mdbx** but may
17+
import other packages on an as needed basis.
1018

11-
Packages in the `exp/` directory are not stable and may change without warning.
12-
That said, they are generally usable if application dependencies are managed
13-
and pinned by tag/commit.
19+
Packages in the `exp/` directory are not stable and may change without warning. That said, they are generally usable if
20+
application dependencies are managed and pinned by tag/commit.
1421

1522
Developers concerned with package stability should consult the documentation.
1623

@@ -24,59 +31,34 @@ Core bindings allowing low-level access to MDBX.
2431

2532
#### exp/mdbxpool [![GoDoc](https://godoc.org/github.com/torquem-ch/mdbx-go/mdbx/exp/mdbxpool?status.svg)](https://godoc.org/github.com/torquem-ch/mdbx-go/mdbx/exp/mdbxpool) [![experimental](https://img.shields.io/badge/stability-experimental-red.svg)](#user-content-versioning-and-stability)
2633

27-
2834
```go
2935
import "github.com/torquem-ch/mdbx-go/exp/mdbxpool"
3036
```
3137

32-
A utility package which facilitates reuse of mdbx.Txn objects using a
33-
sync.Pool. Naively storing mdbx.Txn objects in sync.Pool can be troublesome.
34-
And the mdbxpool.TxnPool type has been defined as a complete pooling solution
35-
and as reference for applications attempting to write their own pooling
36-
implementation.
37-
38-
The mdbxpool package is relatively new. But it has a lot of potential utility.
39-
And once the mdbxpool API has been ironed out, and the implementation hardened
40-
through use by real applications it can be integrated directly into the mdbx
41-
package for more transparent integration. Please test this package and provide
42-
feedback to speed this process up.
38+
A utility package which facilitates reuse of mdbx.Txn objects using a sync.Pool. Naively storing mdbx.Txn objects in
39+
sync.Pool can be troublesome. And the mdbxpool.TxnPool type has been defined as a complete pooling solution and as
40+
reference for applications attempting to write their own pooling implementation.
4341

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

4546
## Key Features
4647

4748
### Idiomatic API
4849

49-
API inspired by [BoltDB](https://github.com/boltdb/bolt) with automatic
50-
commit/rollback of transactions. The goal of mdbx-go is to provide idiomatic
51-
database interactions without compromising the flexibility of the C API.
52-
53-
**NOTE:** While the mdbx package tries hard to make MDBX as easy to use as
54-
possible there are compromises, gotchas, and caveats that application
55-
developers must be aware of when relying on MDBX to store their data. All
56-
users are encouraged to fully read the
57-
[documentation](https://godoc.org/github.com/torquem-ch/mdbx-go/mdbx) so they are
58-
aware of these caveats.
59-
60-
### API coverage
61-
62-
The mdbx-go project aims for complete coverage of the MDBX C API (within
63-
reason). Some notable features and optimizations that are supported:
64-
65-
- Idiomatic subtransactions ("sub-updates") that allow the batching of updates.
66-
67-
- Batch IO on databases utilizing the `MDB_DUPSORT` and `MDB_DUPFIXED` flags.
50+
API inspired by [BoltDB](https://github.com/boltdb/bolt) with automatic commit/rollback of transactions. The goal of
51+
mdbx-go is to provide idiomatic database interactions without compromising the flexibility of the C API.
6852

69-
- Reserved writes than can save in memory copies converting/buffering into
70-
`[]byte`.
53+
**NOTE:** While the mdbx package tries hard to make MDBX as easy to use as possible there are compromises, gotchas, and
54+
caveats that application developers must be aware of when relying on MDBX to store their data. All users are encouraged
55+
to fully read the [documentation](https://erthink.github.io/libmdbx/) so they are aware of these caveats. And even
56+
better if read through [mdbx.h](https://github.com/erthink/libmdbx/blob/master/mdbx.h)
7157

72-
For tracking purposes a list of unsupported features is kept in an
73-
[issue](https://github.com/torquem-ch/mdbx-go/issues/1).
58+
### High Performance notices
7459

75-
### Zero-copy reads
76-
77-
Applications with high performance requirements can opt-in to fast, zero-copy
78-
reads at the cost of runtime safety. Zero-copy behavior is specified at the
79-
transaction level to reduce instrumentation overhead.
60+
Applications with high performance requirements can opt-in to fast, zero-copy reads at the cost of runtime safety.
61+
Zero-copy behavior is specified at the transaction level to reduce instrumentation overhead.
8062

8163
```
8264
err := mdbx.View(func(txn *mdbx.Txn) error {
@@ -89,91 +71,69 @@ err := mdbx.View(func(txn *mdbx.Txn) error {
8971
})
9072
```
9173

92-
## MDBX compared to BoltDB
93-
94-
BoltDB is a quality database with a design similar to MDBX. Both store
95-
key-value data in a file and provide ACID transactions. So there are often
96-
questions of why to use one database or the other.
74+
Use NoReadahead if Data > RAM
9775

9876
### Advantages of BoltDB
9977

10078
- Nested databases allow for hierarchical data organization.
10179

10280
- Far more databases can be accessed concurrently.
10381

104-
- Operating systems that do not support sparse files do not use up excessive
105-
space due to a large pre-allocation of file space.
82+
- No `Bucket` object - means less allocations and higher performance
83+
84+
- Operating systems that do not support sparse files do not use up excessive space due to a large pre-allocation of file
85+
space.
10686

10787
- As a pure Go package bolt can be easily cross-compiled using the `go`
10888
toolchain and `GOOS`/`GOARCH` variables.
10989

110-
- Its simpler design and implementation in pure Go mean it is free of many
111-
caveats and gotchas which are present using the MDBX package. For more
112-
information about caveats with the MDBX package, consult its
113-
[documentation](https://godoc.org/github.com/torquem-ch/mdbx-go/mdbx).
90+
- Its simpler design and implementation in pure Go mean it is free of many caveats and gotchas which are present using
91+
the MDBX package. For more information about caveats with the MDBX package, consult its
92+
[documentation](https://erthink.github.io/libmdbx/) so they are aware of these caveats. And even better if read
93+
through [mdbx.h](https://github.com/erthink/libmdbx/blob/master/mdbx.h).
11494

115-
### Advantages of LMDB and MDBX
95+
### Advantages of MDBX
11696

11797
- Keys can contain multiple values using the DupSort flag.
11898

11999
- Updates can have sub-updates for atomic batching of changes.
120100

121-
- Databases typically remain open for the application lifetime. This limits
122-
the number of concurrently accessible databases. But, this minimizes the
123-
overhead of database accesses and typically produces cleaner code than
124-
an equivalent BoltDB implementation.
125-
126-
- Significantly faster than BoltDB. The raw speed of MDBX easily surpasses
127-
BoltDB. Additionally, MDBX provides optimizations ranging from safe,
128-
feature-specific optimizations to generally unsafe, extremely situational
129-
ones. Applications are free to enable any optimizations that fit their data,
130-
access, and reliability models.
131-
132-
- MDBX allows multiple applications to access a database simultaneously.
133-
Updates from concurrent processes are synchronized using a database lock
134-
file.
135-
136-
- As a C library, applications in any language can interact with MDBX
137-
databases. Mission critical Go applications can use a database while Python
138-
scripts perform analysis on the side.
139-
140-
## Build
101+
- Databases typically remain open for the application lifetime. This limits the number of concurrently accessible
102+
databases. But, this minimizes the overhead of database accesses and typically produces cleaner code than an
103+
equivalent BoltDB implementation.
141104

142-
There is no dependency on shared libraries. But it's impossible to use 'go get' for now. Only way is to copy sources of this package to your project, and call `make mdbx-build` manually. See: https://github.com/torquem-ch/mdbx-go/issues/5
105+
- Significantly faster than BoltDB. The raw speed of MDBX easily surpasses BoltDB. Additionally, MDBX provides
106+
optimizations ranging from safe, feature-specific optimizations to generally unsafe, extremely situational ones.
107+
Applications are free to enable any optimizations that fit their data, access, and reliability models.
143108

144-
On FreeBSD 10, you must explicitly set `CC` (otherwise it will fail with a
145-
cryptic error), for example:
109+
- MDBX allows multiple applications to access a database simultaneously. Updates from concurrent processes are
110+
synchronized using a database lock file.
146111

147-
CC=clang go test -v ./...
112+
- As a C library, applications in any language can interact with MDBX databases. Mission critical Go applications can
113+
use a database while Python scripts perform analysis on the side.
148114

149-
## Documentation
150-
151-
### Go doc
152-
153-
The `go doc` documentation available on
154-
[godoc.org](https://godoc.org/github.com/torquem-ch/mdbx-go) is the primary source
155-
of developer documentation for mdbx-go. It provides an overview of the API
156-
with a lot of usage examples. Where necessary the documentation points out
157-
differences between the semantics of methods and their C counterparts.
115+
## Build
158116

159-
### LMDB
117+
On FreeBSD 10, you must explicitly set `CC` (otherwise it will fail with a cryptic error), for example:
160118

161-
The LMDB [homepage](http://symas.com/mdb/)
119+
CC=clang go test -v ./...
162120

163-
### MDBX
121+
## Documentation
164122

165-
The MDBX [homepage](https://github.com/erthink/libmdbx)
123+
- Examples see in *_test.go files of this repo
124+
- [The MDBX](https://erthink.github.io/libmdbx/) And even better if read
125+
through [mdbx.h](https://github.com/erthink/libmdbx/blob/master/mdbx.h).
126+
- [godoc.org](https://godoc.org/github.com/torquem-ch/mdbx-go)
127+
- [The LMDB](http://symas.com/mdb/)
166128

167129
### Versioning and Stability
168130

169-
The mdbx-go project makes regular releases with IDs `X.Y.Z`. All packages
170-
outside of the `exp/` directory are considered stable and adhere to the
171-
guidelines of [semantic versioning](http://semver.org/).
131+
The mdbx-go project makes regular releases with IDs `X.Y.Z`. All packages outside of the `exp/` directory are considered
132+
stable and adhere to the guidelines of [semantic versioning](http://semver.org/).
172133

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

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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/torquem-ch/mdbx-go
22

3-
go 1.13
3+
go 1.15

internal/mdbxcmd/cmutil.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

mdbx/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.dylib
33
*.o
44
config.h
5+
config2.h
56
config_darwin.h
67
config_linux.h
78
config_win.h

0 commit comments

Comments
 (0)