Skip to content

feat(erasure): code and decode Reed-Solomon stripes (sc-1582) - #110

Open
alanshaw wants to merge 1 commit into
mainfrom
ash/feat/stripe-coding
Open

alanshaw wants to merge 1 commit into
mainfrom
ash/feat/stripe-coding

Conversation

@alanshaw

@alanshaw alanshaw commented Dec 4, 2026

Copy link
Copy Markdown
Member

Adds the shared library that codes and decodes stripes, as the erasure coding RFC defines them, so Ingot, and later repair and other clients, produce identical pieces. Nothing uses it yet. Story: sc-1582.

  • Encoding. Reads a stripe chunk one row at a time and writes each data and parity piece as it goes, so memory stays at one row however large the chunk is (12 MiB for RS 8+4 with 1 MiB cells). It reproduces the test vector in the RFC.
  • Piece lengths and the cell size rule. Gives the length of every piece, including a short last row, and refuses a chunk too short to give every data piece a byte. The upload service needs these lengths to allocate pieces before any byte is sent.
  • Reading a range. Maps a byte range of the chunk to one range in each data piece, and puts the fetched ranges back in order.
  • Rebuilding pieces. Makes any pieces' bytes for a span of rows from any k others. A read with a data piece missing uses it for just the rows it needs, and repair uses it for a whole piece.

The Reed-Solomon arithmetic comes from klauspost/reedsolomon, a new dependency, which is the library the RFC names.

🤖 Generated with Claude Code

Add the shared coding library for the /stripe/rs/0 scheme: streaming
interleaved encode, piece lengths and the cell size rule, range-read
planning, and rebuilding pieces from k others.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unchecked layout arithmetic can overflow, causing division-by-zero panics for accepted configurations and incorrect final-row range lengths.

2 open issues
What changed in this PR

Adds a shared Reed–Solomon stripe library so Ingot, repair, and other clients can produce compatible pieces. No callers are integrated yet.

Changes:

  • Implements streaming encoding and piece reconstruction.
  • Calculates piece lengths and supports byte-range reads.
  • Adds RFC-vector tests, round-trip coverage, and an encoding benchmark.
File Description
go.sum Records Reed–Solomon dependency checksums.
go.mod Adds the Reed–Solomon dependency.
erasure/​layout.go Defines layout validation, piece lengths, and range calculations.
erasure/​erasure_test.go Tests encoding, reconstruction, ranges, and invalid inputs.
erasure/​code.go Implements streaming encoding, range reading, and reconstruction.

Review effort: Balanced

Comment thread erasure/layout.go
// k is 1: a cell longer than the chunk holds no more than the chunk.
cellSize = size
}
return Layout{size: size, k: int(k), m: int(m), cell: cellSize}, nil
Comment thread erasure/layout.go
return Range{}, fmt.Errorf("erasure: rows %d to %d are outside a stripe of %d rows", first, last, l.Rows())
}
start := l.before(slot, first*l.rowSize())
end := l.before(slot, min((last+1)*l.rowSize(), l.size))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants