Skip to content

feat(replication): Multi-Tier Replication Manager (v1.8.0)#4203

Open
Copilot wants to merge 2 commits intodevelopfrom
copilot/implement-multi-tier-replication
Open

feat(replication): Multi-Tier Replication Manager (v1.8.0)#4203
Copilot wants to merge 2 commits intodevelopfrom
copilot/implement-multi-tier-replication

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

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.hMultiTierReplicationManager, ReplicationTier, TierConfig, MultiTierConfig, CollectionAccessStats, MultiTierStats
  • src/replication/multi_tier_replication.cpp — Full implementation; thread-safe via independent shared_mutex for assignments and stats (lock-order enforced to prevent deadlock); per-tier config overrides; built-in defaults

Updated files:

  • tests/test_replication_ha.cpp — 19 new tests (MultiTierReplicationTest) covering all 5 ACs
  • tests/CMakeLists.txtMultiTierReplicationFocusedTests focused target
  • cmake/ModularBuild.cmakemulti_tier_replication.cpp added to THEMIS_TRANSACTION_SOURCES
  • .github/workflows/multi-tier-replication-ci.yml — CI on Ubuntu 22.04/gcc-12 and Ubuntu 24.04/gcc-14
  • src/replication/ROADMAP.md — Phase 8 marked complete ✅

Usage example:

MultiTierConfig cfg;
cfg.auto_tiering_enabled  = true;
cfg.hot_access_threshold  = 100;  // accesses/min → Tier 1
cfg.cold_access_threshold = 5;    // accesses/min → Tier 3

MultiTierReplicationManager mgr(cfg);
mgr.assignTier("financial_transactions", ReplicationTier::TIER_1_CRITICAL);
mgr.assignTier("user_profiles",          ReplicationTier::TIER_2_STANDARD);
mgr.assignTier("audit_logs",             ReplicationTier::TIER_3_ARCHIVAL);

// Auto-tiering: hot data promoted, cold data demoted
mgr.recordAccess("audit_logs");
ReplicationTier t = mgr.evaluateTierPromotion("audit_logs"); // → TIER_3_ARCHIVAL if cold

Type of Change

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

Testing

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

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

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>Multi-Tier Replication</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Multi-Tier Replication' for the replication domain. It is sourced from the consolidated roadmap under 🟢 Low Priority — Future (v1.9.0+) and targets milestone v1.8.0.

Primary detail section: Multi-Tier Replication

Goal

Deliver the scoped changes for Multi-Tier Replication in src/replication/ and complete the linked detail section in a release-ready state for v1.8.0.

Detailed Scope

Multi-Tier Replication

Priority: Low
Target Version: v1.8.0

Hierarchical replication with different consistency and durability tiers.

Features:

  • Tier 1: Strong consistency, high durability (3+ replicas)
  • Tier 2: Eventual consistency, moderate durability (2 replicas)
  • Tier 3: Best-effort, low durability (1 replica, async)
  • Per-collection tier assignment
  • Automatic tier promotion/demotion based on access patterns

Architecture:

class MultiTierReplicationManager {
public:
    enum ReplicationTier {
        TIER_1_CRITICAL,    // 3+ replicas, sync, <10ms
        TIER_2_STANDARD,    // 2 replicas, semi-sync, <50ms
        TIER_3_ARCHIVAL     // 1 replica, async, no guarantee
    };
    
    struct TierConfig {
        ReplicationTier tier;
        uint32_t replica_count;
        ReplicationMode mode;
        uint32_t max_latency_ms;
        uint32_t min_availability_percent;
    };
    
    // Assign collection to tier
    void assignTier(const std::string& collection, ReplicationTier tier);
    
    // Automatic tier adjustment based on access patterns
    void enableAutoTiering(bool enabled);
    
    // Get current tier for collection
    ReplicationTier getTier(const std::string& collection) const;
};

// Example: Multi-tier replication
MultiTierReplicationManager multi_tier;

// Tier assignments
multi_tier.assignTier("financial_transactions", ReplicationTier::TIER_1_CRITICAL);
multi_tier.assignTier("user_profiles", ReplicationTier::TIER_2_STANDARD);
multi_tier.assignTier("audit_logs", ReplicationTier::TIER_3_ARCHIVAL);

// Auto-tiering based on access
multi_tier.enableAutoTiering(true);  // Hot data → Tier 1, Cold data → Tier 3

Acceptance Criteria

  • Tier 1: Strong consistency, high durability (3+ replicas)
  • Tier 2: Eventual consistency, moderate durability (2 replicas)
  • Tier 3: Best-effort, low durability (1 replica, async)
  • Per-collection tier assignment
  • Automatic tier promotion/demotion based on access patterns

Relationships

References

  • src/ROADMAP.md
  • src/replication/FUTURE_ENHANCEMENTS.md#multi-tier-replication
  • Source key: roadmap:258:replication:v1.8.0:multi-tier-replication

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)


💡 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.

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
Copilot AI requested a review from makr-code March 13, 2026 20:14
@makr-code makr-code marked this pull request as ready for review March 14, 2026 06:13
@makr-code makr-code requested a review from Copilot March 14, 2026 06:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 MultiTierReplicationManager API + implementation with tier assignment, per-tier config defaults/overrides, auto-tiering, and stats.
  • Extends replication HA tests with a new MultiTierReplicationTest suite 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;
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.

Multi-Tier Replication

3 participants