Skip to content

Commit 339745a

Browse files
Env info on existing tx (#29)
1 parent 00f85ac commit 339745a

5 files changed

Lines changed: 17 additions & 14 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lint:
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.41.0
25+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./build/bin v1.41.1
2626

2727
check:
2828
which goimports > /dev/null

exp/mdbxpool/txnpool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ const (
5050
// updates and prevent long-lived updates from causing excessive disk
5151
// utilization.
5252
type TxnPool struct {
53+
env *mdbx.Env
54+
pool sync.Pool
5355
// UpdateHandling determines how a TxnPool behaves after updates have been
5456
// committed. It is not safe to modify UpdateHandling if TxnPool is being
5557
// used concurrently.
5658
UpdateHandling UpdateHandling
5759

5860
lastid uintptr
5961
idleGuard uintptr
60-
env *mdbx.Env
61-
pool sync.Pool
6262
}
6363

6464
// NewTxnPool initializes returns a new TxnPool.

mdbx/env.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,18 @@ type EnvInfo struct {
349349
// Info returns information about the environment.
350350
//
351351
// See mdbx_env_info.
352-
func (env *Env) Info() (*EnvInfo, error) {
353-
var _info C.MDBX_envinfo
354-
var ret C.int
355-
if err := env.View(func(txn *Txn) error {
356-
ret = C.mdbx_env_info_ex(env._env, txn._txn, &_info, C.size_t(unsafe.Sizeof(_info)))
357-
return nil
358-
}); err != nil {
359-
return nil, err
352+
// txn - can be nil
353+
func (env *Env) Info(txn *Txn) (*EnvInfo, error) {
354+
if txn == nil {
355+
var err error
356+
txn, err = env.BeginTxn(nil, Readonly)
357+
if err != nil {
358+
return nil, err
359+
}
360+
defer txn.Abort()
360361
}
362+
var _info C.MDBX_envinfo
363+
ret := C.mdbx_env_info_ex(env._env, txn._txn, &_info, C.size_t(unsafe.Sizeof(_info)))
361364
if ret != success {
362365
return nil, operrno("mdbx_env_info", ret)
363366
}

mdbx/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
// lmdb-go have type OpError but typically they do. The Errno field will
1717
// either have type Errno or syscall.Errno.
1818
type OpError struct {
19-
Op string
2019
Errno error
20+
Op string
2121
}
2222

2323
// Error implements the error interface.

mdbx/error_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestErrno_Error(t *testing.T) {
10-
operr := &OpError{"testop", fmt.Errorf("testmsg")}
10+
operr := &OpError{fmt.Errorf("testmsg"), "testop"}
1111
msg := operr.Error()
1212
if msg != "testop: testmsg" {
1313
t.Errorf("message: %q", msg)
@@ -21,7 +21,7 @@ func BenchmarkErrno_Error(b *testing.B) {
2121
NotFound,
2222
MapFull,
2323
} {
24-
operr := &OpError{"mdb_testop", errno}
24+
operr := &OpError{errno, "mdb_testop"}
2525
msg := operr.Error()
2626
if msg == "" {
2727
b.Fatal("empty message")

0 commit comments

Comments
 (0)