Skip to content

Commit

Permalink
Merge #80221
Browse files Browse the repository at this point in the history
80221: sql: show ttl_job_cron if ttl_job_cron is not explicitly set r=rafiss a=otan

Resolves #80215

Release note (sql change): ttl_job_cron is now displayed on SHOW CREATE
TABLE and `reloptions` by default.

Co-authored-by: Oliver Tan <[email protected]>
  • Loading branch information
craig[bot] and otan committed Apr 21, 2022
2 parents 8a45881 + b3f3b03 commit 3553a79
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 78 deletions.
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/testdata/backup-restore/row_level_ttl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down Expand Up @@ -72,7 +72,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down Expand Up @@ -109,7 +109,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ func handleTTLStorageParamChange(
if err != nil {
return err
}
if err := s.SetSchedule(rowLevelTTLSchedule(after)); err != nil {
if err := s.SetSchedule(after.DeletionCronOrDefault()); err != nil {
return err
}
if err := s.Update(params.ctx, params.ExecCfg().InternalExecutor, params.p.txn); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/catalog/catpb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_library(
"job_id.go",
"multiregion.go",
"privilege.go",
"ttl.go",
":gen-privilegedescversion-stringer", # keep
],
embed = [":catpb_go_proto"],
Expand Down
19 changes: 19 additions & 0 deletions pkg/sql/catalog/catpb/ttl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package catpb

// DeletionCronOrDefault returns the DeletionCron or the global default.
func (m *RowLevelTTL) DeletionCronOrDefault() string {
if override := m.DeletionCron; override != "" {
return override
}
return "@hourly"
}
4 changes: 1 addition & 3 deletions pkg/sql/catalog/tabledesc/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -2558,15 +2558,13 @@ func (desc *wrapper) GetStorageParams(spaceBetweenEqual bool) []string {
appendStorageParam(`ttl`, `'on'`)
appendStorageParam(`ttl_automatic_column`, `'on'`)
appendStorageParam(`ttl_expire_after`, string(ttl.DurationExpr))
appendStorageParam(`ttl_job_cron`, fmt.Sprintf(`'%s'`, ttl.DeletionCronOrDefault()))
if bs := ttl.SelectBatchSize; bs != 0 {
appendStorageParam(`ttl_select_batch_size`, fmt.Sprintf(`%d`, bs))
}
if bs := ttl.DeleteBatchSize; bs != 0 {
appendStorageParam(`ttl_delete_batch_size`, fmt.Sprintf(`%d`, bs))
}
if cron := ttl.DeletionCron; cron != "" {
appendStorageParam(`ttl_job_cron`, fmt.Sprintf(`'%s'`, cron))
}
if rc := ttl.RangeConcurrency; rc != 0 {
appendStorageParam(`ttl_range_concurrency`, fmt.Sprintf(`%d`, rc))
}
Expand Down
14 changes: 1 addition & 13 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2358,11 +2358,6 @@ func newTableDesc(
return ret, nil
}

// defaultTTLScheduleCron is the default cron duration for row-level TTL.
// defaultTTLScheduleCron cannot be a cluster setting as this would involve
// changing all existing schedules to match the new setting.
const defaultTTLScheduleCron = "@hourly"

// newRowLevelTTLScheduledJob returns a *jobs.ScheduledJob for row level TTL
// for a given table.
func newRowLevelTTLScheduledJob(
Expand All @@ -2380,7 +2375,7 @@ func newRowLevelTTLScheduledJob(
OnError: jobspb.ScheduleDetails_RETRY_SCHED,
})

if err := sj.SetSchedule(rowLevelTTLSchedule(ttl)); err != nil {
if err := sj.SetSchedule(ttl.DeletionCronOrDefault()); err != nil {
return nil, err
}
args := &catpb.ScheduledRowLevelTTLArgs{
Expand All @@ -2397,13 +2392,6 @@ func newRowLevelTTLScheduledJob(
return sj, nil
}

func rowLevelTTLSchedule(ttl *catpb.RowLevelTTL) string {
if override := ttl.DeletionCron; override != "" {
return override
}
return defaultTTLScheduleCron
}

func checkTTLEnabledForCluster(ctx context.Context, st *cluster.Settings) error {
if !st.Version.IsActive(ctx, clusterversion.RowLevelTTL) {
return pgerror.Newf(
Expand Down
Loading

0 comments on commit 3553a79

Please sign in to comment.