diff --git a/mutable_tree.go b/mutable_tree.go index b26f0c8ab..ab8697ed7 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -40,6 +40,7 @@ type MutableTree struct { unsavedFastNodeRemovals *sync.Map // map[string]interface{} FastNodes that have not yet been removed from disk ndb *nodeDB skipFastStorageUpgrade bool // If true, the tree will work like no fast storage and always not upgrade fast storage + initialVersionSet bool mtx sync.Mutex } @@ -146,8 +147,9 @@ func (tree *MutableTree) WorkingHash() []byte { func (tree *MutableTree) WorkingVersion() int64 { version := tree.version + 1 - if version == 1 && tree.ndb.opts.InitialVersion > 0 { + if version == 1 && tree.initialVersionSet { version = int64(tree.ndb.opts.InitialVersion) + tree.initialVersionSet = false } return version } @@ -459,11 +461,11 @@ func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) { tree.ndb.opts.InitialVersion, firstVersion) } - if latestVersion < targetVersion { + if latestVersion >= 0 && latestVersion < targetVersion { return latestVersion, fmt.Errorf("wanted to load target %d but only found up to %d", targetVersion, latestVersion) } - if firstVersion == 0 { + if firstVersion <= 0 { if targetVersion <= 0 { if !tree.skipFastStorageUpgrade { tree.mtx.Lock() @@ -871,6 +873,7 @@ func (tree *MutableTree) saveFastNodeRemovals() error { // and is otherwise ignored. func (tree *MutableTree) SetInitialVersion(version uint64) { tree.ndb.opts.InitialVersion = version + tree.initialVersionSet = true } // DeleteVersionsTo removes versions upto the given version from the MutableTree. diff --git a/nodedb.go b/nodedb.go index 829c5697d..5b98f785d 100644 --- a/nodedb.go +++ b/nodedb.go @@ -838,7 +838,7 @@ func (ndb *nodeDB) getLatestVersion() (int64, error) { return latestVersion, nil } - return 0, nil + return -1, nil } func (ndb *nodeDB) resetLatestVersion(version int64) {