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

Merkledb split node storage into value and intermediate #1918

Merged
merged 102 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
5d890e2
Split DB into two
dboehm-avalabs Aug 24, 2023
7c510e7
remove locks
dboehm-avalabs Aug 24, 2023
aa2925d
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 24, 2023
86d5b82
merge conflicts
dboehm-avalabs Aug 24, 2023
1db0bbd
linting
dboehm-avalabs Aug 24, 2023
8b923a5
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 24, 2023
bf0a6ac
Update mock_db.go
dboehm-avalabs Aug 24, 2023
7611fec
remove
dboehm-avalabs Aug 24, 2023
c466474
Update x/merkledb/cache_test.go
dboehm-avalabs Aug 24, 2023
226ec45
comments
dboehm-avalabs Aug 24, 2023
7b0c8b8
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 24, 2023
1b92790
Update x/merkledb/db.go
dboehm-avalabs Aug 24, 2023
5a5dcfe
Update x/merkledb/value_node_db.go
dboehm-avalabs Aug 24, 2023
a210644
Update x/merkledb/value_node_db.go
dboehm-avalabs Aug 24, 2023
133040a
comments
dboehm-avalabs Aug 24, 2023
58dcf67
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 24, 2023
3aa5f60
Update db.go
dboehm-avalabs Aug 24, 2023
3cd283f
comments
dboehm-avalabs Aug 24, 2023
e5286b0
Update trie_test.go
dboehm-avalabs Aug 24, 2023
e872e8e
Update cache_test.go
dboehm-avalabs Aug 24, 2023
f4af6ae
Update intermediate_node_db.go
dboehm-avalabs Aug 24, 2023
87b9b93
Update x/merkledb/codec.go
dboehm-avalabs Aug 25, 2023
669bf24
Update x/merkledb/intermediate_node_db.go
dboehm-avalabs Aug 25, 2023
0932ce1
Update x/merkledb/trieview.go
dboehm-avalabs Aug 25, 2023
2f8ef8e
Update x/merkledb/intermediate_node_db.go
dboehm-avalabs Aug 25, 2023
c58436d
Update codec.go
dboehm-avalabs Aug 25, 2023
0450655
merge
dboehm-avalabs Aug 25, 2023
facc808
Update x/merkledb/trieview.go
dboehm-avalabs Aug 25, 2023
4780a13
Update x/merkledb/value_node_db.go
dboehm-avalabs Aug 25, 2023
a319d78
Update x/merkledb/value_node_db.go
dboehm-avalabs Aug 25, 2023
060e081
Update value_node_db.go
dboehm-avalabs Aug 25, 2023
2c463de
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 25, 2023
d35121a
Update x/merkledb/metrics.go
dboehm-avalabs Aug 25, 2023
6ed15e3
Update x/merkledb/metrics.go
dboehm-avalabs Aug 25, 2023
4786c85
Update x/merkledb/intermediate_node_db.go
dboehm-avalabs Aug 25, 2023
e9c9e72
Update x/merkledb/metrics.go
dboehm-avalabs Aug 25, 2023
417196a
Update x/merkledb/metrics.go
dboehm-avalabs Aug 25, 2023
65d36a6
Update x/merkledb/proof.go
dboehm-avalabs Aug 25, 2023
8b3d863
Update x/merkledb/trieview.go
dboehm-avalabs Aug 25, 2023
be95220
Update x/merkledb/metrics.go
dboehm-avalabs Aug 25, 2023
7a2f9b9
changes
dboehm-avalabs Aug 25, 2023
7708ee3
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 25, 2023
02726a7
cleanup
dboehm-avalabs Aug 25, 2023
aaaaaee
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 25, 2023
01a27bd
shift bufferpool
dboehm-avalabs Aug 25, 2023
ced5f69
lint
dboehm-avalabs Aug 25, 2023
6d24b84
Update db.go
dboehm-avalabs Aug 25, 2023
264e3f8
Update db.go
dboehm-avalabs Aug 25, 2023
c94e5f9
use count variable
danlaine Aug 25, 2023
3d7492e
Merge branch 'dev' into MerkleDBSplitNodeStorage
danlaine Aug 25, 2023
98bbc61
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 27, 2023
9b45f93
comments
dboehm-avalabs Aug 27, 2023
e76b05f
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 27, 2023
d897be9
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 28, 2023
62b9607
Update x/merkledb/intermediate_node_db.go
dboehm-avalabs Aug 28, 2023
4734034
comments
dboehm-avalabs Aug 28, 2023
8d511d7
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
ed84b8c
Update intermediate_node_db.go
dboehm-avalabs Aug 28, 2023
d8a8f69
Merge remote-tracking branch 'upstream/dev' into MerkleDBSplitNodeSto…
danlaine Aug 28, 2023
86dcbfc
Update trie.go
dboehm-avalabs Aug 28, 2023
91ff38c
remove unused const
danlaine Aug 28, 2023
e679bff
remove bufferPool reference from merkleDB
danlaine Aug 28, 2023
2731f24
comments
danlaine Aug 28, 2023
aa1cc10
comments; remove unnecessary use of intermediate node iterator
danlaine Aug 28, 2023
130580c
cleanup value node cache
dboehm-avalabs Aug 28, 2023
1ba8b70
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
2708129
comments
danlaine Aug 28, 2023
2d1b403
Merge branch 'MerkleDBSplitNodeStorage' of github.com:ava-labs/avalan…
danlaine Aug 28, 2023
5946fef
Update value_node_db.go
dboehm-avalabs Aug 28, 2023
5096c6c
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
f111648
appease linter
danlaine Aug 28, 2023
49fd287
Merge branch 'MerkleDBSplitNodeStorage' of github.com:ava-labs/avalan…
danlaine Aug 28, 2023
e19a771
nit use switch instead of ifs
danlaine Aug 28, 2023
a7d7d7d
comment
danlaine Aug 28, 2023
d0b307d
move prefix declarations
danlaine Aug 28, 2023
82f2966
close base DB on onEviction error
danlaine Aug 28, 2023
8e02791
rename metrics methods
danlaine Aug 28, 2023
7592cfe
nits
danlaine Aug 28, 2023
fdfb345
Merge branch 'dev' into MerkleDBSplitNodeStorage
dboehm-avalabs Aug 28, 2023
78bda1f
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
f1670ab
fix metric call; comments; nits
danlaine Aug 28, 2023
66849ab
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
055c5e6
move comment
danlaine Aug 28, 2023
a841a6d
Merge branch 'MerkleDBSplitNodeStorage' of github.com:ava-labs/avalan…
danlaine Aug 28, 2023
bcb640f
Update db.go
dboehm-avalabs Aug 28, 2023
0787331
Merge branch 'MerkleDBSplitNodeStorage' of https://github.com/ava-lab…
dboehm-avalabs Aug 28, 2023
7e0b153
Update db.go
dboehm-avalabs Aug 28, 2023
d729fab
comments
danlaine Aug 28, 2023
ee66af1
nit move declaration
danlaine Aug 28, 2023
07fb642
add intermediate node db tests
danlaine Aug 28, 2023
41138ee
Update db.go
dboehm-avalabs Aug 28, 2023
b42aaea
appease linter
danlaine Aug 29, 2023
e2a2996
Merge remote-tracking branch 'upstream/dev' into MerkleDBSplitNodeSto…
danlaine Aug 29, 2023
15e3192
move import
danlaine Aug 29, 2023
c5c58f7
remove old comments
danlaine Aug 29, 2023
3b8a9d4
comments
danlaine Aug 29, 2023
c9e3ec1
nit
danlaine Aug 29, 2023
a2a2619
nits
danlaine Aug 29, 2023
422ec49
add value node db tests
danlaine Aug 29, 2023
8e41981
appease linter
danlaine Aug 29, 2023
8e95dd3
Merge branch 'dev' into MerkleDBSplitNodeStorage
danlaine Aug 29, 2023
affe3ed
Merge branch 'dev' into MerkleDBSplitNodeStorage
danlaine Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions x/merkledb/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type onEvictCache[K comparable, V any] struct {
lock sync.RWMutex
maxSize int
fifo linkedhashmap.LinkedHashmap[K, V]
onEviction func(V) error
onEviction func(K, V) error
}

