Repository navigation
feat(storage): Reed-Solomon erasure coding for blob storage (v1.7.0 #207) - #4232
Merged
Merged
Conversation
… (v1.7.0 Issue #207) Co-authored-by: makr-code <[email protected]>
Copilot
AI
changed the title
[WIP] Implement erasure coding for blob storage
feat(storage): Reed-Solomon erasure coding for blob storage (v1.7.0 #207)
Mar 14, 2026
makr-code
marked this pull request as ready for review
March 14, 2026 17:56
Contributor
There was a problem hiding this comment.
Pull request overview
Implements Reed-Solomon erasure coding support for blob storage by adding an ErasureCodingBackend and wiring BlobRedundancyManager’s PARITY mode to actually encode/decode shards, plus adds focused tests and CI coverage.
Changes:
- Added
ErasureCodingBackendwith low-level encode/decode and an in-memory shard store for tests. - Updated
BlobRedundancyManagerto handlePARITYmode inwriteBlob/readBlobusing erasure-coded chunks. - Added unit/integration tests, updated CMake test registration, and introduced a dedicated CI workflow.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| include/storage/erasure_coding_backend.h | Declares new erasure-coding backend API and shard model. |
| src/storage/erasure_coding_backend.cpp | Implements encode/decode and in-memory shard store. |
| src/storage/blob_redundancy_manager.cpp | Adds PARITY-mode write/read paths using erasure coding. |
| tests/test_erasure_coding_backend.cpp | Adds focused backend tests + PARITY integration tests. |
| cmake/CMakeLists.txt | Builds new backend source and registers new test binary. |
| tests/CMakeLists.txt | Fixes missing endif() that blocked test configuration. |
| .github/workflows/erasure-coding-blob-storage-ci.yml | Adds targeted CI for erasure-coding changes. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+588
to
+607
| if (available.size() < static_cast<size_t>(ec_cfg.data_shards)) { | ||
| return themis::Err<std::vector<uint8_t>>( | ||
| themis::errors::ErrorCode::ERR_STORAGE_FILE_NOT_FOUND, | ||
| "Not enough shards to reconstruct blob '" + blob_id + | ||
| "': have " + std::to_string(available.size()) + | ||
| ", need " + std::to_string(ec_cfg.data_shards) | ||
| ); | ||
| } | ||
|
|
||
| ErasureCodingBackend ec_backend(ec_cfg); | ||
| try { | ||
| auto recovered = ec_backend.decode(blob_id, available, original_size); | ||
| return themis::Ok(std::move(recovered)); | ||
| } catch (const std::exception& ex) { | ||
| return themis::Err<std::vector<uint8_t>>( | ||
| themis::errors::ErrorCode::ERR_STORAGE_FILE_NOT_FOUND, | ||
| "Erasure decode failed for blob '" + blob_id + "': " + | ||
| std::string(ex.what()) | ||
| ); | ||
| } |
Comment on lines
+579
to
+584
|
|
||
| if (available.size() >= static_cast<size_t>(ec_cfg.data_shards)) { | ||
| // We have enough shards to reconstruct; stop reading further | ||
| // to save I/O when shards are on separate remote nodes. | ||
| break; | ||
| } |
Comment on lines
+191
to
+226
| std::lock_guard<std::mutex> lock(store_mutex_); | ||
|
|
||
| auto it = store_.find(blob_id); | ||
| if (it == store_.end()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| const BlobEntry& entry = it->second; | ||
|
|
||
| // Verify we have enough shards for reconstruction | ||
| if (entry.chunks.size() < static_cast<size_t>(config_.data_shards)) { | ||
| spdlog::warn("ErasureCodingBackend::get: blob='{}' only {}/{} shards " | ||
| "available (need {}); cannot reconstruct", | ||
| blob_id, entry.chunks.size(), | ||
| config_.totalShards(), config_.data_shards); | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| // Build EncodedShard map for decode() | ||
| std::map<uint32_t, EncodedShard> shard_map; | ||
| for (const auto& [idx, chunk] : entry.chunks) { | ||
| EncodedShard s; | ||
| s.shard_index = idx; | ||
| s.is_parity = (idx >= config_.data_shards); | ||
| s.original_size = entry.original_size; | ||
| s.data = chunk; | ||
| shard_map[idx] = std::move(s); | ||
| } | ||
|
|
||
| try { | ||
| return decode(blob_id, shard_map, entry.original_size); | ||
| } catch (const std::exception& ex) { | ||
| spdlog::error("ErasureCodingBackend::get: decode failed for '{}': {}", | ||
| blob_id, ex.what()); | ||
| return std::nullopt; | ||
| } |
Comment on lines
+37
to
+47
| themis::sharding::ErasureCodingAlgorithm algo; | ||
| switch (config_.algorithm) { | ||
| case ErasureCodingAlgorithm::CAUCHY: | ||
| algo = themis::sharding::ErasureCodingAlgorithm::CAUCHY; | ||
| break; | ||
| case ErasureCodingAlgorithm::REED_SOLOMON: | ||
| case ErasureCodingAlgorithm::LRC: | ||
| default: | ||
| algo = themis::sharding::ErasureCodingAlgorithm::REED_SOLOMON; | ||
| break; | ||
| } |
Comment on lines
+293
to
+305
| TEST_F(ErasureCodingFocusedTests, TooManyLosses_RS4_2_ThrowsOrFails) { | ||
| ErasureCodingBackend b(makeConfig(4, 2)); | ||
| auto orig = makeData(512); | ||
| auto shards = b.encode("blob", orig); | ||
|
|
||
| // Remove 3 shards (exceeds parity_shards=2) | ||
| std::map<uint32_t, EncodedShard> smap; | ||
| for (auto& s : shards) { | ||
| if (s.shard_index > 2) smap[s.shard_index] = s; | ||
| } | ||
|
|
||
| EXPECT_THROW(b.decode("blob", smap, orig.size()), std::runtime_error); | ||
| } |
…TURE_ENHANCEMENTS status Co-authored-by: makr-code <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements erasure coding redundancy for blob storage.
BlobRedundancyManagerpreviously ignoredRedundancyMode::PARITYand silently fell through to plain replication.ErasureCodingBackendwraps the existingthemis::sharding::ReedSolomonCoder/CauchyReedSolomonCoderand is now wired intowriteBlob/readBlob.Description
ErasureCodingBackend(include/storage/erasure_coding_backend.h+src/storage/erasure_coding_backend.cpp)encode()→vector<EncodedShard>,decode(available_shards, original_size)with zero-padding trimput()/get()/remove()with internal shard store;dropShard()for fault-tolerance testingstorageOverhead(),faultTolerance(),canRecover(n)BlobRedundancyManager(src/storage/blob_redundancy_manager.cpp)writeBlob: PARITY mode encodes viaErasureCodingBackend, stores each chunk atecShardId(meta, i)/ecChunkPath(blob_id, i); fails if fewer thandata_shardschunks writtenreadBlob: collects chunks across shard locations, stops afterdata_shardsavailable (saves I/O), decodes withmetadata.total_sizeasoriginal_sizeto strip paddingecShardId()/ecChunkPath()extracted as file-local helpers — both paths share identical addressing logicBuild & tests
erasure_coding_backend.cppadded toTHEMIS_CORE_SOURCEStest_erasure_coding_backend_focusedregistered intests/CMakeLists.txt→ErasureCodingFocusedTestsctest targetcmake/CMakeLists.txt:test_erasure_coding_backendgtest executable registerederasure-coding-blob-storage-ci.ymluses./.github/actions/configure-themis(aligned with repo convention)endif()intests/CMakeLists.txtthat caused all test configuration to failsrc/storage/FUTURE_ENHANCEMENTS.md: marked ✅ Implemented, correcteddata_blocks/parity_blocks→data_shards/parity_shardsType of Change
Testing
39 tests in
ErasureCodingFocusedTests+ErasureCodingBlobManagerTest:> parity_shardslosses → throws / returnsnullopt)RS(10,4) < 1.5×,RS(4,2) ≈ 1.5×)BlobRedundancyManagerPARITY write → read → shard-loss → recover📚 Research & Knowledge (wenn applicable)
Relevante Quellen:
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.