Skip to content

Commit

Permalink
relax the restriction of delete latest version
Browse files Browse the repository at this point in the history
Closes: #482

Update nodedb.go

changelog
  • Loading branch information
yihuang committed Mar 11, 2022
1 parent ccfb418 commit de3e0a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Improvements

- [#483](https://github.com/cosmos/iavl/pull/483) Allow delete latest version.

## 0.18.0 (March 10, 2022)

### Breaking Changes
Expand Down
5 changes: 1 addition & 4 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,10 @@ func (tree *MutableTree) deleteVersion(version int64) error {
if version <= 0 {
return errors.New("version must be greater than 0")
}
if version == tree.version {
return errors.Errorf("cannot delete latest saved version (%d)", version)
}
if !tree.VersionExists(version) {
return errors.Wrap(ErrVersionDoesNotExist, "")
}
if err := tree.ndb.DeleteVersion(version, true); err != nil {
if err := tree.ndb.DeleteVersion(version, false); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ func (ndb *nodeDB) DeleteVersionsRange(fromVersion, toVersion int64) error {
defer ndb.mtx.Unlock()

latest := ndb.getLatestVersion()
if latest < toVersion {
return errors.Errorf("cannot delete latest saved version (%d)", latest)
if latest+1 < toVersion {
return errors.Errorf("cannot delete future versions [%d..%d)", latest+1, toVersion)
}

predecessor := ndb.getPreviousVersion(fromVersion)
Expand Down

0 comments on commit de3e0a4

Please sign in to comment.