From e144f08ceb438c4edb2e60ba7fef43a82fffc82d Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 6 Dec 2022 20:20:02 +0800 Subject: [PATCH] fix: commit the ndb in LoadVersionForOverwriting (#640) --- CHANGELOG.md | 1 + mutable_tree.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e2fac254..dad0076bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ## Unreleased - [#586](https://github.com/cosmos/iavl/pull/586) Remove the `RangeProof` and refactor the ics23_proof to use the internal methods. +- [#640](https://github.com/cosmos/iavl/pull/640) commit `NodeDB` batch in `LoadVersionForOverwriting`. ## 0.19.4 (October 28, 2022) diff --git a/mutable_tree.go b/mutable_tree.go index 5793b63c0..4924264cd 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -625,6 +625,13 @@ func (tree *MutableTree) LoadVersionForOverwriting(targetVersion int64) (int64, return latestVersion, err } + // Commit the tree rollback first + // The fast storage rebuild don't have to be atomic with this, + // because it's idempotent and will do again when `LoadVersion`. + if err := tree.ndb.Commit(); err != nil { + return latestVersion, err + } + if !tree.skipFastStorageUpgrade { if err := tree.enableFastStorageAndCommitLocked(); err != nil { return latestVersion, err