From 35e0e8ec0f1c812079d63e84523df09118a1ea7f Mon Sep 17 00:00:00 2001 From: yzang2019 Date: Wed, 11 Sep 2024 16:20:00 -0700 Subject: [PATCH] Fix --- mutable_tree.go | 9 +-------- nodedb.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mutable_tree.go b/mutable_tree.go index 37f9bdc..4b011f3 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -556,8 +556,6 @@ func (tree *MutableTree) LazyLoadVersion(targetVersion int64) (toReturn int64, t } }() - tree.versions[targetVersion] = true - iTree := &ImmutableTree{ ndb: tree.ndb, version: targetVersion, @@ -940,7 +938,7 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) { // Mtx is already held at this point clone := tree.ITree.clone() clone.version = version - tree.versions[version] = true + tree.ndb.resetLatestVersion(version) // set new working tree tree.ITree = clone @@ -1170,10 +1168,6 @@ func (tree *MutableTree) DeleteVersionsRange(fromVersion, toVersion int64) error return err } - for version := fromVersion; version < toVersion; version++ { - delete(tree.versions, version) - } - return nil } @@ -1193,7 +1187,6 @@ func (tree *MutableTree) DeleteVersion(version int64) error { return err } - delete(tree.versions, version) return nil } diff --git a/nodedb.go b/nodedb.go index a3e6d9c..9b5feb6 100644 --- a/nodedb.go +++ b/nodedb.go @@ -531,6 +531,10 @@ func (ndb *nodeDB) DeleteVersionsRange(fromVersion, toVersion int64) error { if err != nil { return err } + first, err := ndb.getFirstVersion() + if err != nil { + return err + } if latest < toVersion { return errors.Errorf("cannot delete latest saved version (%d)", latest) } @@ -580,6 +584,15 @@ func (ndb *nodeDB) DeleteVersionsRange(fromVersion, toVersion int64) error { return nil }) + if first <= toVersion && first >= fromVersion { + // Reset first version if we are deleting all versions from first -> toVersion + ndb.resetFirstVersion(toVersion + 1) + } + if latest <= toVersion { + // Reset latest version if we are deleting all versions from fromVersion -> latest + ndb.resetLatestVersion(fromVersion + 1) + } + if err != nil { return err }