gRPC: send regular ping

The idea was that slot updates would be really frequent and serve as a
ping. But during node startup there can be a long phase of no data.
This commit is contained in:
Christian Kamm 2021-11-01 15:51:05 +01:00
parent 6bb288e6b1
commit eab62d0599
3 changed files with 18 additions and 2 deletions

View File

@ -2,7 +2,7 @@ use {
crate::accounts_selector::AccountsSelector,
accountsdb_proto::{
slot_update::Status as SlotUpdateStatus, update::UpdateOneof, AccountWrite, SlotUpdate,
SubscribeRequest, Update,
SubscribeRequest, Update, Ping,
},
bs58,
futures_util::FutureExt,
@ -155,6 +155,16 @@ impl AccountsDbPlugin for AccountsDbPluginGrpc {
.add_service(server)
.serve_with_shutdown(addr, exit_receiver.map(drop)),
);
let sender_c = self.server_broadcast.as_ref().unwrap().clone();
rt.spawn(async move {
loop {
// Don't care about the error if there are no receivers.
let _ = sender_c.send(Update {
update_oneof: Some(UpdateOneof::Ping(Ping{})),
});
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
}
});
self.runtime = Some(rt);
Ok(())
@ -168,6 +178,8 @@ impl AccountsDbPlugin for AccountsDbPluginGrpc {
.send(())
.expect("sending grpc server termination should succeed");
}
// TODO: explicitly shut down runtime?
}
fn update_account(

View File

@ -663,7 +663,8 @@ async fn main() {
status: "bla".into(),
})
.unwrap();
}
},
accountsdb_proto::update::UpdateOneof::Ping(_) => {},
}
}

View File

@ -17,6 +17,7 @@ message Update {
oneof update_oneof {
AccountWrite account_write = 1;
SlotUpdate slot_update = 2;
Ping ping = 3;
}
}
@ -43,3 +44,5 @@ message SlotUpdate {
Status status = 3;
}
message Ping {
}