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

Problem: memiavl restore fail to reopen the db #1130

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook.
- [#1123](https://github.com/crypto-org-chain/cronos/pull/1123) Fix memiavl snapshot switching
- [#1125](https://github.com/crypto-org-chain/cronos/pull/1125) Fix genesis migrate for feeibc, evm, feemarket and gravity.
- [#1130](https://github.com/crypto-org-chain/cronos/pull/1130) Fix lock issues when state-sync with memiavl.

### Features

Expand Down
7 changes: 6 additions & 1 deletion integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ def test_statesync(cronos):
"json-rpc": {
"address": "127.0.0.1:{EVMRPC_PORT}",
"ws-address": "127.0.0.1:{EVMRPC_PORT_WS}",
}
},
"memiavl": {
"enable": True,
"zero-copy": True,
"snapshot-interval": 5,
},
},
)
clustercli.supervisor.startProcess(f"{clustercli.chain_id}-node{i}")
Expand Down
6 changes: 6 additions & 0 deletions memiavl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
snapshotDir := snapshotName(int64(height))
tmpDir := snapshotDir + "-tmp"

fileLock, err := LockFile(filepath.Join(dir, LockFileName))
if err != nil {
return snapshottypes.SnapshotItem{}, fmt.Errorf("fail to lock db: %w", err)
}

Check warning on line 33 in memiavl/import.go

View check run for this annotation

Codecov / codecov/patch

memiavl/import.go#L32-L33

Added lines #L32 - L33 were not covered by tests
defer fileLock.Unlock()
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

// Import nodes into stores. The first item is expected to be a SnapshotItem containing
// a SnapshotStoreItem, telling us which store to import into. The following items will contain
// SnapshotNodeItem (i.e. ExportNode) until we reach the next SnapshotStoreItem or EOF.
Expand Down
7 changes: 7 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func (rs *Store) Snapshot(height uint64, protoWriter protoio.Writer) error {

// Implements interface Snapshotter
func (rs *Store) Restore(height uint64, format uint32, protoReader protoio.Reader) (snapshottypes.SnapshotItem, error) {
if rs.db != nil {
if err := rs.db.Close(); err != nil {
return snapshottypes.SnapshotItem{}, fmt.Errorf("failed to close db: %w", err)
}
rs.db = nil
}

item, err := memiavl.Import(rs.dir, height, format, protoReader)
if err != nil {
return item, err
Expand Down
Loading