Commit b227e3a
feat: auto-recover Reyden Thrift connections onto the kernel backend (#523)
* feat: auto-recover Reyden Thrift connections onto the kernel backend
An unconfigured connection to a Reyden / Real-Time SQL warehouse defaults to
the Thrift backend, which the SQL Gateway proxy rejects with SQLSTATE KP001.
Detect that rejection (StatusError.sqlState === "KP001") in
ThriftBackend.openSession and transparently re-open the session on the
KernelBackend (SEA), remembering the warehouse in a process-wide cache keyed
by (host, warehouse_id) with a ~6h TTL so later connects skip the doomed
Thrift attempt. Only the default path auto-recovers; an explicit backend
choice (routed upstream in the client) is unaffected. On a double failure the
kernel error is surfaced with the original Thrift rejection preserved as its
cause.
Also re-throw the original error unchanged on the non-recovery paths:
StatusError implements Error but does not extend it, so the previous
`error instanceof Error ? error : new Error(String(error))` normalization
wrapped every StatusError into Error("[object Object]"), losing its sqlState
and the double-failure cause.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Address review: close fallback KernelBackend, test TTL expiry
- ThriftBackend: track the KernelBackend(s) created for Reyden (KP001) fallback
and close them in close(), so the process-global log-bridge onLevelChange
listener installed by connect() is released instead of leaking on every
recovery. Add a createKernelBackend() seam so tests can inject a fake without
the native binding, plus a test that close() releases the fallback backend.
- ReydenWarehouseCache test: add a TTL-expiry test (sinon fake timers) covering
the 6h boundary and opportunistic eviction on access.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Address review: reuse one fallback KernelBackend, guard cause overwrite
- ThriftBackend: reuse a single fallback KernelBackend across all Reyden (KP001)
fallback sessions on the connection instead of constructing one per openSession.
connectionOptions are fixed after connect, so it is created + connected once
(lazily, memoized; the attempt is cleared on connect failure so a later open can
retry) and released in close() — this stops per-session accumulation of backends
and process-global log-bridge listeners.
- On the double-failure path, only set the kernel error's `cause` when it is absent,
so a cause the kernel error may already carry is not clobbered.
- Test now opens two fallback sessions and asserts a single KernelBackend is created
and connected once, reused for both, and closed once on close().
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Sweep expired entries from the Reyden warehouse cache on mark
markReyden only added the new entry, so the per-key lazy eviction in
isKnownReyden never reclaimed an entry that was marked and then never
looked up again — it would persist for the life of the process. Sweep
expired entries when marking a warehouse; markReyden runs only on an
actual Thrift rejection, so the sweep is near-free and bounds the cache
to warehouses seen within the TTL window. Adds a fake-timer test.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Close a fallback KernelBackend whose connect races close()
close() released the fallback backend only via this.fallbackKernelBackend,
which getFallbackKernelBackend assigns after connect() resolves. A close()
that ran while a fallback connect was still in flight found the field unset
and skipped it; the pending connect then resolved, installed the process-
global log-bridge listener, and assigned the field on a backend nobody would
ever close — leaking that listener for the process lifetime.
Await the in-flight connect promise in close() instead of only the resolved
field, closing whatever it produces (whether already connected or still in
flight). Adds a test that calls close() during an unresolved fallback connect.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Drop the write-only fallbackKernelBackend field
After close() switched to awaiting the in-flight connect, the
fallbackKernelBackend field became write-only: assigned in the connect
IIFE and cleared in close(), but read nowhere. It also left a confusing
stale write — a close() racing an in-flight connect nulled the field
before the IIFE re-assigned it onto an already-closed backend.
Remove the field; the fallbackKernelBackendConnect promise (whose
resolved value is the backend) is the single source of truth.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
* Make the Reyden cache presence-based, dropping the dead tri-state
markReyden was the only writer and only ever stored isReyden: true, so the
CacheEntry.isReyden field and isKnownReyden's boolean | undefined return type
carried an unreachable "known not Reyden" state. Drop the field and return a
plain boolean: an unexpired entry means Reyden, its absence means not known.
Callers already used the result in a boolean context. Update the tests that
asserted the old undefined return to expect false.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
---------
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>1 parent 28694bc commit b227e3a
5 files changed
Lines changed: 631 additions & 3 deletions
File tree
- lib
- errors
- thrift-backend
- tests/unit/thrift-backend
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
34 | 48 | | |
35 | 49 | | |
36 | 50 | | |
37 | 51 | | |
38 | 52 | | |
39 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
40 | 76 | | |
41 | 77 | | |
42 | 78 | | |
| |||
60 | 96 | | |
61 | 97 | | |
62 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
63 | 156 | | |
64 | 157 | | |
65 | 158 | | |
| |||
93 | 186 | | |
94 | 187 | | |
95 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
96 | 227 | | |
97 | | - | |
| 228 | + | |
| 229 | + | |
98 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
99 | 242 | | |
100 | 243 | | |
0 commit comments