feat: add an API to time out query executions
Currently, if a predicate is hard to match on the Rust side, a sizable query against a very large file can take forever, and ends up hanging. This commit adds an API function `ts_query_cursor_set_timeout_micros` to limit how long query execution is allowed to take, thereby negating the chance of a hang to occur.
This commit is contained in:
parent
a748488596
commit
3f424c0121
11 changed files with 132 additions and 8 deletions
|
|
@ -2362,6 +2362,26 @@ impl QueryCursor {
|
|||
}
|
||||
}
|
||||
|
||||
/// Set the maximum duration in microseconds that query execution should be allowed to
|
||||
/// take before halting.
|
||||
///
|
||||
/// If query execution takes longer than this, it will halt early, returning None.
|
||||
#[doc(alias = "ts_query_cursor_set_timeout_micros")]
|
||||
pub fn set_timeout_micros(&mut self, timeout: u64) {
|
||||
unsafe {
|
||||
ffi::ts_query_cursor_set_timeout_micros(self.ptr.as_ptr(), timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the duration in microseconds that query execution is allowed to take.
|
||||
///
|
||||
/// This is set via [`set_timeout_micros`](QueryCursor::set_timeout_micros).
|
||||
#[doc(alias = "ts_query_cursor_timeout_micros")]
|
||||
#[must_use]
|
||||
pub fn timeout_micros(&self) -> u64 {
|
||||
unsafe { ffi::ts_query_cursor_timeout_micros(self.ptr.as_ptr()) }
|
||||
}
|
||||
|
||||
/// Check if, on its last execution, this cursor exceeded its maximum number
|
||||
/// of in-progress matches.
|
||||
#[doc(alias = "ts_query_cursor_did_exceed_match_limit")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue