Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: IAVL v2 pruning implementation #882

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions v2/cache.go

This file was deleted.

8 changes: 7 additions & 1 deletion v2/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ func RootCommand() (*cobra.Command, error) {
Use: "iavl",
Short: "benchmark cosmos/iavl",
}
cmd.AddCommand(gen.Command(), snapshot.Command(), rollback.Command(), scan.Command(), latestCommand())
cmd.AddCommand(
gen.Command(),
snapshot.Command(),
rollback.Command(),
scan.Command(),
latestCommand(),
)
return cmd, nil
}
31 changes: 30 additions & 1 deletion v2/cmd/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"os"

"github.com/bvinc/go-sqlite-lite/sqlite3"
"github.com/cosmos/iavl/v2"
"github.com/spf13/cobra"
)

func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "scan",
}
cmd.AddCommand(probeCommand())
cmd.AddCommand(probeCommand(), rootsCommand())
return cmd
}

Expand Down Expand Up @@ -72,3 +73,31 @@ func probeCommand() *cobra.Command {
}
return cmd
}

func rootsCommand() *cobra.Command {
var (
dbPath string
version int64
)
cmd := &cobra.Command{
Use: "roots",
Short: "list roots",
RunE: func(cmd *cobra.Command, args []string) error {
sql, err := iavl.NewSqliteDb(iavl.NewNodePool(), iavl.SqliteDbOptions{Path: dbPath})
if err != nil {
return err
}
node, err := sql.LoadRoot(version)
if err != nil {
return err
}
fmt.Printf("root: %+v\n", node)
return sql.Close()
},
}
cmd.Flags().StringVar(&dbPath, "db", "", "path to sqlite db")
cmd.Flags().Int64Var(&version, "version", 0, "version to query")
cmd.MarkFlagRequired("db")
cmd.MarkFlagRequired("version")
return cmd
}
2 changes: 1 addition & 1 deletion v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e
github.com/bvinc/go-sqlite-lite v0.6.1
github.com/cosmos/iavl-bench/bench v0.0.3
github.com/cosmos/iavl-bench/bench v0.0.4
github.com/dustin/go-humanize v1.0.1
github.com/emicklei/dot v1.6.0
github.com/kocubinski/costor-api v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/bvinc/go-sqlite-lite v0.6.1/go.mod h1:2GiE60NUdb0aNhDdY+LXgrqAVDpi2Ij
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cosmos/iavl-bench/bench v0.0.3 h1:PL9PP4+1y+iMblB0EYv+G91posLO4VGJiQ1Wg47ABXM=
github.com/cosmos/iavl-bench/bench v0.0.3/go.mod h1:j2rLae77EffacWcp7mmj3Uaa4AOAmZA7ymvhsuBQKKI=
github.com/cosmos/iavl-bench/bench v0.0.4 h1:J6zQPiBqF4CXMM3QBsLqZgQEBGY0taX85vLIZMhmAfQ=
github.com/cosmos/iavl-bench/bench v0.0.4/go.mod h1:j2rLae77EffacWcp7mmj3Uaa4AOAmZA7ymvhsuBQKKI=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 2 additions & 0 deletions v2/multitree.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ func (mt *MultiTree) SaveVersionConcurrently() ([]byte, int64, error) {
for _, tree := range mt.Trees {
treeCount++
go func(t *Tree) {
//t.sql.logger.Debug().Msgf("saving version %d", t.Version()+1)
h, v, err := t.SaveVersion()
if err != nil {
mt.errorCh <- err
}
//t.sql.logger.Debug().Msgf("saved version %d", v)
mt.doneCh <- saveVersionResult{version: v, hash: h}
}(tree)
}
Expand Down
22 changes: 8 additions & 14 deletions v2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,10 @@ func (node *Node) getLeftNode(t *Tree) (*Node, error) {
if node.leftNode != nil {
return node.leftNode, nil
}
node.leftNode = t.cache.Get(node.leftNodeKey)
if node.leftNode == nil {
var err error
node.leftNode, err = t.sql.getLeftNode(node)
if err != nil {
return nil, err
}
var err error
node.leftNode, err = t.sql.getLeftNode(node)
if err != nil {
return nil, err
}
return node.leftNode, nil
}
Expand All @@ -124,13 +121,10 @@ func (node *Node) getRightNode(t *Tree) (*Node, error) {
if node.rightNode != nil {
return node.rightNode, nil
}
node.rightNode = t.cache.Get(node.rightNodeKey)
if node.rightNode == nil {
var err error
node.rightNode, err = t.sql.getRightNode(node)
if err != nil {
return nil, err
}
var err error
node.rightNode, err = t.sql.getRightNode(node)
if err != nil {
return nil, err
}
return node.rightNode, nil
}
Expand Down
11 changes: 0 additions & 11 deletions v2/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type NodePool struct {
poolId uint64
}

const initialNodePoolSize = 1_000

func NewNodePool() *NodePool {
np := &NodePool{
syncPool: &sync.Pool{
Expand All @@ -41,15 +39,6 @@ func NewNodePool() *NodePool {
return np
}

func (np *NodePool) grow(amount int) {
startSize := len(np.nodes)
log.Warn().Msgf("growing node pool amount=%d; size=%d", amount, startSize+amount)
for i := startSize; i < startSize+amount; i++ {
np.free <- i
np.poolSize += nodeSize
}
}

func (np *NodePool) Get() *Node {
if np.poolId == math.MaxUint64 {
np.poolId = 1
Expand Down
20 changes: 20 additions & 0 deletions v2/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

type VersionRange struct {
versions []int64
cache map[int64]int64
}

func (r *VersionRange) Add(version int64) error {
Expand Down Expand Up @@ -47,3 +48,22 @@ func (r *VersionRange) Find(version int64) int64 {
}
return vs[low]
}

func (r *VersionRange) FindMemoized(version int64) int64 {
if r.cache == nil {
r.cache = make(map[int64]int64)
}
if v, ok := r.cache[version]; ok {
return v
}
v := r.Find(version)
r.cache[version] = v
return v
}

func (r *VersionRange) Last() int64 {
if len(r.versions) == 0 {
return -1
}
return r.versions[len(r.versions)-1]
}
Loading
Loading