From 91733641e5da20c934314be2bc7f27e5fd5e67af Mon Sep 17 00:00:00 2001 From: Gaius Date: Thu, 5 Dec 2024 12:31:53 +0800 Subject: [PATCH] feat: optimize logs for server started Signed-off-by: Gaius --- dragonfly-client/src/grpc/dfdaemon_download.rs | 7 ++++++- dragonfly-client/src/grpc/dfdaemon_upload.rs | 9 +++++++-- dragonfly-client/src/proxy/mod.rs | 5 ++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dragonfly-client/src/grpc/dfdaemon_download.rs b/dragonfly-client/src/grpc/dfdaemon_download.rs index c0570053..a4073075 100644 --- a/dragonfly-client/src/grpc/dfdaemon_download.rs +++ b/dragonfly-client/src/grpc/dfdaemon_download.rs @@ -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"); }); diff --git a/dragonfly-client/src/grpc/dfdaemon_upload.rs b/dragonfly-client/src/grpc/dfdaemon_upload.rs index 179897ee..e559ae04 100644 --- a/dragonfly-client/src/grpc/dfdaemon_upload.rs +++ b/dragonfly-client/src/grpc/dfdaemon_upload.rs @@ -141,6 +141,8 @@ 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() => { @@ -148,11 +150,14 @@ impl DfdaemonUploadServer { } // 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. diff --git a/dragonfly-client/src/proxy/mod.rs b/dragonfly-client/src/proxy/mod.rs index b085e9ac..2dcf6b8a 100644 --- a/dragonfly-client/src/proxy/mod.rs +++ b/dragonfly-client/src/proxy/mod.rs @@ -151,6 +151,8 @@ impl Proxy { pub async fn run(&self, grpc_server_started_barrier: Arc) -> 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() => { @@ -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() => {