Skip to content

Commit 971fd36

Browse files
fix: continue pruning if version is not found (backport #1063) (#1066)
Co-authored-by: PaddyMc <paddymchale@hotmail.com>
1 parent 1170299 commit 971fd36

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
@@ -460,31 +460,37 @@ func newRootkeyCache() *rootkeyCache {
460460
// deletes orphans
461461
func (ndb *nodeDB) deleteVersion(version int64, cache *rootkeyCache) error {
462462
rootKey, err := cache.getRootKey(ndb, version)
463-
if err != nil {
463+
if err != nil && !errors.Is(err, ErrVersionDoesNotExist) {
464464
return err
465465
}
466466

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

490496
literalRootKey := GetRootKey(version)
@@ -498,7 +504,7 @@ func (ndb *nodeDB) deleteVersion(version int64, cache *rootkeyCache) error {
498504

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

0 commit comments

Comments
 (0)