Skip to content

Commit 1aed077

Browse files
committed
jobs: remove dead legacy branches
This is a simple cleanup of version conditionals that no longer serve any purpose and the disused upgrades related to jobs in 25.1. Release note: none. Epic: none.
1 parent 8e52c96 commit 1aed077

File tree

7 files changed

+71
-614
lines changed

7 files changed

+71
-614
lines changed

pkg/clusterversion/cockroach_versions.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ const (
187187

188188
TODO_Delete_V25_1_Start
189189

190-
// TODO_Delete_V25_1_AddJobsTables added new jobs tables.
191-
TODO_Delete_V25_1_AddJobsTables
192-
193190
// TODO_Delete_V25_1_AddRangeForceFlushKey adds the RangeForceFlushKey, a replicated
194191
// range-ID local key, which is written below raft.
195192
TODO_Delete_V25_1_AddRangeForceFlushKey
@@ -203,19 +200,6 @@ const (
203200
// that are part of the XA two-phase commit protocol.
204201
TODO_Delete_V25_1_PreparedTransactionsTable
205202

206-
// TODO_Delete_V25_1_AddJobsColumns added new columns to system.jobs.
207-
TODO_Delete_V25_1_AddJobsColumns
208-
209-
// TODO_Delete_V25_1_JobsWritesFence is an empty version that is used to add a "fence"
210-
// between the column addition version and the backfill version. This allows
211-
// the backfill version's upgrade step to make the assumption that all nodes
212-
// will be writing to the new columns, since moving from fence to backfill can
213-
// only start once no nodes are still on add-columnns.
214-
TODO_Delete_V25_1_JobsWritesFence
215-
216-
// TODO_Delete_V25_1_JobsBackfill backfills the new jobs tables and columns.
217-
TODO_Delete_V25_1_JobsBackfill
218-
219203
// V25_1 is CockroachDB v25.1. It's used for all v25.1.x patch releases.
220204
V25_1
221205

@@ -271,13 +255,9 @@ var versionTable = [numKeys]roachpb.Version{
271255
// v25.1 versions. Internal versions must be even.
272256
TODO_Delete_V25_1_Start: {Major: 24, Minor: 3, Internal: 2},
273257

274-
TODO_Delete_V25_1_AddJobsTables: {Major: 24, Minor: 3, Internal: 4},
275258
TODO_Delete_V25_1_AddRangeForceFlushKey: {Major: 24, Minor: 3, Internal: 8},
276259
TODO_Delete_V25_1_BatchStreamRPC: {Major: 24, Minor: 3, Internal: 10},
277260
TODO_Delete_V25_1_PreparedTransactionsTable: {Major: 24, Minor: 3, Internal: 12},
278-
TODO_Delete_V25_1_AddJobsColumns: {Major: 24, Minor: 3, Internal: 14},
279-
TODO_Delete_V25_1_JobsWritesFence: {Major: 24, Minor: 3, Internal: 16},
280-
TODO_Delete_V25_1_JobsBackfill: {Major: 24, Minor: 3, Internal: 18},
281261

282262
V25_1: {Major: 25, Minor: 1, Internal: 0},
283263

pkg/jobs/registry.go

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func batchJobInsertStmt(
483483
return "", nil, nil, errors.NewAssertionErrorWithWrappedErrf(err, "failed to make timestamp for creation of job")
484484
}
485485
instanceID := r.ID()
486-
columns := []string{`id`, `created`, `status`, `claim_session_id`, `claim_instance_id`, `job_type`}
486+
columns := []string{`id`, `created`, `status`, `claim_session_id`, `claim_instance_id`, `job_type`, `owner`, `description`}
487487
valueFns := map[string]func(*Job) (interface{}, error){
488488
`id`: func(job *Job) (interface{}, error) { return job.ID(), nil },
489489
`created`: func(job *Job) (interface{}, error) { return created, nil },
@@ -494,12 +494,8 @@ func batchJobInsertStmt(
494494
payload := job.Payload()
495495
return payload.Type().String(), nil
496496
},
497-
}
498-
499-
if schemaVersion.AtLeast(clusterversion.TODO_Delete_V25_1_AddJobsColumns.Version()) {
500-
columns = append(columns, `owner`, `description`)
501-
valueFns[`owner`] = func(job *Job) (interface{}, error) { return job.Payload().UsernameProto.Decode().Normalized(), nil }
502-
valueFns[`description`] = func(job *Job) (interface{}, error) { return job.Payload().Description, nil }
497+
`owner`: func(job *Job) (interface{}, error) { return job.Payload().UsernameProto.Decode().Normalized(), nil },
498+
`description`: func(job *Job) (interface{}, error) { return job.Payload().Description, nil },
503499
}
504500

505501
appendValues := func(job *Job, vals *[]interface{}) (err error) {
@@ -590,15 +586,9 @@ func (r *Registry) CreateJobWithTxn(
590586
return errors.NewAssertionErrorWithWrappedErrf(err, "failed to construct job created timestamp")
591587
}
592588

593-
cols := []string{"id", "created", "status", "claim_session_id", "claim_instance_id", "job_type"}
594-
vals := []interface{}{jobID, created, StateRunning, s.ID().UnsafeBytes(), r.ID(), jobType.String()}
595-
v, err := txn.GetSystemSchemaVersion(ctx)
596-
if err != nil {
597-
return err
598-
}
599-
if v.AtLeast(clusterversion.TODO_Delete_V25_1_AddJobsColumns.Version()) {
600-
cols = append(cols, "owner", "description")
601-
vals = append(vals, j.mu.payload.UsernameProto.Decode().Normalized(), j.mu.payload.Description)
589+
cols := []string{"id", "created", "status", "claim_session_id", "claim_instance_id", "job_type", "owner", "description"}
590+
vals := []interface{}{
591+
jobID, created, StateRunning, s.ID().UnsafeBytes(), r.ID(), jobType.String(), j.mu.payload.UsernameProto.Decode().Normalized(), j.mu.payload.Description,
602592
}
603593

604594
totalNumCols := len(cols)
@@ -730,18 +720,9 @@ func (r *Registry) CreateAdoptableJobWithTxn(
730720
}
731721
typ := j.mu.payload.Type().String()
732722

733-
cols := []string{"id", "created", "status", "created_by_type", "created_by_id", "job_type"}
734-
placeholders := []string{"$1", "now() at time zone 'utc'", "$2", "$3", "$4", "$5"}
735-
vals := []interface{}{jobID, StateRunning, createdByType, createdByID, typ}
736-
v, err := txn.GetSystemSchemaVersion(ctx)
737-
if err != nil {
738-
return err
739-
}
740-
if v.AtLeast(clusterversion.TODO_Delete_V25_1_AddJobsColumns.Version()) {
741-
cols = append(cols, "owner", "description")
742-
placeholders = append(placeholders, "$6", "$7")
743-
vals = append(vals, j.mu.payload.UsernameProto.Decode().Normalized(), j.mu.payload.Description)
744-
}
723+
cols := []string{"id", "created", "status", "created_by_type", "created_by_id", "job_type", "owner", "description"}
724+
placeholders := []string{"$1", "now() at time zone 'utc'", "$2", "$3", "$4", "$5", "$6", "$7"}
725+
vals := []interface{}{jobID, StateRunning, createdByType, createdByID, typ, j.mu.payload.UsernameProto.Decode().Normalized(), j.mu.payload.Description}
745726

746727
// Insert the job row, but do not set a `claim_session_id`. By not
747728
// setting the claim, the job can be adopted by any node and will
@@ -1275,20 +1256,11 @@ func (r *Registry) cleanupOldJobsPage(
12751256
}
12761257

12771258
counts := make(map[string]int)
1278-
for i, tbl := range jobMetadataTables {
1259+
for _, tbl := range jobMetadataTables {
12791260
var deleted int
12801261
if err := r.db.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
12811262
// Tables other than job_info -- the 0th -- are only present if the txn is
12821263
// running at a version that includes them.
1283-
if i > 0 {
1284-
v, err := txn.GetSystemSchemaVersion(ctx)
1285-
if err != nil {
1286-
return err
1287-
}
1288-
if v.Less(clusterversion.TODO_Delete_V25_1_AddJobsTables.Version()) {
1289-
return nil
1290-
}
1291-
}
12921264
deleted, err = txn.Exec(ctx, redact.RedactableString("gc-job-"+tbl), txn.KV(),
12931265
"DELETE FROM system."+tbl+" WHERE job_id = ANY($1)", toDelete,
12941266
)
@@ -1337,17 +1309,7 @@ func (r *Registry) DeleteTerminalJobByID(ctx context.Context, id jobspb.JobID) e
13371309
if err != nil {
13381310
return err
13391311
}
1340-
for i, tbl := range jobMetadataTables {
1341-
if i > 0 {
1342-
v, err := txn.GetSystemSchemaVersion(ctx)
1343-
if err != nil {
1344-
return err
1345-
}
1346-
if v.Less(clusterversion.TODO_Delete_V25_1_AddJobsTables.Version()) {
1347-
break
1348-
}
1349-
}
1350-
1312+
for _, tbl := range jobMetadataTables {
13511313
_, err = txn.Exec(
13521314
ctx, redact.RedactableString("delete-job-"+tbl), txn.KV(),
13531315
"DELETE FROM system."+tbl+" WHERE job_id = $1", id,

pkg/jobs/update.go

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/cockroachdb/cockroach/pkg/clusterversion"
1615
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1716
"github.com/cockroachdb/cockroach/pkg/sql/isql"
1817
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
@@ -281,96 +280,88 @@ WHERE id = $1
281280
}
282281
}
283282

284-
v, err := u.txn.GetSystemSchemaVersion(ctx)
285-
if err != nil {
286-
return err
287-
}
288-
if v.AtLeast(clusterversion.TODO_Delete_V25_1_AddJobsTables.Version()) {
289-
if ju.md.State != "" && ju.md.State != state {
290-
if err := j.Messages().Record(ctx, u.txn, "state", string(ju.md.State)); err != nil {
283+
if ju.md.State != "" && ju.md.State != state {
284+
if err := j.Messages().Record(ctx, u.txn, "state", string(ju.md.State)); err != nil {
285+
return err
286+
}
287+
// If we are changing state, we should clear out the status, unless
288+
// we are about to set it to something instead.
289+
if progress == nil || progress.StatusMessage == "" {
290+
if err := j.StatusStorage().Clear(ctx, u.txn); err != nil {
291291
return err
292292
}
293-
// If we are changing state, we should clear out the status, unless
294-
// we are about to set it to something instead.
295-
if progress == nil || progress.StatusMessage == "" {
296-
if err := j.StatusStorage().Clear(ctx, u.txn); err != nil {
297-
return err
298-
}
299-
}
300293
}
294+
}
301295

302-
if progress != nil {
303-
var ts hlc.Timestamp
304-
if hwm := progress.GetHighWater(); hwm != nil {
305-
ts = *hwm
306-
}
296+
if progress != nil {
297+
var ts hlc.Timestamp
298+
if hwm := progress.GetHighWater(); hwm != nil {
299+
ts = *hwm
300+
}
307301

308-
if err := j.ProgressStorage().Set(ctx, u.txn, float64(progress.GetFractionCompleted()), ts); err != nil {
309-
return err
310-
}
302+
if err := j.ProgressStorage().Set(ctx, u.txn, float64(progress.GetFractionCompleted()), ts); err != nil {
303+
return err
304+
}
311305

312-
if progress.StatusMessage != beforeProgress.StatusMessage {
313-
if err := j.StatusStorage().Set(ctx, u.txn, progress.StatusMessage); err != nil {
314-
return err
315-
}
306+
if progress.StatusMessage != beforeProgress.StatusMessage {
307+
if err := j.StatusStorage().Set(ctx, u.txn, progress.StatusMessage); err != nil {
308+
return err
316309
}
310+
}
317311

318-
if progress.TraceID != beforeProgress.TraceID {
319-
if err := j.Messages().Record(ctx, u.txn, "trace-id", fmt.Sprintf("%d", progress.TraceID)); err != nil {
320-
return err
321-
}
312+
if progress.TraceID != beforeProgress.TraceID {
313+
if err := j.Messages().Record(ctx, u.txn, "trace-id", fmt.Sprintf("%d", progress.TraceID)); err != nil {
314+
return err
322315
}
323316
}
324317
}
325-
if v.AtLeast(clusterversion.TODO_Delete_V25_1_AddJobsColumns.Version()) {
326318

327-
vals := []interface{}{j.ID()}
319+
vals := []interface{}{j.ID()}
328320

329-
var update strings.Builder
321+
var update strings.Builder
330322

331-
if payloadBytes != nil {
332-
if beforePayload.Description != payload.Description {
333-
if update.Len() > 0 {
334-
update.WriteString(", ")
335-
}
336-
vals = append(vals, payload.Description)
337-
fmt.Fprintf(&update, "description = $%d", len(vals))
323+
if payloadBytes != nil {
324+
if beforePayload.Description != payload.Description {
325+
if update.Len() > 0 {
326+
update.WriteString(", ")
338327
}
328+
vals = append(vals, payload.Description)
329+
fmt.Fprintf(&update, "description = $%d", len(vals))
330+
}
339331

340-
if beforePayload.UsernameProto.Decode() != payload.UsernameProto.Decode() {
341-
if update.Len() > 0 {
342-
update.WriteString(", ")
343-
}
344-
vals = append(vals, payload.UsernameProto.Decode().Normalized())
345-
fmt.Fprintf(&update, "owner = $%d", len(vals))
332+
if beforePayload.UsernameProto.Decode() != payload.UsernameProto.Decode() {
333+
if update.Len() > 0 {
334+
update.WriteString(", ")
346335
}
336+
vals = append(vals, payload.UsernameProto.Decode().Normalized())
337+
fmt.Fprintf(&update, "owner = $%d", len(vals))
338+
}
347339

348-
if beforePayload.Error != payload.Error {
349-
if update.Len() > 0 {
350-
update.WriteString(", ")
351-
}
352-
vals = append(vals, payload.Error)
353-
fmt.Fprintf(&update, "error_msg = $%d", len(vals))
340+
if beforePayload.Error != payload.Error {
341+
if update.Len() > 0 {
342+
update.WriteString(", ")
354343
}
344+
vals = append(vals, payload.Error)
345+
fmt.Fprintf(&update, "error_msg = $%d", len(vals))
346+
}
355347

356-
if beforePayload.FinishedMicros != payload.FinishedMicros {
357-
if update.Len() > 0 {
358-
update.WriteString(", ")
359-
}
360-
vals = append(vals, time.UnixMicro(payload.FinishedMicros))
361-
fmt.Fprintf(&update, "finished = $%d", len(vals))
348+
if beforePayload.FinishedMicros != payload.FinishedMicros {
349+
if update.Len() > 0 {
350+
update.WriteString(", ")
362351
}
363-
352+
vals = append(vals, time.UnixMicro(payload.FinishedMicros))
353+
fmt.Fprintf(&update, "finished = $%d", len(vals))
364354
}
365-
if len(vals) > 1 {
366-
stmt := fmt.Sprintf("UPDATE system.jobs SET %s WHERE id = $1", update.String())
367-
if _, err := u.txn.ExecEx(
368-
ctx, "job-update-row", u.txn.KV(),
369-
sessiondata.NodeUserSessionDataOverride,
370-
stmt, vals...,
371-
); err != nil {
372-
return err
373-
}
355+
356+
}
357+
if len(vals) > 1 {
358+
stmt := fmt.Sprintf("UPDATE system.jobs SET %s WHERE id = $1", update.String())
359+
if _, err := u.txn.ExecEx(
360+
ctx, "job-update-row", u.txn.KV(),
361+
sessiondata.NodeUserSessionDataOverride,
362+
stmt, vals...,
363+
); err != nil {
364+
return err
374365
}
375366
}
376367

pkg/upgrade/upgrades/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ go_library(
1616
"permanent_upgrades.go",
1717
"schema_changes.go",
1818
"upgrades.go",
19-
"v25_1_add_jobs_tables.go",
2019
"v25_1_prepared_transactions_table.go",
2120
"v25_2_add_sql_activity_flush_job.go",
2221
"v25_2_set_ui_default_timezone.go",
@@ -85,7 +84,6 @@ go_test(
8584
"schema_changes_external_test.go",
8685
"schema_changes_helpers_test.go",
8786
"upgrades_test.go",
88-
"v25_1_add_jobs_tables_test.go",
8987
"v25_1_prepared_transactions_table_test.go",
9088
"v25_2_set_ui_default_timezone_test.go",
9189
"v25_3_add_event_log_column_and_index_test.go",
@@ -100,7 +98,6 @@ go_test(
10098
"//pkg/clusterversion",
10199
"//pkg/jobs",
102100
"//pkg/jobs/jobspb",
103-
"//pkg/jobs/jobstest",
104101
"//pkg/keys",
105102
"//pkg/kv",
106103
"//pkg/roachpb",
@@ -130,7 +127,6 @@ go_test(
130127
"//pkg/sql/sem/tree",
131128
"//pkg/sql/types",
132129
"//pkg/testutils",
133-
"//pkg/testutils/jobutils",
134130
"//pkg/testutils/serverutils",
135131
"//pkg/testutils/skip",
136132
"//pkg/testutils/sqlutils",

pkg/upgrade/upgrades/upgrades.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,13 @@ var upgrades = []upgradebase.Upgrade{
6161

6262
newFirstUpgrade(clusterversion.TODO_Delete_V25_1_Start.Version()),
6363

64-
upgrade.NewTenantUpgrade(
65-
"add new jobs tables",
66-
clusterversion.TODO_Delete_V25_1_AddJobsTables.Version(),
67-
upgrade.NoPrecondition,
68-
addJobsTables,
69-
upgrade.RestoreActionNotRequired("cluster restore does not restore the new field"),
70-
),
71-
7264
upgrade.NewTenantUpgrade(
7365
"create prepared_transactions table",
7466
clusterversion.TODO_Delete_V25_1_PreparedTransactionsTable.Version(),
7567
upgrade.NoPrecondition,
7668
createPreparedTransactionsTable,
7769
upgrade.RestoreActionNotRequired("cluster restore does not restore this table"),
7870
),
79-
upgrade.NewTenantUpgrade(
80-
"add new jobs tables",
81-
clusterversion.TODO_Delete_V25_1_AddJobsColumns.Version(),
82-
upgrade.NoPrecondition,
83-
addJobsColumns,
84-
upgrade.RestoreActionNotRequired("cluster restore does not restore the new field"),
85-
),
86-
upgrade.NewTenantUpgrade(
87-
"backfill new jobs tables",
88-
clusterversion.TODO_Delete_V25_1_JobsBackfill.Version(),
89-
upgrade.NoPrecondition,
90-
backfillJobsTablesAndColumns,
91-
upgrade.RestoreActionNotRequired("cluster restore does not restore jobs tables"),
92-
),
9371

9472
newFirstUpgrade(clusterversion.TODO_Delete_V25_2_Start.Version()),
9573

0 commit comments

Comments
 (0)