From a04fa4838dcba532cea21d054a22e5f948234a5b Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Fri, 18 Mar 2022 13:36:59 +0700 Subject: [PATCH] Snapshots: corner cases when .seg exists and .idx doesn't (#3731) --- turbo/snapshotsync/block_snapshots.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/turbo/snapshotsync/block_snapshots.go b/turbo/snapshotsync/block_snapshots.go index cc2a1d8a5..fa47c9160 100644 --- a/turbo/snapshotsync/block_snapshots.go +++ b/turbo/snapshotsync/block_snapshots.go @@ -600,12 +600,17 @@ func BuildIndices(ctx context.Context, s *RoSnapshots, snapshotDir *dir.Rw, chai return err } if err := s.Txs.View(func(segments []*TxnSegment) error { - for i, sn := range segments { - if sn.From < from { - continue - } + return s.Bodies.View(func(bodySegments []*BodySegment) error { + for i, sn := range segments { + if sn.From < from { + continue + } + + if bodySegments[i].idxBodyNumber == nil { + log.Info("[snapshots] Segment has no index, skip", "seg", bodySegments[i].seg.FilePath()) + continue + } - if err := s.Bodies.View(func(bodySegments []*BodySegment) error { // build txs idx gg := bodySegments[i].seg.MakeGetter() buf, _ := gg.Next(nil) @@ -633,13 +638,9 @@ func BuildIndices(ctx context.Context, s *RoSnapshots, snapshotDir *dir.Rw, chai return err } - return nil - }); err != nil { - return nil } - - } - return nil + return nil + }) }); err != nil { return nil }