From c9c2f3db7350ca38114a8c884162d894698dfd6c Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Wed, 21 Aug 2024 22:31:51 +0100 Subject: [PATCH] log line every power of 10 to avoid spamming --- crates/corro-agent/src/agent/handlers.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/corro-agent/src/agent/handlers.rs b/crates/corro-agent/src/agent/handlers.rs index fc64e08f..bb7ec0ba 100644 --- a/crates/corro-agent/src/agent/handlers.rs +++ b/crates/corro-agent/src/agent/handlers.rs @@ -724,6 +724,7 @@ pub async fn handle_changes( const KEEP_SEEN_CACHE_SIZE: usize = 1000; let mut seen: IndexMap<_, RangeInclusiveSet> = IndexMap::new(); + let mut drop_log_count: u64 = 0; // complicated loop to process changes efficiently w/ a max concurrency // and a minimum chunk size for bigger and faster SQLite transactions loop { @@ -841,10 +842,17 @@ pub async fn handle_changes( // drop items when the queue is full. if queue.len() > max_queue_len { - warn!( - "dropping changes from {} because changes queue is full", - change.actor_id - ); + drop_log_count += 1; + if is_pow_10(drop_log_count) { + if drop_log_count == 1 { + warn!("dropping a change because changes queue is full"); + } else { + warn!( + "dropping {} changes because changes queue is full", + drop_log_count + ); + } + } continue; } @@ -1124,3 +1132,11 @@ mod tests { Ok(()) } } + +#[inline] +fn is_pow_10(i: u64) -> bool { + matches!( + i, + 1 | 10 | 100 | 1000 | 10000 | 1000000 | 10000000 | 100000000 + ) +}