From 6cd626e5a9cd83d2ef4264bfb7fc88c2e4e3d558 Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Thu, 3 Mar 2022 07:37:36 +1100 Subject: [PATCH] sql: add version gating for row-level TTL Release justification: fixes for new functionality Release note: None --- docs/generated/settings/settings-for-tenants.txt | 2 +- docs/generated/settings/settings.html | 2 +- pkg/clusterversion/cockroach_versions.go | 7 +++++++ pkg/clusterversion/key_string.go | 5 +++-- pkg/sql/alter_table.go | 4 ++++ pkg/sql/create_table.go | 14 ++++++++++++++ .../logic_test/row_level_ttl_mixed_21.2_22.1 | 10 ++++++++++ 7 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 pkg/sql/logictest/testdata/logic_test/row_level_ttl_mixed_21.2_22.1 diff --git a/docs/generated/settings/settings-for-tenants.txt b/docs/generated/settings/settings-for-tenants.txt index 763e3ed2f9ff..316c8a7e2b53 100644 --- a/docs/generated/settings/settings-for-tenants.txt +++ b/docs/generated/settings/settings-for-tenants.txt @@ -185,4 +185,4 @@ trace.debug.enable boolean false if set, traces for recent requests can be seen trace.jaeger.agent string the address of a Jaeger agent to receive traces using the Jaeger UDP Thrift protocol, as :. If no port is specified, 6381 will be used. trace.opentelemetry.collector string address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as :. If no port is specified, 4317 will be used. trace.zipkin.collector string the address of a Zipkin instance to receive traces, as :. If no port is specified, 9411 will be used. -version version 21.2-86 set the active cluster version in the format '.' +version version 21.2-88 set the active cluster version in the format '.' diff --git a/docs/generated/settings/settings.html b/docs/generated/settings/settings.html index 60eed0476a57..cf63e04656af 100644 --- a/docs/generated/settings/settings.html +++ b/docs/generated/settings/settings.html @@ -198,6 +198,6 @@ trace.jaeger.agentstringthe address of a Jaeger agent to receive traces using the Jaeger UDP Thrift protocol, as :. If no port is specified, 6381 will be used. trace.opentelemetry.collectorstringaddress of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as :. If no port is specified, 4317 will be used. trace.zipkin.collectorstringthe address of a Zipkin instance to receive traces, as :. If no port is specified, 9411 will be used. -versionversion21.2-86set the active cluster version in the format '.' +versionversion21.2-88set the active cluster version in the format '.' diff --git a/pkg/clusterversion/cockroach_versions.go b/pkg/clusterversion/cockroach_versions.go index 47fff6621176..4bedf909ef07 100644 --- a/pkg/clusterversion/cockroach_versions.go +++ b/pkg/clusterversion/cockroach_versions.go @@ -309,6 +309,9 @@ const ( // can be used to construct schema change plan node. EnableDeclarativeSchemaChanger + // RowLevelTTL is the version where we allow row level TTL tables. + RowLevelTTL + // ************************************************* // Step (1): Add new versions here. // Do not add new versions to a patch release. @@ -507,6 +510,10 @@ var versionsSingleton = keyedVersions{ Key: EnableDeclarativeSchemaChanger, Version: roachpb.Version{Major: 21, Minor: 2, Internal: 86}, }, + { + Key: RowLevelTTL, + Version: roachpb.Version{Major: 21, Minor: 2, Internal: 88}, + }, // ************************************************* // Step (2): Add new versions here. diff --git a/pkg/clusterversion/key_string.go b/pkg/clusterversion/key_string.go index ef8fcbcfdd1a..f7de307fb596 100644 --- a/pkg/clusterversion/key_string.go +++ b/pkg/clusterversion/key_string.go @@ -49,11 +49,12 @@ func _() { _ = x[ChangefeedIdleness-38] _ = x[BackupDoesNotOverwriteLatestAndCheckpoint-39] _ = x[EnableDeclarativeSchemaChanger-40] + _ = x[RowLevelTTL-41] } -const _Key_name = "V21_2Start22_1TargetBytesAvoidExcessAvoidDrainingNamesDrainingNamesMigrationTraceIDDoesntImplyStructuredRecordingAlterSystemTableStatisticsAddAvgSizeColAlterSystemStmtDiagReqsMVCCAddSSTableInsertPublicSchemaNamespaceEntryOnRestoreUnsplitRangesInAsyncGCJobsValidateGrantOptionPebbleFormatBlockPropertyCollectorProbeRequestSelectRPCsTakeTracingInfoInbandPreSeedTenantSpanConfigsSeedTenantSpanConfigsPublicSchemasWithDescriptorsEnsureSpanConfigReconciliationEnsureSpanConfigSubscriptionEnableSpanConfigStoreScanWholeRowsSCRAMAuthenticationUnsafeLossOfQuorumRecoveryRangeLogAlterSystemProtectedTimestampAddColumnEnableProtectedTimestampsForTenantDeleteCommentsWithDroppedIndexesRemoveIncompatibleDatabasePrivilegesAddRaftAppliedIndexTermMigrationPostAddRaftAppliedIndexTermMigrationDontProposeWriteTimestampForLeaseTransfersTenantSettingsTableEnablePebbleFormatVersionBlockPropertiesDisableSystemConfigGossipTriggerMVCCIndexBackfillerEnableLeaseHolderRemovalBackupResolutionInJobLooselyCoupledRaftLogTruncationChangefeedIdlenessBackupDoesNotOverwriteLatestAndCheckpointEnableDeclarativeSchemaChanger" +const _Key_name = "V21_2Start22_1TargetBytesAvoidExcessAvoidDrainingNamesDrainingNamesMigrationTraceIDDoesntImplyStructuredRecordingAlterSystemTableStatisticsAddAvgSizeColAlterSystemStmtDiagReqsMVCCAddSSTableInsertPublicSchemaNamespaceEntryOnRestoreUnsplitRangesInAsyncGCJobsValidateGrantOptionPebbleFormatBlockPropertyCollectorProbeRequestSelectRPCsTakeTracingInfoInbandPreSeedTenantSpanConfigsSeedTenantSpanConfigsPublicSchemasWithDescriptorsEnsureSpanConfigReconciliationEnsureSpanConfigSubscriptionEnableSpanConfigStoreScanWholeRowsSCRAMAuthenticationUnsafeLossOfQuorumRecoveryRangeLogAlterSystemProtectedTimestampAddColumnEnableProtectedTimestampsForTenantDeleteCommentsWithDroppedIndexesRemoveIncompatibleDatabasePrivilegesAddRaftAppliedIndexTermMigrationPostAddRaftAppliedIndexTermMigrationDontProposeWriteTimestampForLeaseTransfersTenantSettingsTableEnablePebbleFormatVersionBlockPropertiesDisableSystemConfigGossipTriggerMVCCIndexBackfillerEnableLeaseHolderRemovalBackupResolutionInJobLooselyCoupledRaftLogTruncationChangefeedIdlenessBackupDoesNotOverwriteLatestAndCheckpointEnableDeclarativeSchemaChangerRowLevelTTL" -var _Key_index = [...]uint16{0, 5, 14, 36, 54, 76, 113, 152, 175, 189, 230, 256, 275, 309, 321, 352, 376, 397, 425, 455, 483, 504, 517, 536, 570, 608, 642, 674, 710, 742, 778, 820, 839, 879, 911, 930, 954, 975, 1006, 1024, 1065, 1095} +var _Key_index = [...]uint16{0, 5, 14, 36, 54, 76, 113, 152, 175, 189, 230, 256, 275, 309, 321, 352, 376, 397, 425, 455, 483, 504, 517, 536, 570, 608, 642, 674, 710, 742, 778, 820, 839, 879, 911, 930, 954, 975, 1006, 1024, 1065, 1095, 1106} func (i Key) String() string { if i < 0 || i >= Key(len(_Key_index)-1) { diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index d19d81fb7eec..0a9c37ca1aa2 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -1865,6 +1865,10 @@ func handleTTLStorageParamChange( } } case before == nil && after != nil: + if err := checkTTLEnabledForCluster(params.ctx, params.p.ExecCfg().Settings); err != nil { + return err + } + // Adding a TTL requires adding the automatic column and deferring the TTL // addition to after the column is successfully added. tableDesc.RowLevelTTL = nil diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index aa25162b61f6..6a6795ce89e1 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -19,6 +19,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/build" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/docs" "github.com/cockroachdb/cockroach/pkg/geo/geoindex" "github.com/cockroachdb/cockroach/pkg/jobs" @@ -1442,6 +1443,9 @@ func NewTableDesc( // Create the TTL column if one does not already exist. if ttl := desc.GetRowLevelTTL(); ttl != nil { + if err := checkTTLEnabledForCluster(ctx, st); err != nil { + return nil, err + } hasRowLevelTTLColumn := false for _, def := range n.Defs { switch def := def.(type) { @@ -2390,6 +2394,16 @@ func rowLevelTTLSchedule(ttl *catpb.RowLevelTTL) string { return defaultTTLScheduleCron } +func checkTTLEnabledForCluster(ctx context.Context, st *cluster.Settings) error { + if !st.Version.IsActive(ctx, clusterversion.RowLevelTTL) { + return pgerror.Newf( + pgcode.FeatureNotSupported, + "row level TTL is only available once the cluster is fully upgraded", + ) + } + return nil +} + // CreateRowLevelTTLScheduledJob creates a new row-level TTL schedule. func CreateRowLevelTTLScheduledJob( ctx context.Context, diff --git a/pkg/sql/logictest/testdata/logic_test/row_level_ttl_mixed_21.2_22.1 b/pkg/sql/logictest/testdata/logic_test/row_level_ttl_mixed_21.2_22.1 new file mode 100644 index 000000000000..e1538100aade --- /dev/null +++ b/pkg/sql/logictest/testdata/logic_test/row_level_ttl_mixed_21.2_22.1 @@ -0,0 +1,10 @@ +# LogicTest: local-mixed-21.2-22.1 + +statement error row level TTL is only available once the cluster is fully upgraded +CREATE TABLE tbl () WITH (ttl_expire_after = '10 minutes') + +statement ok +CREATE TABLE tbl () + +statement error row level TTL is only available once the cluster is fully upgraded +ALTER TABLE tbl SET (ttl_expire_after = '10 minutes')