node: Handle `fetched` differently if initiated

This commit is contained in:
Alexis Sellier 2023-01-30 13:22:33 +01:00
parent 3aa105afda
commit 498a5c4e4a
No known key found for this signature in database
4 changed files with 48 additions and 41 deletions

View File

@ -512,53 +512,56 @@ where
let remote = result.remote; let remote = result.remote;
let rid = result.rid; let rid = result.rid;
let namespaces = result.namespaces; let namespaces = result.namespaces;
let initiated = result.initiated;
log::debug!( if initiated {
target: "service", log::debug!(
"Fetched {rid} {remote} (error={:?})", result.result.as_ref().err() target: "service",
); "Fetched {rid} {remote} (error={:?})", result.result.as_ref().err()
);
let result = match result.result { let result = match result.result {
Ok(updated) => { Ok(updated) => {
self.reactor.event(Event::RefsFetched { self.reactor.event(Event::RefsFetched {
remote, remote,
rid, rid,
updated: updated.clone(), updated: updated.clone(),
}); });
Ok(updated) Ok(updated)
}
Err(err) => {
error!(target: "service", "Fetch failed for {rid} from {remote}: {err}");
if let FetchError::Io(_) = err {
self.reactor
.disconnect(result.remote, DisconnectReason::Fetch(err));
return;
} else {
Err(err)
} }
} Err(err) => {
}; error!(target: "service", "Fetch failed for {rid} from {remote}: {err}");
if let Some(results) = self.fetch_reqs.get(&rid) { if let FetchError::Io(_) = err {
log::debug!(target: "service", "Found existing fetch request, sending result.."); self.reactor
.disconnect(result.remote, DisconnectReason::Fetch(err));
return;
} else {
Err(err)
}
}
};
if results if let Some(results) = self.fetch_reqs.get(&rid) {
.send(FetchResult { log::debug!(target: "service", "Found existing fetch request, sending result..");
rid,
remote, if results
namespaces, .send(FetchResult {
result, rid,
}) initiated,
.is_err() remote,
{ namespaces,
log::error!(target: "service", "Error sending fetch result for {rid}.."); result,
self.fetch_reqs.remove(&rid); })
.is_err()
{
log::error!(target: "service", "Error sending fetch result for {rid}..");
self.fetch_reqs.remove(&rid);
} else {
log::debug!(target: "service", "Sent fetch result for {rid}..");
}
} else { } else {
log::debug!(target: "service", "Sent fetch result for {rid}.."); log::debug!(target: "service", "No fetch requests found for {rid}..");
} }
} else {
log::debug!(target: "service", "No fetch requests found for {rid}..");
} }
if let Some(session) = self.sessions.get_mut(&remote) { if let Some(session) = self.sessions.get_mut(&remote) {

View File

@ -621,6 +621,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
remote: fetch.remote, remote: fetch.remote,
input: Input::Fetched(Arc::new(FetchResult { input: Input::Fetched(Arc::new(FetchResult {
rid: fetch.repo, rid: fetch.repo,
initiated: fetch.initiated,
remote: fetch.remote, remote: fetch.remote,
namespaces: fetch.namespaces, namespaces: fetch.namespaces,
result: Err(FetchError::Io(io::ErrorKind::Other.into())), result: Err(FetchError::Io(io::ErrorKind::Other.into())),
@ -635,6 +636,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
remote: fetch.remote, remote: fetch.remote,
input: Input::Fetched(Arc::new(FetchResult { input: Input::Fetched(Arc::new(FetchResult {
rid: fetch.repo, rid: fetch.repo,
initiated: fetch.initiated,
remote: fetch.remote, remote: fetch.remote,
namespaces: fetch.namespaces, namespaces: fetch.namespaces,
result: Ok(vec![]), result: Ok(vec![]),

View File

@ -81,6 +81,7 @@ impl<G: Signer + EcSign + 'static> Worker<G> {
rid: fetch.repo, rid: fetch.repo,
remote: fetch.remote, remote: fetch.remote,
namespaces: fetch.namespaces, namespaces: fetch.namespaces,
initiated: fetch.initiated,
result, result,
}; };
log::debug!(target: "worker", "Sending response back to service.."); log::debug!(target: "worker", "Sending response back to service..");

View File

@ -61,6 +61,7 @@ impl From<net::SocketAddr> for Address {
pub struct FetchResult { pub struct FetchResult {
pub rid: Id, pub rid: Id,
pub remote: NodeId, pub remote: NodeId,
pub initiated: bool,
pub namespaces: Namespaces, pub namespaces: Namespaces,
pub result: Result<Vec<RefUpdate>, FetchError>, pub result: Result<Vec<RefUpdate>, FetchError>,
} }