Skip to content

feat(storage): Reed-Solomon erasure coding for blob storage (v1.7.0 #207) - #4232

Merged
makr-code merged 4 commits into
developfrom
copilot/erasure-coding-for-blob-storage
Mar 14, 2026
Merged

makr-code merged 4 commits into
developfrom
copilot/erasure-coding-for-blob-storage

Conversation

Copilot AI commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Implements erasure coding redundancy for blob storage. BlobRedundancyManager previously ignored RedundancyMode::PARITY and silently fell through to plain replication. ErasureCodingBackend wraps the existing themis::sharding::ReedSolomonCoder / CauchyReedSolomonCoder and is now wired into writeBlob/readBlob.

Description

ErasureCodingBackend (include/storage/erasure_coding_backend.h + src/storage/erasure_coding_backend.cpp)

  • Low-level: encode() → vector<EncodedShard>, decode(available_shards, original_size) with zero-padding trim
  • High-level: put() / get() / remove() with internal shard store; dropShard() for fault-tolerance testing
  • Config accessors: storageOverhead(), faultTolerance(), canRecover(n)
  • Supported schemes: RS(10,4) = 1.4× overhead, RS(6,3) = RS(4,2) = 1.5×
ErasureCodingConfig cfg;
cfg.data_shards   = 10;   // RS(10,4): 40% overhead vs 200% for 2× mirroring
cfg.parity_shards = 4;

ErasureCodingBackend backend(cfg);
backend.put("blob-123", data);            // encodes → 14 shards
auto result = backend.get("blob-123");    // reconstructs from any 10 of 14
backend.dropShard("blob-123", 2);         // simulate node failure
auto recovered = backend.get("blob-123"); // still recovers (3 remaining in budget)

BlobRedundancyManager (src/storage/blob_redundancy_manager.cpp)

  • writeBlob: PARITY mode encodes via ErasureCodingBackend, stores each chunk at ecShardId(meta, i) / ecChunkPath(blob_id, i); fails if fewer than data_shards chunks written
  • readBlob: collects chunks across shard locations, stops after data_shards available (saves I/O), decodes with metadata.total_size as original_size to strip padding
  • ecShardId() / ecChunkPath() extracted as file-local helpers — both paths share identical addressing logic

Build & tests

  • erasure_coding_backend.cpp added to THEMIS_CORE_SOURCES
  • test_erasure_coding_backend_focused registered in tests/CMakeLists.txt → ErasureCodingFocusedTests ctest target
  • cmake/CMakeLists.txt: test_erasure_coding_backend gtest executable registered
  • CI: erasure-coding-blob-storage-ci.yml uses ./.github/actions/configure-themis (aligned with repo convention)
  • Fixed pre-existing missing endif() in tests/CMakeLists.txt that caused all test configuration to fail
  • src/storage/FUTURE_ENHANCEMENTS.md: marked ✅ Implemented, corrected data_blocks/parity_blocks → data_shards/parity_shards

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

39 tests in ErasureCodingFocusedTests + ErasureCodingBlobManagerTest:

  • RS(10,4) / RS(6,3) / RS(4,2) encode/decode round-trips (1 byte → 64 KB)
  • Single + multi-shard failure at maximum tolerance boundary for all three schemes
  • Unrecoverable scenarios (> parity_shards losses → throws / returns nullopt)
  • Storage overhead assertions (RS(10,4) < 1.5×, RS(4,2) ≈ 1.5×)
  • BlobRedundancyManager PARITY write → read → shard-loss → recover

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Erasure Coding for Blob Storage</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Erasure Coding for Blob Storage' for the storage domain. It is sourced from the consolidated roadmap under 🟡 Medium Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.7.0.

Primary detail section: Erasure Coding for Blob Storage

Goal

Deliver the scoped changes for Erasure Coding for Blob Storage in src/storage/ and complete the linked detail section in a release-ready state for v1.7.0.

Detailed Scope

Erasure Coding for Blob Storage

Priority: Medium
Target Version: v1.7.0

Space-efficient redundancy using erasure codes (e.g., Reed-Solomon).

Encoding Schemes:

  • RS(10,4): 10 data + 4 parity blocks (40% overhead vs 200% for mirroring)
  • RS(6,3): 6 data + 3 parity blocks (50% overhead)
  • RS(4,2): 4 data + 2 parity blocks (50% overhead, faster)

Benefits:

  • 50-70% storage savings vs mirroring
  • Survives multiple node failures
  • Configurable fault tolerance

Example:

ErasureCodingConfig config;
config.data_blocks = 10;
config.parity_blocks = 4;

ErasureCodingBackend backend(config);
backend.put("blob-123", data);  // Automatically encodes and distributes

// Survives loss of up to 4 blocks
auto result = backend.get("blob-123");  // Reconstructs from available blocks

Acceptance Criteria

  • RS(10,4): 10 data + 4 parity blocks (40% overhead vs 200% for mirroring)
  • RS(6,3): 6 data + 3 parity blocks (50% overhead)
  • RS(4,2): 4 data + 2 parity blocks (50% overhead, faster)
  • 50-70% storage savings vs mirroring
  • Survives multiple node failures
  • Configurable fault tolerance

Relationships

References

  • src/ROADMAP.md
  • src/storage/FUTURE_ENHANCEMENTS.md#erasure-coding-for-blob-storage
  • Source key: roadmap:207:storage:v1.7.0:erasure-coding-for-blob-storage

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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
Copilot AI requested a review from makr-code March 14, 2026 16:32
@makr-code
makr-code marked this pull request as ready for review March 14, 2026 17:56
@makr-code
makr-code requested a review from Copilot March 14, 2026 17:56

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.

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 ErasureCodingBackend with low-level encode/decode and an in-memory shard store for tests.
  • Updated BlobRedundancyManager to handle PARITY mode in writeBlob/readBlob using 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);
}
@makr-code
makr-code merged commit f48dc62 into develop Mar 14, 2026
49 of 58 checks passed
@github-actions github-actions Bot added type:test Test-only change area:storage Storage subsystem labels Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage subsystem type:test Test-only change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Erasure Coding for Blob Storage

3 participants