Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fallback to regular indexing if podsi failed #1870

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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