|
| 1 | +// Copyright 2025 The Cockroach Authors. |
| 2 | +// |
| 3 | +// Use of this software is governed by the CockroachDB Software License |
| 4 | +// included in the /LICENSE file. |
| 5 | + |
| 6 | +/* |
| 7 | +This package is used to collect SQL Activity Statistics from the SQL subsystem. |
| 8 | +
|
| 9 | +# The recording of SQL Activity is managed through the following components: |
| 10 | +
|
| 11 | + 1. Conn Executor: SQL Execution is managed here and stats are collected and sent |
| 12 | + to the Stats Collector. |
| 13 | + 2. (sslocal) Stats Collector: Receives stats from the Conn Executor and buffers them into |
| 14 | + the `ssmemstorage.Container` |
| 15 | + 3. (sslocal) SQL Stats Ingester: Receives stats from the Stats Collector and |
| 16 | + flushes them to the registry. |
| 17 | + 4. Container: A per-application container that holds stats for a given |
| 18 | + application. The Ingester flushes |
| 19 | +
|
| 20 | +# Sequence of Operations |
| 21 | +
|
| 22 | +The diagram below illustrates how stats flow through the StatsCollector and |
| 23 | +StatsIngester as a transaction executes. |
| 24 | +
|
| 25 | + +---------------+ +-----------------+ +---------------+ +-----------+ |
| 26 | + | ConnExecutor | | StatsCollector | | StatsIngester | | Container | |
| 27 | + +---------------+ +-----------------+ +---------------+ +-----------+ |
| 28 | + | | | | |
| 29 | + | RecordStatement | | | |
| 30 | + |--------------------------->| | | |
| 31 | + | | -------------------------------------------\ | | |
| 32 | + | |-| *RecordedStmtStats accumulates in buffer | | | |
| 33 | + | | |------------------------------------------| | | |
| 34 | + | | | | |
| 35 | + | EndTransaction | | | |
| 36 | + |--------------------------->| | | |
| 37 | + | | ------------------------------------------\ | | |
| 38 | + | |-| set TransactionID on *RecordedStmtStats | | | |
| 39 | + | | |-----------------------------------------| | | |
| 40 | + | | | | |
| 41 | + | | IngestStatement | | |
| 42 | + | |--------------------------------------------------->| | |
| 43 | + | | | -------------------------------------------\ | |
| 44 | + | | |-| *RecordedStmtStats accumulates in buffer | | |
| 45 | + | | | |------------------------------------------| | |
| 46 | + | | | | |
| 47 | + | | RecordStatement | | |
| 48 | + | |---------------------------------------------------------------------------------------------------------->| |
| 49 | + | | | | |
| 50 | + | RecordTransaction | | | |
| 51 | + |--------------------------->| | | |
| 52 | + | | | | |
| 53 | + | | IngestTransaction | | |
| 54 | + | |--------------------------------------------------->| | |
| 55 | + | | | | |
| 56 | + | | RecordTransaction | | |
| 57 | + | |---------------------------------------------------------------------------------------------------------->| |
| 58 | + | | | -----------------------------------------------\ | |
| 59 | + | | |-| all *RecordedStmtStats in buffer are flushed | | |
| 60 | + | | | |----------------------------------------------| | |
| 61 | + | | | | ----------------------------------------\ |
| 62 | + | | | |-| eventually flushed to persisted stats | |
| 63 | + | | | | |---------------------------------------| |
| 64 | + | | | | |
| 65 | +*/ |
| 66 | +package sslocal |
| 67 | + |
| 68 | +// Input to sequence diagram generator: |
| 69 | +/* |
| 70 | +object ConnExecutor StatsCollector StatsIngester Container |
| 71 | +ConnExecutor -> StatsCollector: RecordStatement |
| 72 | +note right of StatsCollector: *RecordedStmtStats accumulates in buffer |
| 73 | +ConnExecutor -> StatsCollector: EndTransaction |
| 74 | +note right of StatsCollector: set TransactionID on *RecordedStmtStats |
| 75 | +StatsCollector -> StatsIngester: IngestStatement |
| 76 | +note right of StatsIngester: *RecordedStmtStats accumulates in buffer |
| 77 | +StatsCollector -> Container: RecordStatement |
| 78 | +ConnExecutor -> StatsCollector: RecordTransaction |
| 79 | +StatsCollector -> StatsIngester: IngestTransaction |
| 80 | +StatsCollector -> Container: RecordTransaction |
| 81 | +note right of StatsIngester: all *RecordedStmtStats in buffer are flushed |
| 82 | +note right of Container: eventually flushed to persisted stats |
| 83 | +*/ |
0 commit comments