Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions crates/fctl-agent/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ pub async fn accept_loop(listener: UnixListener, events: mpsc::UnboundedSender<L
};
next_id += 1;
let id = next_id;
// Announced here, in the order they connect, so the newest
// connection is the one that stays current.
let (tx, mut rx) = mpsc::unbounded_channel::<String>();
if events.send(LinkEvent::Connected(id, tx)).is_err() {
return;
}
let events = events.clone();
tokio::spawn(async move {
let (read, mut write) = stream.into_split();
let (tx, mut rx) = mpsc::unbounded_channel::<String>();
if events.send(LinkEvent::Connected(id, tx)).is_err() {
return;
}
let writer = tokio::spawn(async move {
while let Some(mut line) = rx.recv().await {
line.push('\n');
Expand Down
16 changes: 16 additions & 0 deletions crates/fctl-agent/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,22 @@ impl Supervisor {
async fn on_link(&mut self, e: LinkEvent) {
match e {
LinkEvent::Connected(id, tx) => {
let (seq, acked) = (self.journal.last_seq(), self.journal.acked());
match self.host.as_ref() {
Some((old, _)) => tracing::info!(
"host link {id} replaces link {old}; journal at agent_seq {seq}, {acked} acknowledged"
),
None => tracing::info!(
"host link {id} attached; journal at agent_seq {seq}, {acked} acknowledged"
),
}
self.host = Some((id, tx));
let hello = self.hello();
self.send(&hello);
}
LinkEvent::Disconnected(id) => {
if self.host.as_ref().is_some_and(|(cur, _)| *cur == id) {
tracing::info!("host link {id} detached");
self.host = None;
}
}
Expand Down Expand Up @@ -267,6 +277,12 @@ impl Supervisor {
self.outbox.clear();
match self.journal.read_after(after_agent_seq) {
Ok(events) => {
if let Some((id, _)) = &self.host {
tracing::info!(
"replaying {} events after agent_seq {after_agent_seq} to host link {id}",
events.len()
);
}
for chunk in events.chunks(100) {
self.send(&AgentToHost::Events {
events: chunk.to_vec(),
Expand Down
Loading