|
| 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