Skip to content

Commit

Permalink
feat: optimize logs for server started
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Dec 5, 2024
1 parent 4b682b9 commit 9173364
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion dragonfly-client/src/grpc/dfdaemon_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,21 @@ impl DfdaemonDownloadServer {
.add_service(health_service)
.add_service(self.service.clone())
.serve_with_incoming_shutdown(uds_stream, async move {
// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Notify the download grpc server is started.
_ = grpc_server_started_barrier.wait() => {
info!("proxy download server is ready to start");
info!("download server is ready to start");
}
// Wait for shutdown signal.
_ = shutdown.recv() => {
info!("download grpc server stop to wait");
}
}

// Wait for the shutdown signal to shutdown the upload grpc server,
// when server is started.
let _ = shutdown.recv().await;
info!("download grpc server shutting down");
});
Expand Down
9 changes: 7 additions & 2 deletions dragonfly-client/src/grpc/dfdaemon_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,23 @@ impl DfdaemonUploadServer {
.add_service(health_service)
.add_service(self.service.clone())
.serve_with_shutdown(self.addr, async move {
// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Notify the upload grpc server is started.
_ = grpc_server_started_barrier.wait() => {
info!("upload server is ready");
}
// Wait for shutdown signal.
_ = shutdown.recv() => {
info!("download grpc server stop to wait");
info!("upload grpc server stop to wait");
}
}

// Wait for the shutdown signal to shutdown the upload grpc server,
// when server is started.
let _ = shutdown.recv().await;
info!("download grpc server shutting down");
info!("upload grpc server shutting down");
});

// Wait for the upload grpc server to shutdown.
Expand Down
5 changes: 2 additions & 3 deletions dragonfly-client/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ impl Proxy {
pub async fn run(&self, grpc_server_started_barrier: Arc<Barrier>) -> ClientResult<()> {
let mut shutdown = self.shutdown.clone();

// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Wait for starting the proxy server
_ = grpc_server_started_barrier.wait() => {
Expand All @@ -171,9 +173,6 @@ impl Proxy {
info!("proxy server listening on {}", self.addr);

loop {
// Clone the shutdown channel.
let mut shutdown = self.shutdown.clone();

// Wait for a client connection.
tokio::select! {
tcp_accepted = listener.accept() => {
Expand Down

0 comments on commit 9173364

Please sign in to comment.