Skip to content

Commit 66c9e4f

Browse files
craig[bot]dt
andcommitted
108353: jobs: change SHOW JOBS timestamps to timestamptz r=dt a=dt Release note (sql change): SHOW JOBS now returns times (created, last_run, etc) using the TimestampTZ column type instead of the Timestamp type, meaning they are now rendered using the session offset. Epic: CRDB-24406. Co-authored-by: David Taylor <[email protected]>
2 parents c5b6392 + c0dc380 commit 66c9e4f

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

pkg/jobs/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const (
132132
// NextRunClause calculates the next execution time of a job with exponential backoff delay, calculated
133133
// using last_run and num_runs values.
134134
NextRunClause = `
135-
COALESCE(last_run, created) + least(
135+
COALESCE(last_run::timestamptz, created::timestamptz) + least(
136136
IF(
137137
args.initial_delay * (power(2, least(62, COALESCE(num_runs, 0))) - 1)::FLOAT >= 0.0,
138138
args.initial_delay * (power(2, least(62, COALESCE(num_runs, 0))) - 1)::FLOAT,

pkg/jobs/jobs_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,20 @@ func TestShowJobs(t *testing.T) {
19441944
// confirmed via the job_type field, which is dependent on the details
19451945
// field.
19461946
out.details = in.details
1947+
// All the timestamps won't compare with simple == due locality, so we
1948+
// check that they are the same instant with time.Equal ourselves.
1949+
if out.created.Equal(in.created) {
1950+
out.created = in.created
1951+
}
1952+
if out.started.Equal(in.started) {
1953+
out.started = in.started
1954+
}
1955+
if out.finished.Equal(in.finished) {
1956+
out.finished = in.finished
1957+
}
1958+
if out.modified.Equal(in.modified) {
1959+
out.modified = in.modified
1960+
}
19471961

19481962
if !reflect.DeepEqual(in, out) {
19491963
diff := strings.Join(pretty.Diff(in, out), "\n")

pkg/server/admin.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,24 +3524,30 @@ func (rs resultScanner) ScanIndex(row tree.Datums, index int, dst interface{}) e
35243524
}
35253525

35263526
case *time.Time:
3527-
s, ok := src.(*tree.DTimestamp)
3528-
if !ok {
3527+
switch s := src.(type) {
3528+
case *tree.DTimestamp:
3529+
*d = s.Time
3530+
case *tree.DTimestampTZ:
3531+
*d = s.Time
3532+
default:
35293533
return errors.Errorf("source type assertion failed")
35303534
}
3531-
*d = s.Time
35323535

35333536
// Passing a **time.Time instead of a *time.Time means the source is allowed
35343537
// to be NULL, in which case nil is stored into *src.
35353538
case **time.Time:
3536-
s, ok := src.(*tree.DTimestamp)
3537-
if !ok {
3538-
if src != tree.DNull {
3539+
switch s := src.(type) {
3540+
case *tree.DTimestamp:
3541+
*d = &s.Time
3542+
case *tree.DTimestampTZ:
3543+
*d = &s.Time
3544+
default:
3545+
if src == tree.DNull {
3546+
*d = nil
3547+
} else {
35393548
return errors.Errorf("source type assertion failed")
35403549
}
3541-
*d = nil
3542-
break
35433550
}
3544-
*d = &s.Time
35453551

35463552
case *[]byte:
35473553
s, ok := src.(*tree.DBytes)

pkg/sql/crdb_internal.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ func tsOrNull(micros int64) (tree.Datum, error) {
892892
return tree.DNull, nil
893893
}
894894
ts := timeutil.Unix(0, micros*time.Microsecond.Nanoseconds())
895-
return tree.MakeDTimestamp(ts, time.Microsecond)
895+
return tree.MakeDTimestampTZ(ts, time.Microsecond)
896896
}
897897

898898
const (
@@ -1117,7 +1117,7 @@ func wrapPayloadUnMarshalError(err error, jobID tree.Datum) error {
11171117
}
11181118

11191119
const (
1120-
jobsQSelect = `SELECT id, status, created, payload, progress, claim_session_id, claim_instance_id`
1120+
jobsQSelect = `SELECT id, status, created::timestamptz, payload, progress, claim_session_id, claim_instance_id`
11211121
// Note that we are querying crdb_internal.system_jobs instead of system.jobs directly.
11221122
// The former has access control built in and will filter out jobs that the
11231123
// user is not allowed to see.
@@ -1126,7 +1126,7 @@ const (
11261126
jobsStatusFilter = ` WHERE status = $3`
11271127
oldJobsTypeFilter = ` WHERE crdb_internal.job_payload_type(payload) = $3`
11281128
jobsTypeFilter = ` WHERE job_type = $3`
1129-
jobsQuery = jobsQSelect + `, last_run, COALESCE(num_runs, 0), ` + jobs.NextRunClause +
1129+
jobsQuery = jobsQSelect + `, last_run::timestamptz, COALESCE(num_runs, 0), ` + jobs.NextRunClause +
11301130
` as next_run` + jobsQFrom + ", " + jobsBackoffArgs
11311131
)
11321132

@@ -1149,17 +1149,17 @@ CREATE TABLE crdb_internal.jobs (
11491149
descriptor_ids INT[],
11501150
status STRING,
11511151
running_status STRING,
1152-
created TIMESTAMP,
1153-
started TIMESTAMP,
1154-
finished TIMESTAMP,
1155-
modified TIMESTAMP,
1152+
created TIMESTAMPTZ,
1153+
started TIMESTAMPTZ,
1154+
finished TIMESTAMPTZ,
1155+
modified TIMESTAMPTZ,
11561156
fraction_completed FLOAT,
11571157
high_water_timestamp DECIMAL,
11581158
error STRING,
11591159
coordinator_id INT,
11601160
trace_id INT,
1161-
last_run TIMESTAMP,
1162-
next_run TIMESTAMP,
1161+
last_run TIMESTAMPTZ,
1162+
next_run TIMESTAMPTZ,
11631163
num_runs INT,
11641164
execution_errors STRING[],
11651165
execution_events JSONB,
@@ -1258,7 +1258,7 @@ func makeJobsTableRows(
12581258
// marshalled.
12591259
id = tree.NewDInt(tree.DInt(job.JobID))
12601260
status = tree.NewDString(string(jobs.StatusPending))
1261-
created = eval.TimestampToInexactDTimestamp(p.txn.ReadTimestamp())
1261+
created = tree.MustMakeDTimestampTZ(timeutil.Unix(0, p.txn.ReadTimestamp().WallTime), time.Microsecond)
12621262
progressBytes, payloadBytes, err = getPayloadAndProgressFromJobsRecord(p, job)
12631263
if err != nil {
12641264
return matched, err

0 commit comments

Comments
 (0)