Skip to content

Commit 24bd59b

Browse files
craig[bot]spilchentbg
committed
156585: sql: move inspect_job.go to pkg/sql/inspect r=spilchen a=spilchen This change moves all inspect related code out of `pkg/sql`, consolidating it under the `pkg/sql/inspect` package: - Moves `inspect_job.go` to `inspect/inspect_job_entry.go`, fully relocating inspect job logic into the inspect package. - Renames `inspect_job.go` to `inspect_resumer.go` to match naming conventions used by other job resumers. - Cleans up naming: removes redundant Inspect prefixes (e.g., TriggerInspectJob → TriggerJob) and unexports functions that are internal-only. Closes #155473 Epic: CRDB-55075 Release note: none 156637: rpc: skip clock offset tests under duress r=stevendanna a=tbg Closes #154839. Reviewers: please bors on LGTM. Epic: none Co-authored-by: Matt Spilchen <matt.spilchen@cockroachlabs.com> Co-authored-by: Tobias Grieger <tobias.b.grieger@gmail.com>
3 parents c1b788a + 98c65f0 + b35f492 commit 24bd59b

File tree

9 files changed

+27
-29
lines changed

9 files changed

+27
-29
lines changed

pkg/rpc/context_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func TestClockOffsetInClientPingRequest(t *testing.T) {
193193
}
194194

