Skip to content

Commit 72404cb

Browse files
committed
sql: add support for span checks and cluster checks
Previously the checks were independent and could only process individual spans. The row count check will be dependent on other checks that perform the scan of each span and will need to aggregate the row counts after all the spans have been processed. This change sets up interfaces for span-level (dependent on other checks running on the spans) and cluster-level checks (run after all spans have been processed). Part of: #155472 Epic: CRDB-55075 Release note: None
1 parent 65de6b4 commit 72404cb

File tree

11 files changed

+890
-95
lines changed

11 files changed

+890
-95
lines changed

pkg/sql/inspect/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
33
go_library(
44
name = "inspect",
55
srcs = [
6+
"cluster_runner.go",
67
"index_consistency_check.go",
78
"inspect_job_entry.go",
89
"inspect_logger.go",
@@ -72,6 +73,7 @@ go_test(
7273
name = "inspect_test",
7374
size = "large",
7475
srcs = [
76+
"cluster_runner_test.go",
7577
"index_consistency_check_test.go",
7678
"inspect_metrics_test.go",
7779
"inspect_processor_test.go",

pkg/sql/inspect/cluster_runner.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2026 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package inspect
7+
8+
import (
9+
"context"
10+
11+
"github.com/cockroachdb/errors"
12+
)
13+
14+
type clusterRunner struct {
15+
// checks holds the list of checks to run. Each check is run to completion
16+
// before moving on to the next.
17+
checks []inspectClusterCheck
18+
19+
// logger records issues reported by the checks.
20+
logger *inspectLoggerBundle
21+
22+
progressTracker *inspectProgressTracker
23+
}
24+
25+
// processClusterChecks runs any cluster-level checks using the accumulated job
26+
// progress.
27+
func (c *clusterRunner) Step(ctx context.Context) (bool, error) {
28+
for len(c.checks) > 0 {
29+
check := c.checks[0]
30+
31+
if !check.Started() {
32+
if err := check.StartCluster(ctx, c.progressTracker.mu.cachedProgress.GetInspect()); err != nil {
33+
return false, errors.Wrapf(err, "error starting cluster inspect check")
34+
}
35+
}
36+
37+
for !check.DoneCluster(ctx) {
38+
issue, err := check.NextCluster(ctx)
39+
if err != nil {
40+
return false, errors.Wrapf(err, "error running cluster inspect check")
41+
}
42+
if issue != nil {
43+
err = c.logger.logIssue(ctx, issue)
44+
if err != nil {
45+
return false, errors.Wrapf(err, "error logging inspect issue")
46+
}
47+
}
48+
return true, nil
49+
}
50+
51+
if err := check.CloseCluster(ctx); err != nil {
52+
return false, errors.Wrapf(err, "error closing cluster inspect check")
53+
}
54+
55+
c.checks = c.checks[1:]
56+
}
57+
58+
return false, nil
59+
}
60+
61+
// Close cleans up all checks in the runner. It will attempt to close each check,
62+
// even if errors occur during closing. If multiple checks fail to close, then
63+
// a combined error is returned.
64+
func (c *clusterRunner) Close(ctx context.Context) error {
65+
var retErr error
66+
for _, check := range c.checks {
67+
if err := check.CloseCluster(ctx); err != nil {
68+
retErr = errors.CombineErrors(retErr, err)
69+
}
70+
}
71+
return retErr
72+
}

0 commit comments

Comments
 (0)