diff --git a/Makefile b/Makefile index 07fea2c..37c2dcb 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ lint: lintci-deps: rm -f ./build/bin/golangci-lint - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./build/bin v1.41.0 + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./build/bin v1.41.1 check: which goimports > /dev/null diff --git a/exp/mdbxpool/txnpool.go b/exp/mdbxpool/txnpool.go index 41c3626..5d97c19 100644 --- a/exp/mdbxpool/txnpool.go +++ b/exp/mdbxpool/txnpool.go @@ -50,6 +50,8 @@ const ( // updates and prevent long-lived updates from causing excessive disk // utilization. type TxnPool struct { + env *mdbx.Env + pool sync.Pool // UpdateHandling determines how a TxnPool behaves after updates have been // committed. It is not safe to modify UpdateHandling if TxnPool is being // used concurrently. @@ -57,8 +59,6 @@ type TxnPool struct { lastid uintptr idleGuard uintptr - env *mdbx.Env - pool sync.Pool } // NewTxnPool initializes returns a new TxnPool. diff --git a/mdbx/env.go b/mdbx/env.go index d663e5f..27d8d23 100644 --- a/mdbx/env.go +++ b/mdbx/env.go @@ -349,15 +349,18 @@ type EnvInfo struct { // Info returns information about the environment. // // See mdbx_env_info. -func (env *Env) Info() (*EnvInfo, error) { - var _info C.MDBX_envinfo - var ret C.int - if err := env.View(func(txn *Txn) error { - ret = C.mdbx_env_info_ex(env._env, txn._txn, &_info, C.size_t(unsafe.Sizeof(_info))) - return nil - }); err != nil { - return nil, err +// txn - can be nil +func (env *Env) Info(txn *Txn) (*EnvInfo, error) { + if txn == nil { + var err error + txn, err = env.BeginTxn(nil, Readonly) + if err != nil { + return nil, err + } + defer txn.Abort() } + var _info C.MDBX_envinfo + ret := C.mdbx_env_info_ex(env._env, txn._txn, &_info, C.size_t(unsafe.Sizeof(_info))) if ret != success { return nil, operrno("mdbx_env_info", ret) } diff --git a/mdbx/error.go b/mdbx/error.go index 6c70ec4..f9c842c 100644 --- a/mdbx/error.go +++ b/mdbx/error.go @@ -16,8 +16,8 @@ import ( // lmdb-go have type OpError but typically they do. The Errno field will // either have type Errno or syscall.Errno. type OpError struct { - Op string Errno error + Op string } // Error implements the error interface. diff --git a/mdbx/error_test.go b/mdbx/error_test.go index 3b7c941..3372a5f 100644 --- a/mdbx/error_test.go +++ b/mdbx/error_test.go @@ -7,7 +7,7 @@ import ( ) func TestErrno_Error(t *testing.T) { - operr := &OpError{"testop", fmt.Errorf("testmsg")} + operr := &OpError{fmt.Errorf("testmsg"), "testop"} msg := operr.Error() if msg != "testop: testmsg" { t.Errorf("message: %q", msg) @@ -21,7 +21,7 @@ func BenchmarkErrno_Error(b *testing.B) { NotFound, MapFull, } { - operr := &OpError{"mdb_testop", errno} + operr := &OpError{errno, "mdb_testop"} msg := operr.Error() if msg == "" { b.Fatal("empty message")