Repository navigation
Backport #33919 to 2.0: [Snowflake] Bound the stored-procedure history scan and isolate its failures - #37614
Conversation
… isolate its failures (#33919) * Bound the Snowflake stored-procedure history read and stop a cancelled one failing the run The stored-procedure history statement scanned the whole lookback window with no upper bound, and our own network_timeout default armed the driver's per-statement cancel timer, so a long queryLogDuration died with 000604 and took the whole run down with it, query lineage included. The read is now bounded at both ends and split in half only when Snowflake cancels it, the socket guard moves to socket_timeout, and a read that still fails is reported against the pipeline instead of raising. * Size the stored-procedure overlap to Snowflake's statement timeout ceiling The two-day overlap was Snowflake's default statement timeout, but an account can raise it up to 604800 seconds, so after a split a long CALL near the window boundary could lose the child queries it ran past the overlap. Reaching the hard seven-day ceiling means no CALL on any account can outlive it. * Stop setting a Snowflake client timeout and classify cancels by SQLSTATE only - Drop the `socket_timeout` default: the driver already bounds every request read at 60 seconds, and any `network_timeout` default cancels long statements - Treat an error as a cancel only when the server reports SQLSTATE 57014, so a client error that merely mentions 57014 no longer triggers a split - Derive the window cache size from the split depth instead of a fixed number (cherry picked from commit d389ad6)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved 🟡 Medium riskBounding and recursively retrying Snowflake history scans while removing the client timeout could leave stored-procedure lineage incomplete when retries exhaust. Bounds the Snowflake stored-procedure history scan at both ends, retries cancelled statements over smaller windows, drops the client-side 600-second network timeout, and records failed history reads against the pipeline instead of aborting the run. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Backport of #33919 to 2.0, which fixed #33918.
Cherry-picked from
d389ad69a9dby hand. Every conflict comes from one of twomainchanges that are not on 2.0, and this backport brings in neither of them:mainbefore Fixes #33918: [Snowflake] Bound the stored-procedure history scan and isolate its failures #33919 moved it out of the statement read. On 2.0 the shared mixin keeps its own row handling, moved out of the new read error handler exactly as Fixes #33918: [Snowflake] Bound the stored-procedure history scan and isolate its failures #33919 does onmain. The tests Fixes #32064: [MSSQL] Keep stored-procedure lineage when the engine returns no procedure body #33369 added for its behavior are left out.main. 2.0 passes it unquoted everywhere, so the stored-procedure statement keeps doing the same, and the test for the quoting is left out.Everything else applies unchanged: the two-ended bound on both halves of the history statement, the split on a Snowflake cancel, the failure isolation in the shared mixin, and dropping the default
network_timeoutfrom the connection.The Snowflake, stored-procedure lineage and MSSQL unit tests pass on the branch. The new tests fail against 2.0's code without the fix.
Original description follows.
Snowflake lineage ingestion fails the entire run with
000604 (57014): SQL execution was cancelled by the client due to a timeoutwhen stored-procedure lineage runs over a longqueryLogDuration. Three things combine.The history query is unbounded. The stored-procedure history query reads
ACCOUNT_USAGE.QUERY_HISTORYtwice, joins the two halves by session and time overlap, and sorts the whole join. Each half was bounded only by a start time, so a 365-day lookback scanned a year of history twice in one statement. Both halves are now bounded at both ends, and a statement that Snowflake cancels is retried over the two halves of its window, recursively, a capped number of times and never below a one-day window. Only a cancel is retried, identified by the server's SQLSTATE 57014, which Snowflake reports both for its own statement timeout (000630) and for a client cancel (000604). A permission or compilation error would fail identically on every half, so it is reported once instead. The child-query half reaches seven days past its window, which is Snowflake's hard ceiling onSTATEMENT_TIMEOUT_IN_SECONDS, so aCALLthat starts just before the window closes keeps every query it ran after the boundary on any account. The global sort is gone: nothing downstream depends on the order, since the rows are handed to a thread pool.Our own connect argument cancelled it. #28131 set
network_timeout=600on the Snowflake connection to bound a severed socket, but the driver also armsnetwork_timeoutas a client-side cancel timer on every statement it executes, which made it a hard ten-minute cap on every Snowflake statement. The connection no longer sets any client timeout. A severed socket is still bounded, because the driver applies its own 60-second read timeout to every request whensocket_timeoutis unset. Anyone who wants a statement deadline can still passnetwork_timeoutorsocket_timeoutinconnectionArguments.One failed statement failed the run. The stored-procedure history read had no error handling, so the exception escaped the lineage producer and the step aborted as
Unhandled. Stored-procedure lineage runs before query lineage, so a cancelled history read also cost the run its query lineage. A read that fails and cannot be narrowed is now recorded against the pipeline and skipped, and the rest of the run continues.