Skip to content

Commit

Permalink
log line every power of 10 to avoid spamming
Browse files Browse the repository at this point in the history
  • Loading branch information
somtochiama committed Aug 26, 2024
1 parent 7045a76 commit 8c7d3b7
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions crates/corro-agent/src/agent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ pub async fn handle_changes(
const KEEP_SEEN_CACHE_SIZE: usize = 1000;
let mut seen: IndexMap<_, RangeInclusiveSet<CrsqlSeq>> = 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 {
Expand Down Expand Up @@ -864,10 +865,21 @@ 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
);
}
}
// reset count
if drop_log_count == 100000000 {
drop_log_count = 0;
}
continue;
}

Expand Down Expand Up @@ -1152,3 +1164,11 @@ mod tests {
Ok(())
}
}

#[inline]
fn is_pow_10(i: u64) -> bool {
matches!(
i,
1 | 10 | 100 | 1000 | 10000 | 1000000 | 10000000 | 100000000
)
}

0 comments on commit 8c7d3b7

Please sign in to comment.