Storage-Layer Reed-Solomon Erasure Coding (10+4)
Membuss integrates protocol-level Reed-Solomon erasure coding (klauspost/reedsolomon) directly into ingestion, block storage, peer placement, transparent retrieval, and background repair pipelines.
1. Adaptive Galois Field Matrix Sharding (GF(2^8))
Membuss dynamically optimizes the data (K) and parity (M) shard configuration based on content size to maximize fault tolerance while minimizing storage overhead:
| Payload Size | Data Shards (K) | Parity Shards (M) | Overhead | Fault Tolerance |
|---|---|---|---|---|
< 64 KB | 2 | 1 | +50% | 1 missing shard |
< 1 MB | 4 | 2 | +50% | 2 missing shards |
< 10 MB | 8 | 3 | +37.5% | 3 missing shards |
≥ 10 MB (Default) | 10 | 4 | +40% | 4 missing shards |
Original Block Payload (256 KiB)
├── Data Shards (D1 ... D10) : 10 × 25.6 KiB
└── Parity Shards (P1 ... P4) : 4 × 25.6 KiB
2. Ingestion & Manifest Persistence
During ingestion (AddWithProgress / AddDirectory):
- Shard Encoding: Each leaf block is encoded using
erasure.NewEncoder(erasure.AdaptiveConfig(size)). - Manifest Creation: An
ErasureManifestprotobuf structure is constructed linkingOriginalMid,DataShards,ParityShards, andShardMids. - Storage & Announcement: All 14 shard blocks are stored in the
Blockstoreunder their respectiveShardMIDhashes and announced across the P2P DHT network.
3. Transparent Resilient Retrieval & Reconstruction
When a client requests a MID via fetchingBlockstore:
- Direct Fetch: Attempts to retrieve the primary block directly.
- Erasure Fallback: If the primary block is missing or storing peers go offline:
- Reads the
ErasureManifestfrom store metadata. - Fetches available shards from connected swarm peers.
- As soon as at least
K = DataShardsvalid shards arrive, executesencoder.Decode(shards, manifest). - Verifies reconstructed bytes match the expected BLAKE3 hash.
- Restores the block locally and streams it seamlessly to the caller.
- Reads the
4. Background Shard Repair Worker
The background repair worker (core/erasure/repair.go) continuously audits sealed MIDs:
- Health Audit: Checks presence of all 14 shards across the network.
- Degraded Detection: Identifies MIDs with
K ≤ present < Nshards available. - Shard Reconstruction: Reconstructs missing data/parity shards via matrix inversion.
- Re-distribution: Writes missing shards back to disk/peers and re-announces them to restore full 10+4 redundancy.