@@ -459,31 +459,37 @@ func newRootkeyCache() *rootkeyCache {
459
459
// deletes orphans
460
460
func (ndb * nodeDB ) deleteVersion (version int64 , cache * rootkeyCache ) error {
461
461
rootKey , err := cache .getRootKey (ndb , version )
462
- if err != nil {
462
+ if err != nil && ! errors . Is ( err , ErrVersionDoesNotExist ) {
463
463
return err
464
464
}
465
465
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
+ }
472
478
}
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
473
492
}
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
487
493
}
488
494
489
495
literalRootKey := GetRootKey (version )
@@ -497,7 +503,7 @@ func (ndb *nodeDB) deleteVersion(version int64, cache *rootkeyCache) error {
497
503
498
504
// check if the version is referred by the next version
499
505
nextRootKey , err := cache .getRootKey (ndb , version + 1 )
500
- if err != nil {
506
+ if err != nil && ! errors . Is ( err , ErrVersionDoesNotExist ) {
501
507
return err
502
508
}
503
509
if bytes .Equal (literalRootKey , nextRootKey ) {
0 commit comments