用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/AzureFoxStudios/wabi --skill wabidb-replication-system命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | wabidb-replication-system |
| version | 0.1.0 |
| author | Hermes |
| description | Learn WabiDB replication system including SyncTransport and HTTP endpoints. |
| platforms | ["linux","macos","windows"] |
| metadata | {"hermes":{"tags":["Replication","WabiDB","SyncTransport","HTTP"]}} |
This skill provides a structured approach to learning WabiDB's replication system, focusing on the SyncTransport trait and HTTP endpoints implementation.
src/replication/)Use these commands to explore the replication system:
# View SyncTransport implementation
read_file /var/home/Ronin/wabi/core/crates/wabidb/src/replication/sync_protocol.rs
# View SyncWorker implementation
read_file /var/home/Ronin/wabi/core/crates/wabidb/src/replication/sync_worker.rs
# Run replication tests
cargo test -p wabidb --test sync_protocol
cargo test -p wabidb --test sync_worker
| Component | Key Files | Key Functions | Purpose |
|---|---|---|---|
| SyncTransport | sync_protocol.rs | build_sync_request, apply_sync_response | Define replication protocol |
| SyncWorker | sync_worker.rs | new, run_once, run_forever | Implement replication worker |
| HTTP Endpoints | sync_endpoints.rs | handle_sync_request, handle_sync_response | HTTP interface |
Pattern: The SyncTransport trait defines the replication protocol with request/response structures.
Key Components:
SyncRequest: Contains since_commit_seq to specify sync starting pointSyncResponse: Contains new entries, latest commit sequence, and sync basebuild_sync_request: Creates a sync request with given sequence numberapply_sync_response: Merges remote entries into local stateExample Implementation:
pub struct SyncRequest {
pub since_commit_seq: u64,
}
pub struct SyncResponse {
pub since_commit_seq: u64,
pub entries: Vec<CommitIndexEntry>,
pub latest_commit_seq: u64,
}
Pattern: The SyncWorker handles periodic synchronization with a remote peer.
Key Components:
new: Creates a new worker with peer endpoint and intervalrun_once: Performs a single sync cyclerun_forever: Runs continuous sync loop with intervalcycle_count: Tracks sync cyclesExample Implementation:
pub struct SyncWorker {
pub peer_endpoint: String,
pub sync_interval_micros: u64,
pub cycle_count: std::sync::atomic::AtomicU64,
}
impl SyncWorker {
pub fn new(peer_endpoint: &str, sync_interval_micros: u64) -> Self {
Self {
peer_endpoint: peer_endpoint.to_string(),
sync_interval_micros,
cycle_count: std::sync::atomic::AtomicU64::new(0),
}
}
pub fn run_once(&self) -> Result<()> {
self.cycle_count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
Ok(())
}
pub async fn run_forever(&self) -> Result<()> {
loop {
self.run_once()?;
tokio::time::sleep(std::time::Duration::from_micros(self.sync_interval_micros)).await;
}
}
}
Pattern: HTTP endpoints provide the network interface for replication.
Key Components:
handle_sync_request: Processes incoming sync requestshandle_sync_response: Processes incoming sync responsesPOST /api/v1/sync/pull: Pulls changes from remotePOST /api/v1/sync/push: Pushes changes to remoteExample Endpoint:
#[post("/api/v1/sync/pull")]
pub async fn handle_sync_request(
State(state): State<Arc<WabiDbEngine>>,
Json(request): Json<SyncRequest>
) -> Result<Json<SyncResponse>> {
let entries = state.read_commit_index_entries(request.since_commit_seq).await?;
let latest = state.latest_commit_seq().await?;
Ok(Json(SyncResponse {
since_commit_seq: request.since_commit_seq,
entries,
latest_commit_seq: latest,
}))
}
Pattern: The replication protocol uses commit sequence numbers to track synchronization state.
Key Components:
since_commit_seq: Specifies the starting point for synchronizationlatest_commit_seq: Tracks the most recent commitCommitIndexEntry: Contains the actual data to replicateExample Protocol Flow:
Pattern: Comprehensive tests validate the replication system.
Key Test Cases:
Example Test:
#[tokio::test]
async fn apply_sync_response_adds_entries() {
let mut state = vec![sample_entry(1), sample_entry(2)];
let resp = SyncResponse {
since_commit_seq: 2,
entries: vec![sample_entry(3), sample_entry(4)],
latest_commit_seq: 4,
};
apply_sync_response(&mut state, resp).unwrap();
assert_eq!(state.len(), 4);
assert_eq!(state[0].commit_seq, 1);
assert_eq!(state[3].commit_seq, 4);
}
Confirm your understanding by running these commands:
# Run SyncTransport tests
cargo test -p wabidb --test sync_protocol
# Run SyncWorker tests
cargo test -p wabidb --test sync_worker
# Run HTTP endpoint tests
cargo test -p wabidb --test sync_endpoints
These tests should all pass, demonstrating the key aspects of WabiDB's replication system.