feat(replication): Multi-Tier Replication Manager (v1.8.0)#4203
Open
feat(replication): Multi-Tier Replication Manager (v1.8.0)#4203
Conversation
Co-authored-by: makr-code <150588092+makr-code@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement multi-tier replication for the replication domain
feat(replication): Multi-Tier Replication Manager (v1.8.0)
Mar 13, 2026
makr-code
approved these changes
Mar 14, 2026
There was a problem hiding this comment.
Pull request overview
Adds a new replication-domain component (MultiTierReplicationManager) implementing a configurable three-tier durability/consistency model with optional auto-tiering driven by per-collection access rates, along with focused CI and unit test coverage.
Changes:
- Introduces
MultiTierReplicationManagerAPI + implementation with tier assignment, per-tier config defaults/overrides, auto-tiering, and stats. - Extends replication HA tests with a new
MultiTierReplicationTestsuite and adds a focused CTest target. - Wires the module into modular builds, adds a dedicated GitHub Actions workflow, and updates the replication roadmap.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
include/replication/multi_tier_replication.h |
Declares tiers/configs/stats and the MultiTierReplicationManager public API. |
src/replication/multi_tier_replication.cpp |
Implements tier assignment, auto-tiering, and stats tracking with shared-mutex-based synchronization. |
tests/test_replication_ha.cpp |
Adds MultiTierReplicationTest validating tier defaults, assignment, auto-tiering decisions, and stats. |
tests/CMakeLists.txt |
Adds MultiTierReplicationFocusedTests target and ctest registration. |
cmake/ModularBuild.cmake |
Adds multi_tier_replication.cpp to the transaction module source list for modular builds. |
.github/workflows/multi-tier-replication-ci.yml |
Adds a focused CI workflow to build/run the multi-tier replication focused suite on Ubuntu. |
src/replication/ROADMAP.md |
Marks the module complete and documents delivered scope/tests/CI. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+312
to
+315
| // Simple rate: recent_accesses / window_seconds * 60 | ||
| const double window = static_cast<double>( | ||
| config_.auto_tier_window_seconds > 0 ? config_.auto_tier_window_seconds : 60); | ||
| stats.access_rate_per_min = (stats.recent_accesses / window) * 60.0; |
Comment on lines
+217
to
+233
| ReplicationTier MultiTierReplicationManager::evaluateTierPromotion( | ||
| const std::string& collection) | ||
| { | ||
| if (!auto_tiering_.load()) { | ||
| return getTier(collection); | ||
| } | ||
|
|
||
| ReplicationTier current = getTier(collection); | ||
| double rate = 0.0; | ||
|
|
||
| { | ||
| std::unique_lock<std::shared_mutex> lk(stats_mutex_); | ||
| auto& stats = access_stats_[collection]; | ||
| if (stats.collection.empty()) { | ||
| stats.collection = collection; | ||
| stats.current_tier = current; | ||
| } |
Comment on lines
+47
to
+60
| * TIER_1_CRITICAL – 3 replicas, SYNC, 10 ms SLA, 99.9% availability | ||
| * TIER_2_STANDARD – 2 replicas, SEMI_SYNC, 50 ms SLA, 99% availability | ||
| * TIER_3_ARCHIVAL – 1 replica, ASYNC, no SLA, 90% availability | ||
| */ | ||
| TierConfig builtinTierConfig(ReplicationTier tier) { | ||
| switch (tier) { | ||
| case ReplicationTier::TIER_1_CRITICAL: { | ||
| TierConfig cfg; | ||
| cfg.tier = ReplicationTier::TIER_1_CRITICAL; | ||
| cfg.replica_count = 3; | ||
| cfg.mode = ReplicationMode::SYNC; | ||
| cfg.max_latency_ms = 10; | ||
| cfg.min_availability_pct = 99; // 99.9% rounded to uint | ||
| return cfg; |
| // ── Internal helpers ────────────────────────────────────────────────────── | ||
|
|
||
| /** | ||
| * Recompute access_rate_per_min and recent_accesses for a collection. |
Comment on lines
+284
to
+290
| /** | ||
| * Apply a tier change and update promotion/demotion counters. | ||
| * Must be called while holding the assignment write lock. | ||
| */ | ||
| void applyTierChange(const std::string& collection, | ||
| ReplicationTier old_tier, | ||
| ReplicationTier new_tier); |
Comment on lines
+2491
to
+2504
| add_executable(test_multi_tier_replication_focused | ||
| test_replication_ha.cpp | ||
| ${CMAKE_SOURCE_DIR}/src/replication/multi_tier_replication.cpp | ||
| ) | ||
|
|
||
| target_include_directories(test_multi_tier_replication_focused PRIVATE | ||
| ${CMAKE_SOURCE_DIR}/include | ||
| ${CMAKE_SOURCE_DIR}/src | ||
| ) | ||
|
|
||
| target_link_libraries(test_multi_tier_replication_focused PRIVATE | ||
| ${TEST_LIBS} | ||
| themis_core | ||
| Threads::Threads |
| ../src/replication/replication_slot.cpp | ||
| ../src/replication/raft_v2.cpp | ||
| ../src/replication/schema_cdc.cpp | ||
| ../src/replication/multi_tier_replication.cpp |
| void MultiTierReplicationManager::enableAutoTiering(bool enabled) | ||
| { | ||
| auto_tiering_.store(enabled); | ||
| config_.auto_tiering_enabled = enabled; |
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 hierarchical replication with three configurable durability/consistency tiers and automatic tier promotion/demotion based on per-collection access patterns.
Description
Three-tier model:
TIER_1_CRITICAL— 3+ replicas,SYNC, <10 ms SLA (financial transactions, auth)TIER_2_STANDARD— 2 replicas,SEMI_SYNC, <50 ms SLA (profiles, catalogs)TIER_3_ARCHIVAL— 1 replica,ASYNC, no latency guarantee (audit logs, metrics)New files:
include/replication/multi_tier_replication.h—MultiTierReplicationManager,ReplicationTier,TierConfig,MultiTierConfig,CollectionAccessStats,MultiTierStatssrc/replication/multi_tier_replication.cpp— Full implementation; thread-safe via independentshared_mutexfor assignments and stats (lock-order enforced to prevent deadlock); per-tier config overrides; built-in defaultsUpdated files:
tests/test_replication_ha.cpp— 19 new tests (MultiTierReplicationTest) covering all 5 ACstests/CMakeLists.txt—MultiTierReplicationFocusedTestsfocused targetcmake/ModularBuild.cmake—multi_tier_replication.cppadded toTHEMIS_TRANSACTION_SOURCES.github/workflows/multi-tier-replication-ci.yml— CI on Ubuntu 22.04/gcc-12 and Ubuntu 24.04/gcc-14src/replication/ROADMAP.md— Phase 8 marked complete ✅Usage example:
Type of Change
Testing
📚 Research & Knowledge (wenn applicable)
/docs/research/angelegt?/docs/research/implementation_influence/eingetragen?Relevante Quellen:
Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.