-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend): support idle in transaction session timeout #14566
Changes from 1 commit
9f18c51
19f4b9f
8a74663
0d39532
8a28391
5eabe82
4f75d1c
dcacd31
3a0edd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
statement ok | ||
set idle_in_transaction_session_timeout = 1000 | ||
|
||
statement ok | ||
begin read only; | ||
|
||
statement ok | ||
select 1; | ||
|
||
# wait enough time to trigger idle_in_transaction_session_timeout | ||
sleep 2s | ||
|
||
statement error | ||
select 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use std::sync::Arc; | |
use std::time::Instant; | ||
|
||
use bytes::Bytes; | ||
use parking_lot::Mutex; | ||
use risingwave_common::types::DataType; | ||
use risingwave_sqlparser::ast::Statement; | ||
use thiserror_ext::AsReport; | ||
|
@@ -112,6 +113,8 @@ pub trait Session: Send + Sync { | |
fn transaction_status(&self) -> TransactionStatus; | ||
|
||
fn init_exec_context(&self, sql: Arc<str>) -> ExecContextGuard; | ||
|
||
fn check_idle_in_transaction_timeout(&self) -> bool; | ||
} | ||
|
||
/// Each session could run different SQLs multiple times. | ||
|
@@ -120,6 +123,8 @@ pub struct ExecContext { | |
pub running_sql: Arc<str>, | ||
/// The instant of the running sql | ||
pub last_instant: Instant, | ||
/// A reference used to update when `ExecContext` is dropped | ||
pub last_idle_instant: Arc<Mutex<Option<Instant>>>, | ||
} | ||
|
||
/// `ExecContextGuard` holds a `Arc` pointer. Once `ExecContextGuard` is dropped, | ||
|
@@ -132,6 +137,12 @@ impl ExecContextGuard { | |
} | ||
} | ||
|
||
impl Drop for ExecContext { | ||
fn drop(&mut self) { | ||
*self.last_idle_instant.lock() = Some(Instant::now()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
According to the postgresql docs, this variable doesn't care about how long a statement is running, which should be handled by parameters like statement timeout There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From PG's documents:
IIUC, that means a running batch query should not be killed. Do we behave at the same way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we won't kill any query, but unpin the snapshot (either by background monitor or session termination triggered by a later statement). The session would be terminated when the later statement arrives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By "killed" I mean any means that cause the query to end. When a snapshot is unpinned, it's possible that the (running) iterator runs into errors and terminates, is it the cases? If so, I was saying that we should avoid such thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just ensure there is no running SQL in the current session during calling |
||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum UserAuthenticator { | ||
// No need to authenticate. | ||
|
@@ -362,9 +373,14 @@ mod tests { | |
let exec_context = Arc::new(ExecContext { | ||
running_sql: sql, | ||
last_instant: Instant::now(), | ||
last_idle_instant: Default::default(), | ||
}); | ||
ExecContextGuard::new(exec_context) | ||
} | ||
|
||
fn check_idle_in_transaction_timeout(&self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
async fn do_test_query(bind_addr: impl Into<String>, pg_config: impl Into<String>) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a new error variant? I believe the handling logic can be quite similar to handling
Panic
here.risingwave/src/utils/pgwire/src/pg_protocol.rs
Lines 350 to 360 in 240416f