feat(cluster): implement distributed clustering with etcd coordination

- Integrate etcd-client for distributed coordination and leader election
- Add remote client macros with proper formatting for all services
- Implement RequestMetrics for tracking RPC performance and errors
- Add rate limiting mechanism across all service endpoints
- Create ElectionRequest and ElectionResult message types for leader election
- Add role management with primary/replica switching capabilities
- Implement health checker with automatic failover detection
- Add repository count metrics for cluster monitoring
- Update Cargo.toml with etcd-client and dashmap dependencies
- Modify RepoEntry to include read_only flag for replica handling
- Implement should_accept_election logic to prevent duplicate elections
- Add RoleChangedEvent handling for cluster role updates
This commit is contained in:
zhenyi
2026-06-08 14:31:29 +08:00
parent d243dce027
commit 8f472a0443
37 changed files with 4691 additions and 83 deletions
Generated
+24
View File
@@ -457,6 +457,24 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "etcd-client"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ed900ba953ca6bf1fadb75e0c6b73d8463b9e2bb6bdb7b4573e8e7295852fbe"
dependencies = [
"http",
"prost",
"tokio",
"tokio-stream",
"tonic",
"tonic-build",
"tonic-prost",
"tonic-prost-build",
"tower",
"tower-service",
]
[[package]]
name = "faster-hex"
version = "0.10.0"
@@ -668,8 +686,10 @@ name = "gitks"
version = "1.0.0"
dependencies = [
"async-trait",
"dashmap",
"dotenvy",
"duct",
"etcd-client",
"gix",
"gix-archive",
"moka",
@@ -678,6 +698,8 @@ dependencies = [
"ractor",
"ractor_cluster",
"serde",
"serde_json",
"sha2",
"tempfile",
"thiserror",
"tokio",
@@ -2462,6 +2484,7 @@ dependencies = [
"aws-lc-rs",
"log",
"once_cell",
"ring",
"rustls-pki-types",
"rustls-webpki",
"subtle",
@@ -2936,6 +2959,7 @@ dependencies = [
"socket2",
"sync_wrapper",
"tokio",
"tokio-rustls",
"tokio-stream",
"tower",
"tower-layer",