func newOnEvictCache[K comparable, V any](maxSize int, onEviction func(V) error) onEvictCache[K, V] {
func newOnEvictCache[K comparable, V any](maxSize int, onEviction func(K, V) error) onEvictCache[K, V] {
return onEvictCache[K, V]{
maxSize: maxSize,
fifo: linkedhashmap.New[K, V](),
Expand Down Expand Up @@ -55,7 +55,7 @@ func (c *onEvictCache[K, V]) Put(key K, value V) error {
if c.fifo.Len() > c.maxSize {
oldestKey, oldestVal, _ := c.fifo.Oldest()
c.fifo.Delete(oldestKey)
return c.onEviction(oldestVal)
return c.onEviction(oldestKey, oldestVal)
}
return nil
}
Expand All @@ -75,12 +75,12 @@ func (c *onEvictCache[K, V]) Flush() error {
// modifies [c.fifo], which violates the iterator's invariant.
var errs wrappers.Errs
for {
_, node, exists := c.removeOldest()
key, value, exists := c.removeOldest()
if !exists {
// The cache is empty.
return errs.Err
}

errs.Add(c.onEviction(node))
errs.Add(c.onEviction(key, value))
}
}
8 changes: 4 additions & 4 deletions x/merkledb/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestNewOnEvictCache(t *testing.T) {
require := require.New(t)

called := false
onEviction := func(int) error {
onEviction := func(int, int) error {
called = true
return nil
}
Expand All @@ -28,7 +28,7 @@ func TestNewOnEvictCache(t *testing.T) {
require.Zero(cache.fifo.Len())
// Can't test function equality directly so do this
// to make sure it was assigned correctly
require.NoError(cache.onEviction(0))
require.NoError(cache.onEviction(0, 0))
require.True(called)
}

Expand All @@ -39,7 +39,7 @@ func TestOnEvictCacheNoOnEvictionError(t *testing.T) {
require := require.New(t)

evicted := []int{}
onEviction := func(n int) error {
onEviction := func(key int, n int) error {
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
evicted = append(evicted, n)
return nil
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestOnEvictCacheOnEvictionError(t *testing.T) {
var (
require = require.New(t)
evicted = []int{}
onEviction = func(n int) error {
onEviction = func(key, n int) error {
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
// Evicting even keys errors
evicted = append(evicted, n)
if n%2 == 0 {
Expand Down
6 changes: 6 additions & 0 deletions x/merkledb/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (c *codecImpl) encodeDBNode(n *dbNode) []byte {
path := entry.compressedPath.Serialize()
c.encodeSerializedPath(buf, path)
_, _ = buf.Write(entry.id[:])
c.encodeBool(buf, entry.hasValue)
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
}
}
return buf.Bytes()
Expand Down Expand Up @@ -179,9 +180,14 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode) error {
if err != nil {
return err
}
hasValue, err := c.decodeBool(src)
if err != nil {
return err
}
n.children[byte(index)] = child{
compressedPath: compressedPath.deserialize(),
id: childID,
hasValue: hasValue,
}
}
if src.Len() != 0 {
Expand Down