Skip to content

Commit

Permalink
Env info on existing tx (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 4, 2021
1 parent 00f85ac commit 339745a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions exp/mdbxpool/txnpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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.
UpdateHandling UpdateHandling

lastid uintptr
idleGuard uintptr
env *mdbx.Env
pool sync.Pool
}

// NewTxnPool initializes returns a new TxnPool.
Expand Down
19 changes: 11 additions & 8 deletions mdbx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion mdbx/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions mdbx/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit 339745a

Please sign in to comment.