Skip to content

Commit

Permalink
Check if can recover slot when it's the first not found slot (upper b…
Browse files Browse the repository at this point in the history
…ound)
  • Loading branch information
gagliardetto committed Sep 25, 2023
1 parent 9b35c9e commit 223a61d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/blockstore/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 223a61d

Please sign in to comment.