Skip to content

Commit cb471bf

Browse files
committed
roachtest: add operation to query crdb_internal.probe_ranges
Since SRE uses crdb_internal.probe_ranges to test for prod cluster health, we would like to add this as a roach operation to make the DRT cluster as realistic as possible, and test for potential issues with crdb_internal.probe_ranges. Fixes: cockroachdb#102034 Release note: None Epic: None
1 parent 0c74fb7 commit cb471bf

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

pkg/cmd/roachtest/operations/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
"network_partition.go",
1818
"node_kill.go",
1919
"pause_job.go",
20+
"probe_ranges.go",
2021
"register.go",
2122
"resize.go",
2223
"session_vars.go",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2024 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 operations
7+
8+
import (
9+
"context"
10+
"fmt"
11+
"time"
12+
13+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
14+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/operation"
15+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/operations/helpers"
16+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
17+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
18+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestflags"
19+
"github.com/cockroachdb/cockroach/pkg/util/randutil"
20+
)
21+
22+
func runProbeRanges(
23+
ctx context.Context, o operation.Operation, c cluster.Cluster,
24+
) registry.OperationCleanup {
25+
rng, _ := randutil.NewPseudoRand()
26+
27+
nodes := c.All()
28+
nid := nodes[rng.Intn(len(nodes))]
29+
30+
conn := c.Conn(ctx, o.L(), nid, option.VirtualClusterName(roachtestflags.VirtualCluster))
31+
defer conn.Close()
32+
33+
dbName := helpers.PickRandomDB(ctx, o, conn, helpers.SystemDBs)
34+
tableName := helpers.PickRandomTable(ctx, o, conn, dbName)
35+
sid := helpers.PickRandomStore(ctx, o, conn, nid)
36+
37+
compactionStmt := fmt.Sprintf(`SELECT crdb_internal.compact_engine_span(
38+
%d, %d,
39+
(SELECT raw_start_key FROM [SHOW RANGES FROM TABLE %s.%s WITH KEYS] LIMIT 1),
40+
(SELECT raw_end_key FROM [SHOW RANGES FROM TABLE %s.%s WITH KEYS] LIMIT 1))`,
41+
nid, sid, dbName, tableName, dbName, tableName)
42+
o.Status(fmt.Sprintf("compacting a range for table %s.%s in n%d, s%d",
43+
dbName, tableName, nid, sid))
44+
_, err := conn.ExecContext(ctx, compactionStmt)
45+
if err != nil {
46+
o.Fatal(err)
47+
}
48+
return nil
49+
}
50+
51+
// runKVProber tests that accessing crdb_internal_probe_ranges works across mixed version clusters.
52+
func runKVProberMixedVersion(ctx context.Context, o operation.Operation, c cluster.Cluster) registry.OperationCleanup {
53+
rng, _ := randutil.NewPseudoRand()
54+
55+
nodes := c.All()
56+
nid := nodes[rng.Intn(len(nodes))]
57+
58+
conn := c.Conn(ctx, o.L(), nid, option.VirtualClusterName(roachtestflags.VirtualCluster))
59+
defer conn.Close()
60+
61+
kvProbeRead := fmt.Sprintf(`select count(error) from crdb_internal.probe_ranges(interval '1s', 'read') where node_id=%d"`, nid)
62+
kvProbeWrite := fmt.Sprintf(`select count(error) from crdb_internal.probe_ranges(interval '1s', 'write') where node_id=%d"`, nid)
63+
64+
o.Status("probing reads to crdb_internal.probe_ranges")
65+
_, read_err := conn.ExecContext(ctx, kvProbeRead)
66+
if read_err != nil {
67+
o.Fatal(read_err)
68+
}
69+
70+
o.Status("probing writes to crdb_internal.probe_ranges")
71+
_, write_err := conn.ExecContext(ctx, kvProbeWrite)
72+
if write_err != nil {
73+
o.Fatal(write_err)
74+
}
75+
76+
return nil
77+
}
78+
79+
func registerProbeRanges(r registry.Registry) {
80+
r.AddOperation(registry.OperationSpec{
81+
Name: "manual-compaction",
82+
Owner: registry.OwnerStorage,
83+
Timeout: 24 * time.Hour,
84+
CompatibleClouds: registry.OnlyGCE,
85+
CanRunConcurrently: registry.OperationCanRunConcurrently,
86+
Dependencies: []registry.OperationDependency{registry.OperationRequiresZeroUnavailableRanges},
87+
Run: runProbeRanges,
88+
})
89+
}

0 commit comments

Comments
 (0)