Skip to content

Commit c0dc380

Browse files
committed
jobs: change SHOW JOBS timestamps to timestamptz
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.
1 parent 8769bec commit c0dc380

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
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/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)