195195
func testClockOffsetInPingRequestInternal(t *testing.T, clientOnly bool) {
196+
skip.UnderDuress(t, "https://github.com/cockroachdb/cockroach/issues/154839")
196197
ctx := context.Background()
197198
stopper := stop.NewStopper()
198199
defer stopper.Stop(ctx)

pkg/sql/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ go_library(
141141
"information_schema.go",
142142
"insert.go",
143143
"insert_fast_path.go",
144-
"inspect_job.go",
145144
"instrumentation.go",
146145
"internal.go",
147146
"internal_result_channel.go",

pkg/sql/importer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ go_library(
6161
"//pkg/sql/faketreeeval",
6262
"//pkg/sql/flowinfra",
6363
"//pkg/sql/gcjob",
64+
"//pkg/sql/inspect",
6465
"//pkg/sql/isql",
6566
"//pkg/sql/lexbase",
6667
"//pkg/sql/pgwire/pgcode",

pkg/sql/importer/import_job.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
3232
"github.com/cockroachdb/cockroach/pkg/sql/flowinfra"
3333
"github.com/cockroachdb/cockroach/pkg/sql/gcjob"
34+
"github.com/cockroachdb/cockroach/pkg/sql/inspect"
3435
"github.com/cockroachdb/cockroach/pkg/sql/isql"
3536
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
3637
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
@@ -328,12 +329,12 @@ func (r *importResumer) Resume(ctx context.Context, execCtx interface{}) error {
328329
}
329330
tblDesc := tabledesc.NewBuilder(table.Desc).BuildImmutableTable()
330331
if len(tblDesc.PublicNonPrimaryIndexes()) > 0 {
331-
checks, err := sql.InspectChecksForTable(ctx, nil /* p */, tblDesc)
332+
checks, err := inspect.ChecksForTable(ctx, nil /* p */, tblDesc)
332333
if err != nil {
333334
return err
334335
}
335336

336-
job, err := sql.TriggerInspectJob(
337+
job, err := inspect.TriggerJob(
337338
ctx,
338339
fmt.Sprintf("import-validation-%s", tblDesc.GetName()),
339340
p.ExecCfg(),

pkg/sql/inspect/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ go_library(
44
name = "inspect",
55
srcs = [
66
"index_consistency_check.go",
7-
"inspect_job.go",
7+
"inspect_job_entry.go",
88
"inspect_logger.go",
99
"inspect_metrics.go",
1010
"inspect_plan.go",
1111
"inspect_processor.go",
12+
"inspect_resumer.go",
1213
"issue.go",
1314
"log_sink.go",
1415
"progress.go",
@@ -71,9 +72,9 @@ go_test(
7172
size = "large",
7273
srcs = [
7374
"index_consistency_check_test.go",
74-
"inspect_job_test.go",
7575
"inspect_metrics_test.go",
7676
"inspect_processor_test.go",
77+
"inspect_resumer_test.go",
7778
"issue_test.go",
7879
"main_test.go",
7980
"progress_test.go",

pkg/sql/inspect_job.go renamed to pkg/sql/inspect/inspect_job_entry.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
// Use of this software is governed by the CockroachDB Software License
44
// included in the /LICENSE file.
55

6-
// TODO(148365): Move this file to the `pkg/sql/inspect` package. The scrub command
7-
// will have to forgo its dependency on inspect.
8-
9-
package sql
6+
package inspect
107

118
import (
129
"context"
1310

1411
"github.com/cockroachdb/cockroach/pkg/jobs"
1512
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1613
"github.com/cockroachdb/cockroach/pkg/security/username"
14+
"github.com/cockroachdb/cockroach/pkg/sql"
1715
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1816
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
1917
"github.com/cockroachdb/cockroach/pkg/sql/isql"
@@ -27,13 +25,11 @@ import (
2725
"github.com/cockroachdb/cockroach/pkg/util/log"
2826
)
2927

30-
// TriggerInspectJob starts an inspect job for the snapshot.
31-
// TODO(148365): Stop exporting this function when it's moved to the inspect
32-
// package.
33-
func TriggerInspectJob(
28+
// TriggerJob starts an inspect job for the snapshot.
29+
func TriggerJob(
3430
ctx context.Context,
3531
jobRecordDescription string,
36-
execCfg *ExecutorConfig,
32+
execCfg *sql.ExecutorConfig,
3733
txn isql.Txn,
3834
checks []*jobspb.InspectDetails_Check,
3935
asOf hlc.Timestamp,
@@ -98,11 +94,10 @@ func TriggerInspectJob(
9894
return job, nil
9995
}
10096

101-
// InspectChecksForDatabase generates checks on every supported index on every
97+
// checksForDatabase generates checks on every supported index on every
10298
// table in the given database.
103-
// TODO(148365): Stop exporting this function after moving to pkg/sql/inspect.
104-
func InspectChecksForDatabase(
105-
ctx context.Context, p PlanHookState, db catalog.DatabaseDescriptor,
99+
func checksForDatabase(
100+
ctx context.Context, p sql.PlanHookState, db catalog.DatabaseDescriptor,
106101
) ([]*jobspb.InspectDetails_Check, error) {
107102
avoidLeased := false
108103
if aost := p.ExtendedEvalContext().AsOfSystemTime; aost != nil {
@@ -120,7 +115,7 @@ func InspectChecksForDatabase(
120115
checks := []*jobspb.InspectDetails_Check{}
121116

122117
if err := tables.ForEachDescriptor(func(desc catalog.Descriptor) error {
123-
tableChecks, err := InspectChecksForTable(ctx, p, desc.(catalog.TableDescriptor))
118+
tableChecks, err := ChecksForTable(ctx, p, desc.(catalog.TableDescriptor))
124119
if err != nil {
125120
return err
126121
}
@@ -133,10 +128,10 @@ func InspectChecksForDatabase(
133128
return checks, nil
134129
}
135130

136-
// InspectChecksForTable generates checks on every supported index on the given
131+
// ChecksForTable generates checks on every supported index on the given
137132
// table.
138-
func InspectChecksForTable(
139-
ctx context.Context, p PlanHookState, table catalog.TableDescriptor,
133+
func ChecksForTable(
134+
ctx context.Context, p sql.PlanHookState, table catalog.TableDescriptor,
140135
) ([]*jobspb.InspectDetails_Check, error) {
141136
checks := []*jobspb.InspectDetails_Check{}
142137

@@ -165,11 +160,11 @@ type indexKey struct {
165160
descpb.IndexID
166161
}
167162

168-
// InspectChecksByIndexNames generates checks for the specified index names.
163+
// checksByIndexNames generates checks for the specified index names.
169164
// If index names are not found or are not supported for inspection, an error is returned.
170165
// Index names are deduplicated.
171-
func InspectChecksByIndexNames(
172-
ctx context.Context, p PlanHookState, names tree.TableIndexNames,
166+
func checksByIndexNames(
167+
ctx context.Context, p sql.PlanHookState, names tree.TableIndexNames,
173168
) ([]*jobspb.InspectDetails_Check, error) {
174169
checks := []*jobspb.InspectDetails_Check{}
175170

pkg/sql/inspect/inspect_plan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ func newInspectRun(
109109
// No INDEX options or INDEX ALL specified - inspect all indexes.
110110
switch stmt.Typ {
111111
case tree.InspectTable:
112-
checks, err := sql.InspectChecksForTable(ctx, p, run.table)
112+
checks, err := ChecksForTable(ctx, p, run.table)
113113
if err != nil {
114114
return inspectRun{}, err
115115
}
116116
run.checks = checks
117117
case tree.InspectDatabase:
118-
if checks, err := sql.InspectChecksForDatabase(ctx, p, run.db); err != nil {
118+
if checks, err := checksForDatabase(ctx, p, run.db); err != nil {
119119
return inspectRun{}, err
120120
} else {
121121
run.checks = checks
@@ -152,7 +152,7 @@ func newInspectRun(
152152
}
153153
}
154154

155-
if checks, err := sql.InspectChecksByIndexNames(ctx, p, run.namedIndexes); err != nil {
155+
if checks, err := checksByIndexNames(ctx, p, run.namedIndexes); err != nil {
156156
return inspectRun{}, err
157157
} else {
158158
run.checks = checks
@@ -236,7 +236,7 @@ func inspectPlanHook(
236236
// the job record creation happens transactionally.
237237
plannerTxn := p.InternalSQLTxn()
238238

239-
sj, err := sql.TriggerInspectJob(ctx, tree.AsString(stmt), p.ExecCfg(), plannerTxn, run.checks, run.asOfTimestamp)
239+
sj, err := TriggerJob(ctx, tree.AsString(stmt), p.ExecCfg(), plannerTxn, run.checks, run.asOfTimestamp)
240240
if err != nil {
241241
return err
242242
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)