Skip to content

Commit

Permalink
Fast Cache Migration (#9)
Browse files Browse the repository at this point in the history
* implement nodedb changes to set and get chain version from the database

* implement and unit test upgrade to fast storage in mutable tree

* refactor for auto upgrade to fast version in mutable tree contructor, load version and lazy load version

* use proper functionality for getting latest version

* remove unused error

* fix comment

* use fast version value in tests

* spurious tab

* fix style problems and remove redundant code in tests
  • Loading branch information
p0mvn committed Feb 13, 2022
1 parent dfd175e commit c6d015d
Show file tree
Hide file tree
Showing 11 changed files with 805 additions and 39 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/confio/ics23/go v0.6.6
github.com/gogo/gateway v1.1.0
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
17 changes: 13 additions & 4 deletions immutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ func (t *ImmutableTree) Version() int64 {
return t.version
}

// IsLatestVersion returns true if curren tree is of the latest version, false otherwise.
func (t *ImmutableTree) IsLatestVersion() bool {
// IsLatestTreeVersion returns true if curren tree is of the latest version, false otherwise.
func (t *ImmutableTree) IsLatestTreeVersion() bool {
return t.version == t.ndb.getLatestVersion()
}

Expand Down Expand Up @@ -236,8 +236,7 @@ func (t *ImmutableTree) Iterate(fn func(key []byte, value []byte) bool) bool {

// Iterator returns an iterator over the immutable tree.
func (t *ImmutableTree) Iterator(start, end []byte, ascending bool) dbm.Iterator {
isFastTraversal := t.IsLatestVersion()
if isFastTraversal {
if t.IsFastCacheEnabled() {
return NewFastIterator(start, end, ascending, t.ndb)
} else {
return NewIterator(start, end, ascending, t)
Expand All @@ -259,6 +258,16 @@ func (t *ImmutableTree) IterateRange(start, end []byte, ascending bool, fn func(
})
}

// GetStorageVersion returns the version of the underlying storage.
func (t *ImmutableTree) GetStorageVersion() (string) {
return t.ndb.getStorageVersion()
}

// IsFastCacheEnabled returns true if fast storage is enabled, false otherwise.
func (t *ImmutableTree) IsFastCacheEnabled() bool {
return t.IsLatestTreeVersion() && t.ndb.isFastStorageEnabled()
}

// IterateRangeInclusive makes a callback for all nodes with key between start and end inclusive.
// If either are nil, then it is open on that side (nil, nil is the same as Iterate). The keys and
// values must not be modified, since they may point to data stored within IAVL.
Expand Down
Loading

0 comments on commit c6d015d

Please sign in to comment.