Skip to content

Commit

Permalink
fix: fallback to regular indexing if podsi failed (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
ischasny authored Jan 15, 2024
1 parent 019b67d commit e2e1bf6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions piecedirectory/piecedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,6 @@ func (cr *countingReader) Read(p []byte) (n int, err error) {
}

func parsePieceWithDataSegmentIndex(pieceCid cid.Cid, unpaddedSize int64, r types.SectionReader) ([]model.Record, error) {
defer func() {
// This is a temporary workaround to handle "slice bounds out of range" errors in podsi indexing.
// The bug affects a minor number of deals, so recovering here will help to unblock the users.
// TODO: remove this recover when the underlying bug is figured out and fixed.
if err := recover(); err != nil {
log.Errorw("Recovered from panic and skipped indexing the piece.", "piece", pieceCid, "error", err)
}
}()

concurrency := runtime.NumCPU()
if concurrency < PodsiMinConcurrency {
Expand All @@ -437,10 +429,14 @@ func parsePieceWithDataSegmentIndex(pieceCid cid.Cid, unpaddedSize int64, r type
Reader: r,
cnt: &readsCnt,
}
indexData, err := datasegment.ParseDataSegmentIndex(bufio.NewReaderSize(cr, PodsiBuffesrSize))
panicked := false
indexData, err := parseDataSegmentIndex(pieceCid, bufio.NewReaderSize(cr, PodsiBuffesrSize), &panicked)
if err != nil {
return nil, fmt.Errorf("could not parse data segment index: %w", err)
}
if panicked {
return nil, fmt.Errorf("could not parse data segment index because of an internal panic")
}

log.Debugw("podsi: parsed data segment index", "segments", len(indexData.Entries), "reads", readsCnt, "time", time.Since(start).String())

Expand Down Expand Up @@ -523,6 +519,21 @@ func parsePieceWithDataSegmentIndex(pieceCid cid.Cid, unpaddedSize int64, r type
return recs, nil
}

// parseDataSegmentIndex is a temporary wrapper around datasegment.ParseDataSegmentIndex that exists only as a workaround
// for "slice bounds out of range" panic inside lotus. This funciton should be removed once the panic is fixed.
func parseDataSegmentIndex(pieceCid cid.Cid, unpaddedReader io.Reader, panicked *bool) (datasegment.IndexData, error) {
defer func() {
// This is a temporary workaround to handle "slice bounds out of range" errors in podsi indexing.
// The bug affects a minor number of deals, so recovering here will help to unblock the users.
// TODO: remove this recover when the underlying bug is figured out and fixed.
if err := recover(); err != nil {
*panicked = true
log.Errorw("Recovered from panic and skipped indexing the piece.", "piece", pieceCid, "error", err)
}
}()
return datasegment.ParseDataSegmentIndex(unpaddedReader)
}

func validateEntries(entries []datasegment.SegmentDesc) ([]datasegment.SegmentDesc, error) {
res := make([]datasegment.SegmentDesc, 0, len(entries))
for i, e := range entries {
Expand Down

0 comments on commit e2e1bf6

Please sign in to comment.