From 223a61da9dc59f7edb12b59bf1e336f383466b19 Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Mon, 25 Sep 2023 13:18:31 +0200 Subject: [PATCH] Check if can recover slot when it's the first not found slot (upper bound) --- pkg/blockstore/schedule.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/blockstore/schedule.go b/pkg/blockstore/schedule.go index 0573c61..7acbadf 100644 --- a/pkg/blockstore/schedule.go +++ b/pkg/blockstore/schedule.go @@ -481,11 +481,11 @@ func (schedule *TraversalSchedule) init( wanted, ) { - _, err := handle.DB.GetSlotMeta(wanted) - if err == nil { - logInfof("even though we couldn't find the slot root, we found the meta for slot %d", wanted) + ok, err := canRecoverSlot(handle, wanted) + if ok { + logInfof("even though we couldn't find the slot root, the slot %d is recoverable", wanted) } else { - logInfof("we couldn't find the slot root, and we couldn't find the meta for slot %d either", wanted) + logInfof("we couldn't find the slot root, and the slot %d is not recoverable: %s", wanted, err) } } break slotLoop @@ -658,6 +658,22 @@ func (schedule *TraversalSchedule) init( return nil } +func canRecoverSlot(db *WalkHandle, slot uint64) (bool, error) { + // can get meta, and can get entries + meta, err := db.DB.GetSlotMeta(slot) + if err != nil { + return false, fmt.Errorf("db %q: failed to get meta for slot %d: %s", db.DB.DB.Name(), slot, err) + } + if meta == nil { + return false, fmt.Errorf("db %q: meta for slot %d is nil", db.DB.DB.Name(), slot) + } + _, err = db.DB.GetEntries(meta, db.shredRevision) + if err != nil { + return false, fmt.Errorf("db %q: failed to get entries for slot %d: %s", db.DB.DB.Name(), slot, err) + } + return true, nil +} + func reverse[T any](x []T) { for i := len(x)/2 - 1; i >= 0; i-- { opp := len(x) - 1 - i