-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathstatement_diagnostics.go
674 lines (621 loc) · 20.9 KB
/
statement_diagnostics.go
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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package stmtdiagnostics
import (
"context"
"fmt"
"math/rand"
"time"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/multitenant"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/sql/sqlutil"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
)
var pollingInterval = settings.RegisterDurationSetting(
settings.TenantReadOnly,
"sql.stmt_diagnostics.poll_interval",
"rate at which the stmtdiagnostics.Registry polls for requests, set to zero to disable",
10*time.Second)
var bundleChunkSize = settings.RegisterByteSizeSetting(
settings.TenantWritable,
"sql.stmt_diagnostics.bundle_chunk_size",
"chunk size for statement diagnostic bundles",
1024*1024,
func(val int64) error {
if val < 16 {
return errors.Errorf("chunk size must be at least 16 bytes")
}
return nil
},
)
// Registry maintains a view on the statement fingerprints
// on which data is to be collected (i.e. system.statement_diagnostics_requests)
// and provides utilities for checking a query against this list and satisfying
// the requests.
type Registry struct {
mu struct {
// NOTE: This lock can't be held while the registry runs any statements
// internally; it'd deadlock.
syncutil.Mutex
// requests waiting for the right query to come along. The conditional
// requests are left in this map until they either are satisfied or
// expire (i.e. they never enter unconditionalOngoing map).
requestFingerprints map[RequestID]Request
// ids of unconditional requests that this node is in the process of
// servicing.
unconditionalOngoing map[RequestID]Request
// epoch is observed before reading system.statement_diagnostics_requests, and then
// checked again before loading the tables contents. If the value changed in
// between, then the table contents might be stale.
epoch int
rand *rand.Rand
}
st *cluster.Settings
ie sqlutil.InternalExecutor
db *kv.DB
}
// Request describes a statement diagnostics request along with some conditional
// information.
type Request struct {
fingerprint string
samplingProbability float64
minExecutionLatency time.Duration
expiresAt time.Time
}
func (r *Request) isExpired(now time.Time) bool {
return !r.expiresAt.IsZero() && r.expiresAt.Before(now)
}
func (r *Request) isConditional() bool {
return r.minExecutionLatency != 0
}
// NewRegistry constructs a new Registry.
func NewRegistry(ie sqlutil.InternalExecutor, db *kv.DB, st *cluster.Settings) *Registry {
r := &Registry{
ie: ie,
db: db,
st: st,
}
r.mu.rand = rand.New(rand.NewSource(timeutil.Now().UnixNano()))
return r
}
// Start will start the polling loop for the Registry.
func (r *Registry) Start(ctx context.Context, stopper *stop.Stopper) {
ctx, _ = stopper.WithCancelOnQuiesce(ctx)
// Since background statement diagnostics collection is not under user
// control, exclude it from cost accounting and control.
ctx = multitenant.WithTenantCostControlExemption(ctx)
// NB: The only error that should occur here would be if the server were
// shutting down so let's swallow it.
_ = stopper.RunAsyncTask(ctx, "stmt-diag-poll", r.poll)
}
func (r *Registry) poll(ctx context.Context) {
var (
timer timeutil.Timer
lastPoll time.Time
deadline time.Time
pollIntervalChanged = make(chan struct{}, 1)
maybeResetTimer = func() {
if interval := pollingInterval.Get(&r.st.SV); interval <= 0 {
// Setting the interval to a non-positive value stops the polling.
timer.Stop()
} else {
newDeadline := lastPoll.Add(interval)
if deadline.IsZero() || !deadline.Equal(newDeadline) {
deadline = newDeadline
timer.Reset(timeutil.Until(deadline))
}
}
}
poll = func() {
if err := r.pollRequests(ctx); err != nil {
if ctx.Err() != nil {
return
}
log.Warningf(ctx, "error polling for statement diagnostics requests: %s", err)
}
lastPoll = timeutil.Now()
}
)
pollingInterval.SetOnChange(&r.st.SV, func(ctx context.Context) {
select {
case pollIntervalChanged <- struct{}{}:
default:
}
})
for {
maybeResetTimer()
select {
case <-pollIntervalChanged:
continue // go back around and maybe reset the timer
case <-timer.C:
timer.Read = true
case <-ctx.Done():
return
}
poll()
}
}
// RequestID is the ID of a diagnostics request, corresponding to the id
// column in statement_diagnostics_requests.
// A zero ID is invalid.
type RequestID int
// CollectedInstanceID is the ID of an instance of collected diagnostics,
// corresponding to the id column in statement_diagnostics.
type CollectedInstanceID int
// addRequestInternalLocked adds a request to r.mu.requestFingerprints. If the
// request is already present or it has already expired, the call is a noop.
func (r *Registry) addRequestInternalLocked(
ctx context.Context,
id RequestID,
queryFingerprint string,
samplingProbability float64,
minExecutionLatency time.Duration,
expiresAt time.Time,
) {
if r.findRequestLocked(id) {
// Request already exists.
return
}
if r.mu.requestFingerprints == nil {
r.mu.requestFingerprints = make(map[RequestID]Request)
}
r.mu.requestFingerprints[id] = Request{
fingerprint: queryFingerprint,
samplingProbability: samplingProbability,
minExecutionLatency: minExecutionLatency,
expiresAt: expiresAt,
}
}
// findRequestLocked returns whether the request already exists. If the request
// is not ongoing and has already expired, it is removed from the registry (yet
// true is still returned).
func (r *Registry) findRequestLocked(requestID RequestID) bool {
f, ok := r.mu.requestFingerprints[requestID]
if ok {
if f.isExpired(timeutil.Now()) {
// This request has already expired.
delete(r.mu.requestFingerprints, requestID)
}
return true
}
_, ok = r.mu.unconditionalOngoing[requestID]
return ok
}
// cancelRequest removes the request with the given RequestID from the Registry
// if present.
func (r *Registry) cancelRequest(requestID RequestID) {
r.mu.Lock()
defer r.mu.Unlock()
delete(r.mu.requestFingerprints, requestID)
delete(r.mu.unconditionalOngoing, requestID)
}
// InsertRequest is part of the StmtDiagnosticsRequester interface.
func (r *Registry) InsertRequest(
ctx context.Context,
stmtFingerprint string,
samplingProbability float64,
minExecutionLatency time.Duration,
expiresAfter time.Duration,
) error {
_, err := r.insertRequestInternal(ctx, stmtFingerprint, samplingProbability, minExecutionLatency, expiresAfter)
return err
}
func (r *Registry) insertRequestInternal(
ctx context.Context,
stmtFingerprint string,
samplingProbability float64,
minExecutionLatency time.Duration,
expiresAfter time.Duration,
) (RequestID, error) {
isSamplingProbabilitySupported := r.st.Version.IsActive(ctx, clusterversion.SampledStmtDiagReqs)
if !isSamplingProbabilitySupported && samplingProbability != 0 {
return 0, errors.New(
"sampling probability only supported after 22.2 version migrations have completed",
)
}
if samplingProbability < 0 || samplingProbability > 1 {
return 0, errors.AssertionFailedf(
"malformed input: expected sampling probability in range [0.0, 1.0], got %f",
samplingProbability)
}
if samplingProbability != 0 && minExecutionLatency.Nanoseconds() == 0 {
return 0, errors.AssertionFailedf(
"malformed input: got non-zero sampling probability %f and empty min exec latency",
samplingProbability)
}
var reqID RequestID
var expiresAt time.Time
err := r.db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
// Check if there's already a pending request for this fingerprint.
row, err := r.ie.QueryRowEx(ctx, "stmt-diag-check-pending", txn,
sessiondata.InternalExecutorOverride{
User: username.RootUserName(),
},
`SELECT count(1) FROM system.statement_diagnostics_requests
WHERE
completed = false AND
statement_fingerprint = $1 AND
(expires_at IS NULL OR expires_at > now())`,
stmtFingerprint)
if err != nil {
return err
}
if row == nil {
return errors.New("failed to check pending statement diagnostics")
}
count := int(*row[0].(*tree.DInt))
if count != 0 {
return errors.New(
"A pending request for the requested fingerprint already exists. " +
"Cancel the existing request first and try again.",
)
}
now := timeutil.Now()
insertColumns := "statement_fingerprint, requested_at"
qargs := make([]interface{}, 2, 5)
qargs[0] = stmtFingerprint // statement_fingerprint
qargs[1] = now // requested_at
if samplingProbability != 0 {
insertColumns += ", sampling_probability"
qargs = append(qargs, samplingProbability) // sampling_probability
}
if minExecutionLatency != 0 {
insertColumns += ", min_execution_latency"
qargs = append(qargs, minExecutionLatency) // min_execution_latency
}
if expiresAfter != 0 {
insertColumns += ", expires_at"
expiresAt = now.Add(expiresAfter)
qargs = append(qargs, expiresAt) // expires_at
}
valuesClause := "$1, $2"
for i := range qargs[2:] {
valuesClause += fmt.Sprintf(", $%d", i+3)
}
stmt := "INSERT INTO system.statement_diagnostics_requests (" +
insertColumns + ") VALUES (" + valuesClause + ") RETURNING id;"
row, err = r.ie.QueryRowEx(
ctx, "stmt-diag-insert-request", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
stmt, qargs...,
)
if err != nil {
return err
}
if row == nil {
return errors.New("failed to insert statement diagnostics request")
}
reqID = RequestID(*row[0].(*tree.DInt))
return nil
})
if err != nil {
return 0, err
}
// Manually insert the request in the (local) registry. This lets this node
// pick up the request quickly if the right query comes around, without
// waiting for the poller.
func() {
r.mu.Lock()
defer r.mu.Unlock()
r.mu.epoch++
r.addRequestInternalLocked(ctx, reqID, stmtFingerprint, samplingProbability, minExecutionLatency, expiresAt)
}()
return reqID, nil
}
// CancelRequest is part of the server.StmtDiagnosticsRequester interface.
func (r *Registry) CancelRequest(ctx context.Context, requestID int64) error {
row, err := r.ie.QueryRowEx(ctx, "stmt-diag-cancel-request", nil, /* txn */
sessiondata.InternalExecutorOverride{
User: username.RootUserName(),
},
// Rather than deleting the row from the table, we choose to mark the
// request as "expired" by setting `expires_at` into the past. This will
// allow any queries that are currently being traced for this request to
// write their collected bundles.
"UPDATE system.statement_diagnostics_requests SET expires_at = '1970-01-01' "+
"WHERE completed = false AND id = $1 "+
"AND (expires_at IS NULL OR expires_at > now()) RETURNING id;",
requestID,
)
if err != nil {
return err
}
if row == nil {
// There is no pending diagnostics request with the given fingerprint.
return errors.Newf("no pending request found for the fingerprint: %s", requestID)
}
reqID := RequestID(requestID)
r.cancelRequest(reqID)
return nil
}
// IsExecLatencyConditionMet returns true if the completed request's execution
// latency satisfies the request's condition. If false is returned, it inlines
// the logic of RemoveOngoing.
func (r *Registry) IsExecLatencyConditionMet(
requestID RequestID, req Request, execLatency time.Duration,
) bool {
if req.minExecutionLatency <= execLatency {
return true
}
// This is a conditional request and the condition is not satisfied, so we
// only need to remove the request if it has expired.
if req.isExpired(timeutil.Now()) {
r.mu.Lock()
defer r.mu.Unlock()
delete(r.mu.requestFingerprints, requestID)
}
return false
}
// RemoveOngoing removes the given request from the list of ongoing queries.
func (r *Registry) RemoveOngoing(requestID RequestID, req Request) {
r.mu.Lock()
defer r.mu.Unlock()
if req.isConditional() {
if req.isExpired(timeutil.Now()) {
delete(r.mu.requestFingerprints, requestID)
}
} else {
delete(r.mu.unconditionalOngoing, requestID)
}
}
// ShouldCollectDiagnostics checks whether any data should be collected for the
// given query, which is the case if the registry has a request for this
// statement's fingerprint (and assuming probability conditions hold); in this
// case ShouldCollectDiagnostics will return true again on this node for the
// same diagnostics request only for conditional requests.
//
// If shouldCollect is true, RemoveOngoing needs to be called (which is inlined
// by IsExecLatencyConditionMet when that returns false).
func (r *Registry) ShouldCollectDiagnostics(
ctx context.Context, fingerprint string,
) (shouldCollect bool, reqID RequestID, req Request) {
r.mu.Lock()
defer r.mu.Unlock()
// Return quickly if we have no requests to trace.
if len(r.mu.requestFingerprints) == 0 {
return false, 0, req
}
for id, f := range r.mu.requestFingerprints {
if f.fingerprint == fingerprint {
if f.isExpired(timeutil.Now()) {
delete(r.mu.requestFingerprints, id)
return false, 0, req
}
reqID = id
req = f
break
}
}
if reqID == 0 {
return false, 0, Request{}
}
if !req.isConditional() {
if r.mu.unconditionalOngoing == nil {
r.mu.unconditionalOngoing = make(map[RequestID]Request)
}
r.mu.unconditionalOngoing[reqID] = req
delete(r.mu.requestFingerprints, reqID)
}
if req.samplingProbability == 0 || r.mu.rand.Float64() < req.samplingProbability {
return true, reqID, req
}
return false, 0, Request{}
}
// InsertStatementDiagnostics inserts a trace into system.statement_diagnostics.
//
// traceJSON is either DNull (when collectionErr should not be nil) or a *DJSON.
//
// If requestID is not zero, it also marks the request as completed in
// system.statement_diagnostics_requests. If requestID is zero, a new entry is
// inserted.
//
// collectionErr should be any error generated during the collection or
// generation of the bundle/trace.
func (r *Registry) InsertStatementDiagnostics(
ctx context.Context,
requestID RequestID,
stmtFingerprint string,
stmt string,
bundle []byte,
collectionErr error,
) (CollectedInstanceID, error) {
var diagID CollectedInstanceID
if ctx.Err() != nil {
// If the context was canceled (likely due to a statement timeout), we
// still want to save the statement bundle, so we override the canceled
// context with a background one.
ctx = context.Background()
}
err := r.db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
if requestID != 0 {
row, err := r.ie.QueryRowEx(ctx, "stmt-diag-check-completed", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"SELECT count(1) FROM system.statement_diagnostics_requests WHERE id = $1 AND completed = false",
requestID)
if err != nil {
return err
}
if row == nil {
return errors.New("failed to check completed statement diagnostics")
}
cnt := int(*row[0].(*tree.DInt))
if cnt == 0 {
// Someone else already marked the request as completed. We've traced for nothing.
// This can only happen once per node, per request since we're going to
// remove the request from the registry.
return nil
}
}
// Generate the values that will be inserted.
errorVal := tree.DNull
if collectionErr != nil {
errorVal = tree.NewDString(collectionErr.Error())
}
bundleChunksVal := tree.NewDArray(types.Int)
for len(bundle) > 0 {
chunkSize := int(bundleChunkSize.Get(&r.st.SV))
chunk := bundle
if len(chunk) > chunkSize {
chunk = chunk[:chunkSize]
}
bundle = bundle[len(chunk):]
// Insert the chunk into system.statement_bundle_chunks.
row, err := r.ie.QueryRowEx(
ctx, "stmt-bundle-chunks-insert", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"INSERT INTO system.statement_bundle_chunks(description, data) VALUES ($1, $2) RETURNING id",
"statement diagnostics bundle",
tree.NewDBytes(tree.DBytes(chunk)),
)
if err != nil {
return err
}
if row == nil {
return errors.New("failed to check statement bundle chunk")
}
chunkID := row[0].(*tree.DInt)
if err := bundleChunksVal.Append(chunkID); err != nil {
return err
}
}
collectionTime := timeutil.Now()
// Insert the trace into system.statement_diagnostics.
row, err := r.ie.QueryRowEx(
ctx, "stmt-diag-insert", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"INSERT INTO system.statement_diagnostics "+
"(statement_fingerprint, statement, collected_at, bundle_chunks, error) "+
"VALUES ($1, $2, $3, $4, $5) RETURNING id",
stmtFingerprint, stmt, collectionTime, bundleChunksVal, errorVal,
)
if err != nil {
return err
}
if row == nil {
return errors.New("failed to insert statement diagnostics")
}
diagID = CollectedInstanceID(*row[0].(*tree.DInt))
if requestID != 0 {
// Mark the request from system.statement_diagnostics_request as completed.
_, err := r.ie.ExecEx(ctx, "stmt-diag-mark-completed", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"UPDATE system.statement_diagnostics_requests "+
"SET completed = true, statement_diagnostics_id = $1 WHERE id = $2",
diagID, requestID)
if err != nil {
return err
}
} else {
// Insert a completed request into system.statement_diagnostics_request.
// This is necessary because the UI uses this table to discover completed
// diagnostics.
_, err := r.ie.ExecEx(ctx, "stmt-diag-add-completed", txn,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"INSERT INTO system.statement_diagnostics_requests"+
" (completed, statement_fingerprint, statement_diagnostics_id, requested_at)"+
" VALUES (true, $1, $2, $3)",
stmtFingerprint, diagID, collectionTime)
if err != nil {
return err
}
}
return nil
})
if err != nil {
return 0, err
}
return diagID, nil
}
// pollRequests reads the pending rows from system.statement_diagnostics_requests and
// updates r.mu.requests accordingly.
func (r *Registry) pollRequests(ctx context.Context) error {
var rows []tree.Datums
isSamplingProbabilitySupported := r.st.Version.IsActive(ctx, clusterversion.SampledStmtDiagReqs)
// Loop until we run the query without straddling an epoch increment.
for {
r.mu.Lock()
epoch := r.mu.epoch
r.mu.Unlock()
var extraColumns string
if isSamplingProbabilitySupported {
extraColumns = ", sampling_probability"
}
it, err := r.ie.QueryIteratorEx(ctx, "stmt-diag-poll", nil, /* txn */
sessiondata.InternalExecutorOverride{
User: username.RootUserName(),
},
fmt.Sprintf(`SELECT id, statement_fingerprint, min_execution_latency, expires_at%s
FROM system.statement_diagnostics_requests
WHERE completed = false AND (expires_at IS NULL OR expires_at > now())`, extraColumns),
)
if err != nil {
return err
}
rows = rows[:0]
var ok bool
for ok, err = it.Next(ctx); ok; ok, err = it.Next(ctx) {
rows = append(rows, it.Cur())
}
if err != nil {
return err
}
r.mu.Lock()
// If the epoch changed it means that a request was added to the registry
// manually while the query was running. In that case, if we were to process
// the query results normally, we might remove that manually-added request.
if r.mu.epoch != epoch {
r.mu.Unlock()
continue
}
break
}
defer r.mu.Unlock()
now := timeutil.Now()
var ids util.FastIntSet
for _, row := range rows {
id := RequestID(*row[0].(*tree.DInt))
stmtFingerprint := string(*row[1].(*tree.DString))
var minExecutionLatency time.Duration
var expiresAt time.Time
var samplingProbability float64
if minExecLatency, ok := row[2].(*tree.DInterval); ok {
minExecutionLatency = time.Duration(minExecLatency.Nanos())
}
if e, ok := row[3].(*tree.DTimestampTZ); ok {
expiresAt = e.Time
}
if isSamplingProbabilitySupported {
if prob, ok := row[4].(*tree.DFloat); ok {
samplingProbability = float64(*prob)
}
}
ids.Add(int(id))
r.addRequestInternalLocked(ctx, id, stmtFingerprint, samplingProbability, minExecutionLatency, expiresAt)
}
// Remove all other requests.
for id, req := range r.mu.requestFingerprints {
if !ids.Contains(int(id)) || req.isExpired(now) {
delete(r.mu.requestFingerprints, id)
}
}
return nil
}