Skip to content

Commit

Permalink
Problem: memiavl snapshot rewrite could rollback state
Browse files Browse the repository at this point in the history
Solution:
- wait for async commit to finish to make sure catching up to latest state.
  • Loading branch information
yihuang committed Aug 4, 2023
1 parent 496ce7e commit b986da1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [#1087](https://github.com/crypto-org-chain/cronos/pull/1087) memiavl fix LastCommitID when memiavl db not loaded.
- [#1088](https://github.com/crypto-org-chain/cronos/pull/1088) memiavl fix empty value in write-ahead-log replaying.
- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook.
- [#]() Fix memiavl snapshot switching

### Features

Expand Down
5 changes: 5 additions & 0 deletions memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func (db *DB) checkBackgroundSnapshotRewrite() error {
return fmt.Errorf("background snapshot rewriting failed: %w", result.err)
}

// wait for pending wal writings to finish, to make sure catching up to latest state
if err := db.WaitAsyncCommit(); err != nil {
return fmt.Errorf("wait async commit failed: %w", err)
}

// catchup the remaining wal
if err := result.mtree.CatchupWAL(db.wal, 0); err != nil {
return fmt.Errorf("catchup failed: %w", err)
Expand Down

0 comments on commit b986da1

Please sign in to comment.