Skip to content

Commit 8a2e2fe

Browse files
authored
fix: continue pruning if version is not found (#1063)
1 parent 0bce70d commit 8a2e2fe

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

nodedb.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -459,31 +459,37 @@ func newRootkeyCache() *rootkeyCache {
459459
// deletes orphans
460460
func (ndb *nodeDB) deleteVersion(version int64, cache *rootkeyCache) error {
461461
rootKey, err := cache.getRootKey(ndb, version)
462-
if err != nil {
462+
if err != nil && !errors.Is(err, ErrVersionDoesNotExist) {
463463
return err
464464
}
465465

466-
if err := ndb.traverseOrphansWithRootkeyCache(cache, version, version+1, func(orphan *Node) error {
467-
if orphan.nodeKey.nonce == 0 && !orphan.isLegacy {
468-
// if the orphan is a reformatted root, it can be a legacy root
469-
// so it should be removed from the pruning process.
470-
if err := ndb.deleteFromPruning(ndb.legacyNodeKey(orphan.hash)); err != nil {
471-
return err
466+
if errors.Is(err, ErrVersionDoesNotExist) {
467+
ndb.logger.Error("Error while pruning, moving on the the next version in the store", "version missing", version, "next version", version+1, "err", err)
468+
}
469+
470+
if rootKey != nil {
471+
if err := ndb.traverseOrphansWithRootkeyCache(cache, version, version+1, func(orphan *Node) error {
472+
if orphan.nodeKey.nonce == 0 && !orphan.isLegacy {
473+
// if the orphan is a reformatted root, it can be a legacy root
474+
// so it should be removed from the pruning process.
475+
if err := ndb.deleteFromPruning(ndb.legacyNodeKey(orphan.hash)); err != nil {
476+
return err
477+
}
472478
}
479+
if orphan.nodeKey.nonce == 1 && orphan.nodeKey.version < version {
480+
// if the orphan is referred to the previous root, it should be reformatted
481+
// to (version, 0), because the root (version, 1) should be removed but not
482+
// applied now due to the batch writing.
483+
orphan.nodeKey.nonce = 0
484+
}
485+
nk := orphan.GetKey()
486+
if orphan.isLegacy {
487+
return ndb.deleteFromPruning(ndb.legacyNodeKey(nk))
488+
}
489+
return ndb.deleteFromPruning(ndb.nodeKey(nk))
490+
}); err != nil && !errors.Is(err, ErrVersionDoesNotExist) {
491+
return err
473492
}
474-
if orphan.nodeKey.nonce == 1 && orphan.nodeKey.version < version {
475-
// if the orphan is referred to the previous root, it should be reformatted
476-
// to (version, 0), because the root (version, 1) should be removed but not
477-
// applied now due to the batch writing.
478-
orphan.nodeKey.nonce = 0
479-
}
480-
nk := orphan.GetKey()
481-
if orphan.isLegacy {
482-
return ndb.deleteFromPruning(ndb.legacyNodeKey(nk))
483-
}
484-
return ndb.deleteFromPruning(ndb.nodeKey(nk))
485-
}); err != nil {
486-
return err
487493
}
488494

489495
literalRootKey := GetRootKey(version)
@@ -497,7 +503,7 @@ func (ndb *nodeDB) deleteVersion(version int64, cache *rootkeyCache) error {
497503

498504
// check if the version is referred by the next version
499505
nextRootKey, err := cache.getRootKey(ndb, version+1)
500-
if err != nil {
506+
if err != nil && !errors.Is(err, ErrVersionDoesNotExist) {
501507
return err
502508
}
503509
if bytes.Equal(literalRootKey, nextRootKey) {

0 commit comments

Comments
 (0)