Files
gitks/main.rs
T
zhenyi 8c95eb230d refactor(actor): implement replica sync and ref update notification system
- Add is_write parameter to remote clients for read/write routing distinction
- Introduce RepoEntry struct with role tracking (primary/replica) for repositories
- Replace HashSet with HashMap for repository storage with role metadata
- Add ROLE_PRIMARY and ROLE_REPLICA constants for node role identification
- Implement FindPrimary and FindReplica RPC methods for role-based routing
- Add RefUpdateEvent message type for propagating reference updates
- Create sync module with BundleApplicator for handling replica synchronization
- Implement notify_ref_update calls after branch/tag/commit operations
- Add broadcast_ref_update function to propagate events across cluster nodes
- Modify route_repository to prioritize primary for writes and replicas for reads
- Update actor message handling to support role-based repository discovery
- Implement sync_from_primary function using pack protocol for incremental updates
2026-06-08 01:54:08 +08:00

61 lines
2.0 KiB
Rust

use std::path::PathBuf;
use gitks::actor::init_actor_cluster;
use gitks::server::{serve, GitksService};
const DEFAULT_HOST: &str = "0.0.0.0";
const DEFAULT_PORT: &str = "50051";
const DEFAULT_STORAGE_NAME: &str = "default";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
tracing_subscriber::fmt().init();
tracing::info!(
version = env!("CARGO_PKG_VERSION"),
"gitks starting up"
);
let host = std::env::var("GITKS_HOST").unwrap_or_else(|_| DEFAULT_HOST.into());
let port = std::env::var("GITKS_PORT").unwrap_or_else(|_| DEFAULT_PORT.into());
let storage_name = std::env::var("STORAGE_NAME").unwrap_or_else(|_| DEFAULT_STORAGE_NAME.into());
let grpc_addr = std::env::var("GITKS_ADVERTISE_ADDR")
.unwrap_or_else(|_| format!("http://{host}:{port}"));
let repo_prefix = std::env::var("REPO_PREFIX_PATH")
.map_err(|_| "REPO_PREFIX_PATH environment variable is required (e.g. /data/repos)")?;
let repo_prefix = PathBuf::from(&repo_prefix);
if !repo_prefix.is_absolute() {
return Err("REPO_PREFIX_PATH must be an absolute path".into());
}
if !repo_prefix.exists() {
tracing::info!(path = %repo_prefix.display(), "creating repo prefix directory");
std::fs::create_dir_all(&repo_prefix)?;
}
let addr: std::net::SocketAddr = format!("{host}:{port}").parse()?;
let actor_svc = GitksService::new(repo_prefix.clone());
let (node_actor, node_handle) = init_actor_cluster(
actor_svc,
storage_name.clone(),
grpc_addr.clone(),
).await?;
let svc = GitksService::new(repo_prefix.clone())
.with_actor(node_actor.clone())
.with_grpc_addr(grpc_addr.clone());
tracing::info!(
"starting gitks gRPC server on {addr}, repo prefix: {}, storage: {storage_name}, advertise: {grpc_addr}",
repo_prefix.display()
);
serve(addr, svc).await?;
node_actor.stop(None);
node_handle.await?;
tracing::info!("gitks shut down");
Ok(())
}