Skip to content

Commit

Permalink
allow single iteration to traverseOrphans with target version
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Nov 14, 2022
1 parent 9869055 commit e5874bd
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,30 @@ func (ndb *nodeDB) DeleteVersionsFrom(version int64, fastMode bool) error {
if err != nil {
return err
}
}
// Next, delete orphans:
// - Delete orphan entries *and referred nodes* with fromVersion >= version
// - Delete orphan entries with toVersion >= version-1 (since orphans at latest are not orphans)
err = ndb.traverseOrphans(func(key, hash []byte) error {
var fromVersion, toVersion int64
orphanKeyFormat.Scan(key, &toVersion, &fromVersion)

// Next, delete orphans:
// - Delete orphan entries *and referred nodes* with fromVersion >= version
// - Delete orphan entries with toVersion >= version-1 (since orphans at latest are not orphans)
for v := version - 1; v <= latest; v++ {
err = ndb.traverseOrphansVersion(v, func(key, hash []byte) error {
if fromVersion >= version {
if err = ndb.batch.Delete(key); err != nil {
return err
}
if err = ndb.batch.Delete(ndb.nodeKey(hash)); err != nil {
return err
}
ndb.nodeCache.Remove(hash)
} else if toVersion >= version-1 {
if err = ndb.batch.Delete(key); err != nil {
return err
}
}
return nil
})
} else {
err = ndb.traverseOrphansVersion(version, func(key, hash []byte) error {
var fromVersion, toVersion int64
orphanKeyFormat.Scan(key, &toVersion, &fromVersion)
if fromVersion >= version {
Expand All @@ -473,10 +490,9 @@ func (ndb *nodeDB) DeleteVersionsFrom(version int64, fastMode bool) error {
}
return nil
})

if err != nil {
return err
}
}
if err != nil {
return err
}

// Delete the version root entries
Expand Down

0 comments on commit e5874bd

Please sign in to comment.