Skip to content

Commit 010cf60

Browse files
authored
Ensure MDBX_USE_FALLOCATE is enabled (#203)
* Enable MDBX_USE_FALLOCATE * Fix lints
1 parent b036ff3 commit 010cf60

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

check_fallocate.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build ignore
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"strings"
8+
9+
"github.com/erigontech/mdbx-go/mdbx"
10+
)
11+
12+
func main() {
13+
buildOpts := mdbx.BuildOptions()
14+
15+
fmt.Println("=== MDBX Build Options ===")
16+
fmt.Println(buildOpts)
17+
fmt.Println()
18+
19+
// Check for MDBX_USE_FALLOCATE specifically
20+
if strings.Contains(buildOpts, "MDBX_USE_FALLOCATE=1") || strings.Contains(buildOpts, "MDBX_USE_FALLOCATE=AUTO=1") {
21+
fmt.Println("✓ MDBX_USE_FALLOCATE is ENABLED (1)")
22+
} else if strings.Contains(buildOpts, "MDBX_USE_FALLOCATE=0") || strings.Contains(buildOpts, "MDBX_USE_FALLOCATE=AUTO=0") {
23+
fmt.Println("✗ MDBX_USE_FALLOCATE is DISABLED (0)")
24+
} else {
25+
fmt.Println("? MDBX_USE_FALLOCATE status unknown")
26+
}
27+
28+
// Also check _GNU_SOURCE status
29+
if strings.Contains(buildOpts, "_GNU_SOURCE=YES") {
30+
fmt.Println("✓ _GNU_SOURCE is defined")
31+
} else if strings.Contains(buildOpts, "_GNU_SOURCE=NO") {
32+
fmt.Println("✗ _GNU_SOURCE is NOT defined")
33+
}
34+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ toolchain go1.24.1
66

77
require github.com/ianlancetaylor/cgosymbolizer v0.0.0-20241129212102-9c50ad6b591e
88

9-
require golang.org/x/sys v0.31.0 // indirect
9+
require golang.org/x/sys v0.31.0

mdbx/mdbx.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ details about dealing with such situations.
127127
package mdbx
128128

129129
/*
130-
#cgo !windows CFLAGS: -O2 -g -DNDEBUG=1 -std=gnu11 -fvisibility=hidden -ffast-math -fPIC -pthread -Wno-error=attributes -W -Wall -Wextra -Wpedantic -Wno-deprecated-declarations -Wno-format -Wno-format-security -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-unused-function -Wno-format-extra-args -Wno-missing-field-initializers -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes
130+
#cgo !windows CFLAGS: -D_GNU_SOURCE -O2 -g -DNDEBUG=1 -std=gnu11 -fvisibility=hidden -ffast-math -fPIC -pthread -Wno-error=attributes -W -Wall -Wextra -Wpedantic -Wno-deprecated-declarations -Wno-format -Wno-format-security -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-unused-function -Wno-format-extra-args -Wno-missing-field-initializers -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes
131131
#cgo windows CFLAGS: -O2 -g -DNDEBUG=1 -std=gnu11 -fvisibility=hidden -ffast-math -fexceptions -fno-common -W -Wno-deprecated-declarations -Wno-bad-function-cast -Wno-cast-function-type -Wall -Wno-format -Wno-format-security -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-unused-function -Wno-format-extra-args -Wno-missing-field-initializers -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes
132132
133133
#cgo windows LDFLAGS: -lntdll
@@ -175,6 +175,16 @@ func Version() string {
175175
return C.GoString(C.mdbx_version.git.describe)
176176
}
177177

178+
// BuildOptions returns the build-time configuration options used when
179+
// compiling libmdbx. This includes settings like MDBX_USE_FALLOCATE,
180+
// MDBX_DEBUG, and other compile-time flags.
181+
//
182+
// Example output: " MDBX_DEBUG=0 ... MDBX_USE_FALLOCATE=1 ..."
183+
func BuildOptions() string {
184+
//nolint:gocritic // C variable access pattern
185+
return C.GoString(C.mdbx_build.options)
186+
}
187+
178188
func GetSysRamInfo() (pageSize, totalPages, availablePages int, err error) {
179189
var cPageSize, cTotalPages, cAvailablePages C.intptr_t
180190

mdbx/txn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ func (txn *Txn) renew() error {
442442
// null bytes in the name argument.
443443
//
444444
// See mdbx_dbi_open.
445+
//
445446
// Deprecated: use OpenDBISimple instead
446447
func (txn *Txn) OpenDBI(name string, flags uint, cmp, dcmp CmpFunc) (DBI, error) {
447448
cname := C.CString(name)
@@ -495,7 +496,8 @@ type Cmp func(k1, k2 []byte) int
495496
// returned in those cases. This is not a big deal for now because
496497
// applications are expected to handle any error encountered opening a
497498
// database.
498-
// Deprecated: openDBISimple instead because using comparators now is a deprecated
499+
//
500+
// Deprecated: use OpenDBISimple instead because using comparators is now deprecated
499501
func (txn *Txn) openDBI(cname *C.char, flags uint, cmp, dcmp *C.MDBX_cmp_func) (DBI, error) {
500502
var dbi C.MDBX_dbi
501503
ret := C.mdbx_dbi_open_ex(txn._txn, cname, C.MDBX_db_flags_t(flags), &dbi, cmp, dcmp)

0 commit comments

Comments
 (0)