@@ -40,6 +40,7 @@ type MutableTree struct {
40
40
unsavedFastNodeRemovals * sync.Map // map[string]interface{} FastNodes that have not yet been removed from disk
41
41
ndb * nodeDB
42
42
skipFastStorageUpgrade bool // If true, the tree will work like no fast storage and always not upgrade fast storage
43
+ initialVersionSet bool
43
44
44
45
mtx sync.Mutex
45
46
}
@@ -146,8 +147,9 @@ func (tree *MutableTree) WorkingHash() []byte {
146
147
147
148
func (tree * MutableTree ) WorkingVersion () int64 {
148
149
version := tree .version + 1
149
- if version == 1 && tree .ndb . opts . InitialVersion > 0 {
150
+ if version == 1 && tree .initialVersionSet {
150
151
version = int64 (tree .ndb .opts .InitialVersion )
152
+ tree .initialVersionSet = false
151
153
}
152
154
return version
153
155
}
@@ -459,11 +461,11 @@ func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) {
459
461
tree .ndb .opts .InitialVersion , firstVersion )
460
462
}
461
463
462
- if latestVersion < targetVersion {
464
+ if latestVersion >= 0 && latestVersion < targetVersion {
463
465
return latestVersion , fmt .Errorf ("wanted to load target %d but only found up to %d" , targetVersion , latestVersion )
464
466
}
465
467
466
- if firstVersion = = 0 {
468
+ if firstVersion < = 0 {
467
469
if targetVersion <= 0 {
468
470
if ! tree .skipFastStorageUpgrade {
469
471
tree .mtx .Lock ()
@@ -871,6 +873,7 @@ func (tree *MutableTree) saveFastNodeRemovals() error {
871
873
// and is otherwise ignored.
872
874
func (tree * MutableTree ) SetInitialVersion (version uint64 ) {
873
875
tree .ndb .opts .InitialVersion = version
876
+ tree .initialVersionSet = true
874
877
}
875
878
876
879
// DeleteVersionsTo removes versions upto the given version from the MutableTree.
0 commit comments