feat(cluster): implement Raft consensus with tracing and HTTP support

- Add Raft log and snapshot mechanisms for distributed consensus
- Integrate hyper HTTP server and client libraries for network communication
- Enhance tracing capabilities with structured logging and spans
- Add dependency tracking for new consensus-related crates
- Implement snapshot storage with serialization and persistence
- Add remote repository synchronization via Raft commands
- Include comprehensive tracing instrumentation across services
This commit is contained in:
zhenyi
2026-06-10 18:33:42 +08:00
parent 0207cde234
commit c32a7cad2f
10 changed files with 453 additions and 6 deletions
+50
View File
@@ -355,3 +355,53 @@ fn update_local_ref(repo_path: &Path, ref_name: &str, new_oid: &str) {
Err(e) => tracing::error!(ref_name = %ref_name, error = %e, "update-ref spawn failed"),
}
}
/// Apply a committed Raft command to the local git repository.
/// This is called on followers when they receive committed entries from the leader.
pub fn apply_raft_command_to_repo(
repo_prefix: &Path,
command: &crate::actor::raft_log::Command,
) {
match command {
crate::actor::raft_log::Command::RefUpdate {
relative_path,
ref_name,
old_oid: _,
new_oid,
} => {
let repo_path = repo_prefix.join(relative_path);
tracing::info!(
relative_path = %relative_path,
ref_name = %ref_name,
new_oid = %new_oid,
"applying RefUpdate from Raft log to local repo"
);
update_local_ref(&repo_path, ref_name, new_oid);
}
crate::actor::raft_log::Command::RegisterRepo {
relative_path,
storage_name: _,
} => {
tracing::info!(
relative_path = %relative_path,
"RegisterRepo from Raft log (no git action needed)"
);
}
crate::actor::raft_log::Command::RemoveRepo { relative_path } => {
tracing::info!(
relative_path = %relative_path,
"RemoveRepo from Raft log (no git action needed)"
);
}
crate::actor::raft_log::Command::SetPrimary {
storage_name,
relative_paths,
} => {
tracing::info!(
storage_name = %storage_name,
paths = relative_paths.len(),
"SetPrimary from Raft log (no git action needed)"
);
}
}
}