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

Method startDisconnectMonitor

server/conn.go:375–422  ·  view source on GitHub ↗

startDisconnectMonitor starts a goroutine that polls the client connection for disconnects using bufio.Reader.Peek. During query execution the message loop is blocked on the executor, so nobody else touches the bufio.Reader, making concurrent Peek calls safe. When the client sends a TCP FIN or RST,

(ctx context.Context)

Source from the content-addressed store, hash-verified

373 physicalCatalog := c.physicalCatalog
374 switch {
375 case physicalCatalog == physicalDuckLakeCatalog:
376 backend = transpiler.BackendDuckLake
377 case c.server.cfg.DuckLake.MetadataStore != "" || c.server.cfg.AlwaysDuckLake:
378 backend = transpiler.BackendDuckLake
379 physicalCatalog = physicalDuckLakeCatalog
380 }
381
382 logicalDatabaseName := ""
383 if backend == transpiler.BackendDuckLake {
384 logicalDatabaseName = c.database
385 }
386
387 return transpiler.New(transpiler.Config{
388 Backend: backend,
389 LogicalDatabaseName: logicalDatabaseName,
390 PhysicalCatalogName: physicalCatalog,
391 ConvertPlaceholders: convertPlaceholders,
392 })
393}
394
395// querySourceGUCName is the fully-qualified name of the duckgres-namespaced
396// session GUC, used as the SHOW result column label.
397const querySourceGUCName = "duckgres.query_source"
398
399// defaultQuerySource is the value reported for `duckgres.query_source` when the
400// session GUC has not been set. Downstream (pull-based compute billing) treats a
401// missing query_source as this bucket.
402const defaultQuerySource = "standard"
403
404// QuerySource returns the current value of the `duckgres.query_source` session
405// GUC, or defaultQuerySource ("standard") if it was never set / set to empty.
406// This never errors on a missing value: an unset GUC is defined to mean
407// "standard". It is the accessor a future compute meter reads to bucket usage.
408func (c *clientConn) QuerySource() string {
409 if c.querySource == "" {
410 return defaultQuerySource
411 }
412 return c.querySource
413}
414
415// setQuerySource records a client-supplied `duckgres.query_source` value on the
416// session. Callers must pass an already-validated canonical value ("standard",
417// "endpoints", or "" = reset to default): the transpiler validates SET
418// statements (transform.NormalizeQuerySource, rejecting anything else with
419// 22023 before this is reached) and applyStartupQuerySource validates the
420// startup option. The setter itself stays dumb; ConnectionBilling additionally
421// clamps at the metering boundary as defense in depth.
422func (c *clientConn) setQuerySource(value string) {
423 c.querySource = value
424}
425

Callers 1

queryContextInnerMethod · 0.95

Calls 4

SetReadDeadlineMethod · 0.80
AddMethod · 0.80
NowMethod · 0.80
TimeoutMethod · 0.80

Tested by

no test coverage detected