Skip to content

Commit 2f2800e

Browse files
craig[bot]rafiss
andcommitted
Merge #159276
159276: schemachanger: support metadata-only TTL parameters and ttl_job_cron r=rafiss a=rafiss See individual commits. ### schemachanger: handle basic TTL params The builder was updated so that it modifies the scpb.RowLevelTTL element for when handling TTL storage params. This is needed so that we can do proper validation on the TTL params, since the validation logic checks dependencies between different parameters. The UpsertRowLevelTTL immediate mutation takes care of modifying the descriptor. Logic was also needed to avoid dropping the TTL schedule if we are modifying parameters. ### schemachanger: support ttl_job_cron parameter in declarative schema changer Previously, modifying the ttl_job_cron storage parameter required falling back to the legacy schema changer because the declarative schema changer had no mechanism to update the TTL scheduled job's cron expression. This commit adds support for ttl_job_cron by: 1. Adding UpdateTTLScheduleCron as a new deferred mutation operation that updates the cron expression on the existing TTL scheduled job. 2. Implementing findOldTTLCron in opgen to detect when the cron expression has changed by comparing the new RowLevelTTL element against the one being dropped, emitting UpdateTTLScheduleCron only when necessary. 3. Adding UpdateTTLScheduleCron to metadataUpdater which loads the scheduled job, updates its cron expression, and persists the change. informs: #122379 Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents eeef8a1 + bcf17ec commit 2f2800e

31 files changed

+562
-175
lines changed

pkg/sql/GEMINI.md

Lines changed: 0 additions & 147 deletions
This file was deleted.

pkg/sql/alter_table.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,6 @@ func (n *alterTableNode) startExec(params runParams) error {
768768
return err
769769
}
770770

771-
paramIsDelete := t.StorageParams.GetVal("ttl_delete_rate_limit") != nil
772-
paramIsSelect := t.StorageParams.GetVal("ttl_select_rate_limit") != nil
773-
774-
if paramIsDelete || paramIsSelect {
775-
printTTLRateLimitNotice(params.ctx, params.p)
776-
}
777-
778771
case *tree.AlterTableResetStorageParams:
779772
setter := tablestorageparam.NewSetter(n.tableDesc, false /* isNewObject */)
780773
if err := storageparam.Reset(

pkg/sql/create_table.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,13 +1431,6 @@ func NewTableDesc(
14311431
return nil, err
14321432
}
14331433

1434-
paramIsDelete := n.StorageParams.GetVal("ttl_delete_rate_limit") != nil
1435-
paramIsSelect := n.StorageParams.GetVal("ttl_select_rate_limit") != nil
1436-
1437-
if paramIsDelete || paramIsSelect {
1438-
printTTLRateLimitNotice(ctx, evalCtx.ClientNoticeSender)
1439-
}
1440-
14411434
setter.TableDesc.RowLevelTTL = setter.UpdatedRowLevelTTL
14421435

14431436
indexEncodingVersion := descpb.StrictIndexColumnIDGuaranteesVersion

pkg/sql/descmetadata/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ go_library(
66
importpath = "github.com/cockroachdb/cockroach/pkg/sql/descmetadata",
77
visibility = ["//visibility:public"],
88
deps = [
9+
"//pkg/jobs",
910
"//pkg/jobs/jobspb",
1011
"//pkg/keys",
12+
"//pkg/scheduledjobs",
1113
"//pkg/settings",
1214
"//pkg/sql/catalog",
1315
"//pkg/sql/catalog/descpb",

pkg/sql/descmetadata/metadata_updater.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"context"
1010
"fmt"
1111

12+
"github.com/cockroachdb/cockroach/pkg/jobs"
1213
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1314
"github.com/cockroachdb/cockroach/pkg/keys"
15+
"github.com/cockroachdb/cockroach/pkg/scheduledjobs"
1416
"github.com/cockroachdb/cockroach/pkg/settings"
1517
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1618
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
@@ -113,3 +115,19 @@ func (mu metadataUpdater) UpdateTTLScheduleLabel(
113115
)
114116
return err
115117
}
118+
119+
// UpdateTTLScheduleCron implement scexec.DescriptorMetadataUpdater.
120+
func (mu metadataUpdater) UpdateTTLScheduleCron(
121+
ctx context.Context, scheduleID jobspb.ScheduleID, cronExpr string,
122+
) error {
123+
env := scheduledjobs.ProdJobSchedulerEnv
124+
schedules := jobs.ScheduledJobTxn(mu.txn)
125+
s, err := schedules.Load(ctx, env, scheduleID)
126+
if err != nil {
127+
return err
128+
}
129+
if err := s.SetScheduleAndNextRun(cronExpr); err != nil {
130+
return err
131+
}
132+
return schedules.Update(ctx, s)
133+
}

0 commit comments

Comments
 (0)