| Crates.io | aegis-replication |
| lib.rs | aegis-replication |
| version | 0.1.7 |
| created_at | 2026-01-20 02:38:34.563863+00 |
| updated_at | 2026-01-24 03:53:05.963001+00 |
| description | Distributed replication for Aegis database |
| homepage | https://automatanexus.com |
| repository | https://github.com/AutomataNexus/Aegis-DB |
| max_upload_size | |
| id | 2055687 |
| size | 295,679 |
Distributed replication and consensus for the Aegis Database Platform.
aegis-replication provides the distributed systems layer including Raft consensus, consistent hashing, sharding, distributed transactions, and conflict-free replicated data types (CRDTs).
┌────────────────────────────────────────────────────────┐
│ Cluster Manager │
├────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Raft │ │ Shard │ │ Transaction │ │
│ │ Consensus │ │ Router │ │ Coordinator │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Hash │ │ Vector │ │ CRDT │ │
│ │ Ring │ │ Clocks │ │ Engine │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├────────────────────────────────────────────────────────┤
│ Transport Layer │
│ (gRPC / TCP / In-Memory) │
└────────────────────────────────────────────────────────┘
| Module | Description |
|---|---|
raft |
Raft consensus implementation |
cluster |
Cluster membership management |
shard |
Shard assignment and routing |
partition |
Data partitioning strategies |
hash |
Consistent hashing algorithms |
transaction |
Distributed transaction coordinator |
crdt |
CRDT implementations |
vector_clock |
Vector clock for causality |
transport |
Network communication |
log |
Replicated log |
[dependencies]
aegis-replication = { path = "../aegis-replication" }
use aegis_replication::raft::{RaftNode, RaftConfig};
let config = RaftConfig {
node_id: 1,
peers: vec![2, 3],
election_timeout: Duration::from_millis(150..300),
heartbeat_interval: Duration::from_millis(50),
};
let node = RaftNode::new(config, storage)?;
// Start the node
node.start().await?;
// Propose a value (only leader can propose)
if node.is_leader() {
node.propose(command).await?;
}
use aegis_replication::hash::{HashRing, JumpHash};
// HashRing with virtual nodes
let mut ring = HashRing::new(150); // 150 virtual nodes per physical node
ring.add_node("node-1");
ring.add_node("node-2");
ring.add_node("node-3");
// Get nodes for a key (returns primary + replicas)
let nodes = ring.get_nodes("user:123", 3);
// JumpHash for fixed node count
let node_index = JumpHash::hash("user:123", 3);
use aegis_replication::transaction::{TwoPhaseCommit, TransactionCoordinator};
let coordinator = TransactionCoordinator::new(cluster);
// Begin distributed transaction
let tx = coordinator.begin().await?;
// Execute on multiple shards
tx.execute_on_shard(shard_1, operation_1).await?;
tx.execute_on_shard(shard_2, operation_2).await?;
// Two-phase commit
coordinator.commit(tx).await?;
use aegis_replication::crdt::{GCounter, LWWRegister, ORSet};
// G-Counter (grow-only counter)
let mut counter = GCounter::new(node_id);
counter.increment(5);
counter.merge(&remote_counter);
println!("Count: {}", counter.value());
// LWW-Register (last-writer-wins)
let mut register = LWWRegister::new();
register.set("value", timestamp);
// OR-Set (observed-remove set)
let mut set = ORSet::new(node_id);
set.add("item");
set.remove("item");
use aegis_replication::vector_clock::VectorClock;
let mut clock = VectorClock::new();
// Increment local time
clock.increment(node_id);
// Merge with remote clock
clock.merge(&remote_clock);
// Compare causality
match clock.compare(&other_clock) {
Ordering::Before => println!("Happened before"),
Ordering::After => println!("Happened after"),
Ordering::Concurrent => println!("Concurrent events"),
}
[replication]
replication_factor = 3
consistency_level = "quorum" # one, quorum, all
[raft]
election_timeout_min = 150
election_timeout_max = 300
heartbeat_interval = 50
[sharding]
strategy = "hash" # hash, range
shard_count = 16
auto_rebalance = true
cargo test -p aegis-replication
Test count: 136 tests
Apache-2.0