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:
+9
-8
@@ -9,12 +9,13 @@ use super::{GitksService, into_status};
|
||||
async fn remote_pack_client(
|
||||
svc: &GitksService,
|
||||
header: Option<&RepositoryHeader>,
|
||||
is_write: bool,
|
||||
) -> Result<Option<PackServiceClient<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 pack rpc");
|
||||
@@ -42,7 +43,7 @@ impl pack_service_server::PackService 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_pack_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, inner.repository.as_ref(), false).await? {
|
||||
return client.advertise_refs(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -69,7 +70,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
let gb = match self.resolve(first.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_pack_client(self, first.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, first.repository.as_ref(), false).await? {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(16);
|
||||
let _ = tx.send(first).await;
|
||||
tokio::spawn(async move {
|
||||
@@ -122,7 +123,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
let gb = match self.resolve(first.repository.as_ref()) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_pack_client(self, first.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, first.repository.as_ref(), false).await? {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(16);
|
||||
let _ = tx.send(first).await;
|
||||
tokio::spawn(async move {
|
||||
@@ -171,7 +172,7 @@ impl pack_service_server::PackService 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_pack_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, inner.repository.as_ref(), false).await? {
|
||||
let resp = client.pack_objects(inner).await?;
|
||||
let stream = super::bridge_server_stream(resp.into_inner());
|
||||
return Ok(tonic::Response::new(stream));
|
||||
@@ -200,7 +201,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
let gb = match self.resolve(inputs.first().and_then(|r| r.repository.as_ref())) {
|
||||
Ok(gb) => gb,
|
||||
Err(err) if err.code() == tonic::Code::NotFound => {
|
||||
if let Some(mut client) = remote_pack_client(self, inputs.first().and_then(|r| r.repository.as_ref())).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, inputs.first().and_then(|r| r.repository.as_ref()), false).await? {
|
||||
return client.index_pack(tokio_stream::iter(inputs)).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -223,7 +224,7 @@ impl pack_service_server::PackService 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_pack_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, inner.repository.as_ref(), false).await? {
|
||||
return client.list_packfiles(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
@@ -246,7 +247,7 @@ impl pack_service_server::PackService 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_pack_client(self, inner.repository.as_ref()).await? {
|
||||
if let Some(mut client) = remote_pack_client(self, inner.repository.as_ref(), false).await? {
|
||||
return client.fsck(inner).await;
|
||||
}
|
||||
return Err(err);
|
||||
|
||||
Reference in New Issue
Block a user