Skip to content

Commit

Permalink
Merge #77267
Browse files Browse the repository at this point in the history
77267: sql: add version gating for row-level TTL r=rafiss a=otan

Release justification: fixes for new functionality

Release note: None

Co-authored-by: Oliver Tan <[email protected]>
  • Loading branch information
craig[bot] and otan committed Mar 3, 2022
2 parents 1e1d559 + 6cd626e commit dbdbb93
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host>:<port>. 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 <host>:<port>. If no port is specified, 4317 will be used.
trace.zipkin.collector string the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.
version version 21.2-86 set the active cluster version in the format '<major>.<minor>'
version version 21.2-88 set the active cluster version in the format '<major>.<minor>'
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@
<tr><td><code>trace.jaeger.agent</code></td><td>string</td><td><code></code></td><td>the address of a Jaeger agent to receive traces using the Jaeger UDP Thrift protocol, as <host>:<port>. If no port is specified, 6381 will be used.</td></tr>
<tr><td><code>trace.opentelemetry.collector</code></td><td>string</td><td><code></code></td><td>address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.</td></tr>
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>21.2-86</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>21.2-88</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
7 changes: 7 additions & 0 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions pkg/clusterversion/key_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit dbdbb93

Please sign in to comment.