MCPcopy Create free account
hub / github.com/PostHog/duckgres / QueryContext

Method QueryContext

server/flightclient/flight_executor.go:170–249  ·  view source on GitHub ↗
(ctx context.Context, query string, args ...any)

Source from the content-addressed store, hash-verified

168 limiter = NewQueryLogLimiter()
169 }
170 ctx, cancel := context.WithCancel(context.Background())
171 e := &FlightExecutor{
172 client: client,
173 sessionToken: sessionToken,
174 ownerEpoch: 0,
175 alloc: memory.DefaultAllocator,
176 ownsClient: false,
177 ctx: ctx,
178 cancel: cancel,
179 queryLogLimiter: limiter,
180 }
181 return e
182}
183
184// MarkDead marks this executor's backing worker as dead. All subsequent RPC
185// calls will return ErrWorkerDead without touching the (possibly closed) gRPC client.
186func (e *FlightExecutor) MarkDead() {
187 e.dead.Store(true)
188}
189
190// IsDead reports whether this executor has been marked dead.
191func (e *FlightExecutor) IsDead() bool {
192 return e.dead.Load()
193}
194
195// withSession adds the session token to the gRPC context.
196func (e *FlightExecutor) withSession(ctx context.Context) context.Context {
197 ctx = metadata.AppendToOutgoingContext(
198 ctx,
199 "x-duckgres-session", e.sessionToken,
200 "x-duckgres-worker-id", strconv.Itoa(e.workerID),
201 "x-duckgres-cp-instance-id", e.cpInstanceID,
202 "x-duckgres-owner-epoch", strconv.FormatInt(e.ownerEpoch, 10),
203 )
204 // Sourced from the context rather than executor state: the executor is
205 // per-session and serves many statements while pgwire reaches it through
206 // the same call.
207 if queryID := wire.QueryIDFromContext(ctx); queryID != "" {
208 ctx = metadata.AppendToOutgoingContext(ctx, wire.QueryIDMetadataKey, queryID)
209 }
210 return ctx
211}
212
213func (e *FlightExecutor) SetOwnerEpoch(ownerEpoch int64) {
214 e.ownerEpoch = ownerEpoch
215}
216
217func (e *FlightExecutor) SetControlMetadata(workerID int, cpInstanceID string, ownerEpoch int64) {
218 e.workerID = workerID
219 e.cpInstanceID = cpInstanceID
220 e.ownerEpoch = ownerEpoch
221}
222
223// recoverClientPanic converts a nil-pointer panic from a closed Flight SQL
224// client into an error. The arrow-go Close() method nils out the embedded
225// FlightServiceClient, so any concurrent RPC on the shared client panics.
226// Only nil-pointer dereferences are recovered; other panics are re-raised
227// to preserve stack traces for unrelated programmer errors.

Callers 2

QueryMethod · 0.95
PingContextMethod · 0.95

Calls 13

mergedContextMethod · 0.95
withSessionMethod · 0.95
releaseQueryHandleMethod · 0.95
waitForSessionIdleMethod · 0.95
IsEmptyQueryFunction · 0.92
recoverClientPanicFunction · 0.85
interpolateArgsFunction · 0.85
ExecuteMethod · 0.65
ErrMethod · 0.65
ReleaseMethod · 0.65
TrailerMethod · 0.45

Tested by

no test coverage detected