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
This commit is contained in:
+10
-6
@@ -6,12 +6,13 @@ use super::{GitksService, into_status};
|
||||
async fn remote_merge_client(
|
||||
svc: &GitksService,
|
||||
header: Option<&RepositoryHeader>,
|
||||
is_write: bool,
|
||||
) -> Result<Option<MergeServiceClient<tonic::transport::Channel>>, tonic::Status> {
|
||||
let header = match header {
|
||||
Some(h) => h,
|
||||
None => return Ok(None),
|
||||
};
|
||||
let Some(route) = svc.route_repository(header).await? else {
|
||||
let Some(route) = svc.route_repository(header, is_write).await? else {
|
||||
return Ok(None);
|
||||
};
|
||||
tracing::info!(storage_name = %route.storage_name, relative_path = %route.relative_path, actor_name = %route.actor_name, grpc_addr = %route.grpc_addr, "forwarding merge rpc");
|
||||
@@ -35,7 +36,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
let gb = match self.resolve(inner.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref(), false).await? {
|
||||
return client.check_merge(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -59,7 +60,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
let gb = match self.resolve(inner.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref(), true).await? {
|
||||
return client.merge(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -68,6 +69,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
};
|
||||
let resp = gb.merge(inner).map_err(into_status)?;
|
||||
tracing::info!(%repo, %target, status = resp.status, "merge done");
|
||||
self.notify_ref_update(&repo, &format!("refs/heads/{}", target), "", "");
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
let gb = match self.resolve(inner.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref(), false).await? {
|
||||
return client.list_merge_conflicts(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -106,7 +108,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
let gb = match self.resolve(inner.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref(), true).await? {
|
||||
return client.resolve_merge_conflicts(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -115,6 +117,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
};
|
||||
let resp = gb.resolve_merge_conflicts(inner).map_err(into_status)?;
|
||||
tracing::info!(%repo, %target, status = resp.status, "merge conflicts resolved");
|
||||
self.notify_ref_update(&repo, &format!("refs/heads/{}", target), "", "");
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
|
||||
@@ -130,7 +133,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
let gb = match self.resolve(inner.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_merge_client(self, inner.repository.as_ref(), true).await? {
|
||||
return client.rebase(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -139,6 +142,7 @@ impl merge_service_server::MergeService for GitksService {
|
||||
};
|
||||
let resp = gb.rebase(inner).map_err(into_status)?;
|
||||
tracing::info!(%repo, %branch, status = resp.status, "rebase done");
|
||||
self.notify_ref_update(&repo, &format!("refs/heads/{}", branch), "", "");
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user