Skip to content

Commit

Permalink
enable only if debug assertions
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Nov 28, 2022
1 parent b1ddf6d commit c2c3795
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/frontend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::{Arc, Mutex};
// use tokio::sync::Mutex;
use std::time::Duration;

use futures::pin_mut;
use parking_lot::{RwLock, RwLockReadGuard};
use pgwire::pg_field_descriptor::PgFieldDescriptor;
use pgwire::pg_response::PgResponse;
Expand Down Expand Up @@ -784,22 +785,27 @@ impl Session<PgResponseStream> for SessionImpl {
}
let stmt = stmts.swap_remove(0);
let rsp = {
// Report the SQL in the log periodically if the query is slow.
const SLOW_QUERY_LOG_PERIOD: Duration = Duration::from_secs(60);
let mut ticker = tokio::time::interval(SLOW_QUERY_LOG_PERIOD);
ticker.reset();
let mut handle_fut = Box::pin(handle(self, stmt, sql, format));
loop {
tokio::select! {
_ = ticker.tick() => {
tracing::warn!(sql, "slow query has been running for another {SLOW_QUERY_LOG_PERIOD:?}");
}
result = &mut handle_fut => {
break result;
let handle_fut = handle(self, stmt, sql, format);
if cfg!(debug_assertions) {
// Report the SQL in the log periodically if the query is slow.
const SLOW_QUERY_LOG_PERIOD: Duration = Duration::from_secs(60);
let mut ticker = tokio::time::interval(SLOW_QUERY_LOG_PERIOD);
ticker.reset();
pin_mut!(handle_fut);
loop {
tokio::select! {
_ = ticker.tick() => {
tracing::warn!(sql, "slow query has been running for another {SLOW_QUERY_LOG_PERIOD:?}");
}
result = &mut handle_fut => {
break result;
}
}
}
} else {
handle_fut.await
}
}
}
.inspect_err(|e| tracing::error!("failed to handle sql:\n{}:\n{}", sql, e))?;
Ok(rsp)
}
Expand Down

0 comments on commit c2c3795

Please sign in to comment.