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:
Amaan Qureshi 2024-08-29 17:21:52 -04:00
parent a748488596
commit 3f424c0121
11 changed files with 132 additions and 8 deletions

View file

@ -1279,6 +1279,7 @@ class Query {
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF,
timeoutMicros = 0,
} = {},
) {
if (typeof matchLimit !== 'number') {
@ -1298,6 +1299,7 @@ class Query {
endIndex,
matchLimit,
maxStartDepth,
timeoutMicros,
);
const rawCount = getValue(TRANSFER_BUFFER, 'i32');
@ -1342,6 +1344,7 @@ class Query {
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF,
timeoutMicros = 0,
} = {},
) {
if (typeof matchLimit !== 'number') {
@ -1361,6 +1364,7 @@ class Query {
endIndex,
matchLimit,
maxStartDepth,
timeoutMicros,
);
const count = getValue(TRANSFER_BUFFER, 'i32');