Skip to content

Commit

Permalink
Merge branch 'master' into e35_mdbx_v0_13
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed May 23, 2024
2 parents 02a0bc4 + 02cb1c2 commit 114ad31
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ _cgo_export.*
_testmain.go

*.exe
*.out

go.work*
1 change: 1 addition & 0 deletions dbg/keep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package dbg
8 changes: 8 additions & 0 deletions dbg/pprof_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build debug
// +build debug

package dbg

import (
_ "github.com/benesch/cgosymbolizer"
)
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module github.com/erigontech/mdbx-go

go 1.15

require (
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b h1:5JgaFtHFRnOPReItxvhMDXbvuBkjSWE+9glJyF466yw=
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b/go.mod h1:eMD2XUcPsHYbakFEocKrWZp47G0MRJYoC60qFblGjpA=
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d h1:Azx2B59D4+zpVVtuYb8Oe3uOLi/ift4xfwKdhBX0Cy0=
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d/go.mod h1:DvXTE/K/RtHehxU8/GtDs4vFtfw64jJ3PaCnFri8CRg=
47 changes: 45 additions & 2 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mdbx

import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"os"
Expand Down Expand Up @@ -1263,8 +1264,9 @@ func TestCursor_Del_DupSort(t *testing.T) {
if err != nil {
panic(err)
}
fmt.Printf("kk: %s\n", kk)
fmt.Printf("vv: %s\n", vv)
_, _ = kk, vv //TODO: add assert
//fmt.Printf("kk: %s\n", kk)
//fmt.Printf("vv: %s\n", vv)

return nil
})
Expand Down Expand Up @@ -1563,3 +1565,44 @@ func BenchmarkCursor_Renew(b *testing.B) {
return nil
})
}

func BenchmarkCursor_SetRange(b *testing.B) {
env, _ := setup(b)

var db DBI
k := make([]byte, 8)
binary.BigEndian.PutUint64(k, uint64(1))

if err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenRoot(0)
if err != nil {
return err
}
err = txn.Put(db, k, k, 0)
if err != nil {
return err
}
return nil
}); err != nil {
b.Errorf("dbi: %v", err)
return
}

if err := env.View(func(txn *Txn) (err error) {
c, err := txn.OpenCursor(db)
if err != nil {
return err
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := c.Get(k, nil, SetRange)
if err != nil {
return err
}
}
return nil
}); err != nil {
b.Errorf("put: %v", err)
}
}
2 changes: 2 additions & 0 deletions mdbx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"sync"
"time"
"unsafe"

_ "github.com/erigontech/mdbx-go/dbg"
)

// success is a value returned from the MDBX API to indicate a successful call.
Expand Down
36 changes: 36 additions & 0 deletions mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,42 @@ func openDBI(env *Env, key string, flags uint) (DBI, error) {
return db, nil
}

func BenchmarkTxn_Get(b *testing.B) {
env, _ := setup(b)

var db DBI
k := make([]byte, 8)
binary.BigEndian.PutUint64(k, uint64(1))

if err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenRoot(0)
if err != nil {
return err
}
err = txn.Put(db, k, k, 0)
if err != nil {
return err
}
return nil
}); err != nil {
b.Errorf("dbi: %v", err)
return
}

if err := env.View(func(txn *Txn) (err error) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := txn.Get(db, k)
if err != nil {
return err
}
}
return nil
}); err != nil {
b.Errorf("put: %v", err)
}
}

func TestTxnEnvWarmup(t *testing.T) {
env, _ := setup(t)

Expand Down

0 comments on commit 114ad31

Please sign in to comment.