Skip to content

Commit

Permalink
Problem: memiavl rootmulti store access map concurrently (crypto-org-…
Browse files Browse the repository at this point in the history
…chain#1302)

* Problem: memiavl rootmulti store access map concurrently

Solution:
- code refactoring

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored and mmsqe committed Jan 30, 2024
1 parent b0af3db commit ba1fb2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- [#1241](https://github.com/crypto-org-chain/cronos/pull/1241) Improve parallelization of memiavl restoration.
- [#1302](https://github.com/crypto-org-chain/cronos/pull/1302) Fix concurrent map access in rootmulti store.

### State Machine Breaking

Expand Down
4 changes: 4 additions & 0 deletions store/memiavlstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func New(tree *memiavl.Tree, logger log.Logger) *Store {
return &Store{tree: tree, logger: logger}
}

func (st *Store) SetTree(tree *memiavl.Tree) {
st.tree = tree
}

func (st *Store) Commit() types.CommitID {
panic("memiavl store is not supposed to be committed alone")
}
Expand Down
7 changes: 2 additions & 5 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ func (rs *Store) Commit() types.CommitID {
panic(err)
}

// the underlying memiavl tree might be reloaded, reload the store as well.
// the underlying memiavl tree might be reloaded, update the tree.
for key := range rs.stores {
store := rs.stores[key]
if store.GetStoreType() == types.StoreTypeIAVL {
rs.stores[key], err = rs.loadCommitStoreFromParams(rs.db, key, rs.storesParams[key])
if err != nil {
panic(fmt.Errorf("inconsistent store map, store %s not found", key.Name()))
}
store.(*memiavlstore.Store).SetTree(rs.db.TreeByName(key.Name()))
}
}

Expand Down

0 comments on commit ba1fb2d

Please sign in to comment.