From 19ec89593da07b4e69d6f217a7bebf202dc2a280 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Tue, 27 Dec 2022 15:24:10 -0600 Subject: [PATCH] improvement: drop queries that are running during a checkpoint --- src/db.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/db.rs b/src/db.rs index 8f9ba56..5106880 100644 --- a/src/db.rs +++ b/src/db.rs @@ -828,6 +828,17 @@ pub async fn db_query( sub, client_id, sub.id ); } + // check if a checkpoint is trying to run, and abort + if row_count % 100 == 0 { + { + if let Err(_) = safe_to_read.try_lock() { + // lock was held, abort this query + debug!("query aborted due to checkpoint (cid: {}, sub: {:?})", client_id, sub.id); + return Ok(()); + } + } + } + // check if this is still active; every 100 rows if row_count % 100 == 0 && abandon_query_rx.try_recv().is_ok() { debug!("query aborted (cid: {}, sub: {:?})", client_id, sub.id); @@ -849,6 +860,12 @@ pub async fn db_query( let ok: Result<()> = Ok(()); return ok; } + // check if a checkpoint is trying to run, and abort + if let Err(_) = safe_to_read.try_lock() { + // lock was held, abort this query + debug!("query aborted due to checkpoint (cid: {}, sub: {:?})", client_id, sub.id); + return Ok(()); + } // give the queue a chance to clear before trying again thread::sleep(Duration::from_millis(100)); }