(ctx context.Context, query string, args ...any)
| 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. |
| 186 | func (e *FlightExecutor) MarkDead() { |
| 187 | e.dead.Store(true) |
| 188 | } |
| 189 | |
| 190 | // IsDead reports whether this executor has been marked dead. |
| 191 | func (e *FlightExecutor) IsDead() bool { |
| 192 | return e.dead.Load() |
| 193 | } |
| 194 | |
| 195 | // withSession adds the session token to the gRPC context. |
| 196 | func (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 | |
| 213 | func (e *FlightExecutor) SetOwnerEpoch(ownerEpoch int64) { |
| 214 | e.ownerEpoch = ownerEpoch |
| 215 | } |
| 216 | |
| 217 | func (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. |
no test coverage detected