From 1e029a18266f9319c898bdd259ad430581a642b8 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 21 Jul 2024 11:50:08 +0100 Subject: [PATCH] Reduce logging in SFTP wormfile implementation Signed-off-by: Olivier --- yama_wormfile_sftp/src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/yama_wormfile_sftp/src/lib.rs b/yama_wormfile_sftp/src/lib.rs index 5423f02..e80c199 100644 --- a/yama_wormfile_sftp/src/lib.rs +++ b/yama_wormfile_sftp/src/lib.rs @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; -use std::time::Duration; +use std::time::{Duration, Instant}; use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite, AsyncWriteExt, ReadBuf}; use tokio_stream::StreamExt; use tracing::debug; @@ -465,10 +465,10 @@ impl AsyncWrite for SftpWormWriter { impl WormFileWriter for SftpWormWriter { #[async_backtrace::framed] async fn finalise(&mut self, target_path: &WormPath, replace: bool) -> io::Result<()> { - debug!("finalising SFTP file to {target_path:?}"); + let flush_start = Instant::now(); self.flush().await?; - debug!("flushed SFTP file to {target_path:?}"); + let mkdirs_start = Instant::now(); let SftpWormWriter { temp_path, file, @@ -492,7 +492,6 @@ impl WormFileWriter for SftpWormWriter { .await .map_err(|e| io::Error::new(ErrorKind::Other, e.to_string()))?; } - debug!("created dirs SFTP file to {target_path:?}"); // Avoid allowing a replacement if not intended. // But this is currently not atomic, so it's just a sanity check rather than a foolproof // safeguard! @@ -513,12 +512,19 @@ impl WormFileWriter for SftpWormWriter { } } - debug!("moving SFTP file to {target_path:?}"); + let move_start = Instant::now(); // Perform the move. fs.rename(&temp_path.as_ref().as_str(), target_path.as_str()) .await .map_err(|e| io::Error::new(ErrorKind::Other, e))?; - debug!("moved SFTP file to {target_path:?}"); + + let end = Instant::now(); + debug!( + "Saved SFTP file to {target_path:?} (flush={:?}, mkdirs={:?}, move={:?})", + mkdirs_start - flush_start, + move_start - mkdirs_start, + end - move_start + ); Ok(()) } }