Skip to content

Commit

Permalink
sql: forbid TIMETZ during mixed 19.2/20.1 node clusters
Browse files Browse the repository at this point in the history
Release note (bug fix): This PR fixes a bug preventing clusters from
creating TIMETZ columns before they accept 20.1 without downgrading.
  • Loading branch information
otan committed Apr 7, 2020
1 parent 6cbde81 commit af1a68d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@
<tr><td><code>trace.debug.enable</code></td><td>boolean</td><td><code>false</code></td><td>if set, traces for recent requests can be seen in the /debug page</td></tr>
<tr><td><code>trace.lightstep.token</code></td><td>string</td><td><code></code></td><td>if set, traces go to Lightstep using this token</td></tr>
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>if set, traces go to the given Zipkin instance (example: '127.0.0.1:9411'); ignored if trace.lightstep.token is set</td></tr>
<tr><td><code>version</code></td><td>custom validation</td><td><code>19.2-16</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
<tr><td><code>version</code></td><td>custom validation</td><td><code>19.2-17</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
6 changes: 6 additions & 0 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
VersionStatementDiagnosticsSystemTables
VersionSchemaChangeJob
VersionSavepoints
VersionTimeTZType

// Add new versions here (step one of two).
)
Expand Down Expand Up @@ -444,6 +445,11 @@ var versionsSingleton = keyedVersions([]keyedVersion{
Key: VersionSavepoints,
Version: roachpb.Version{Major: 19, Minor: 2, Unstable: 16},
},
{
// VersionTimeTZType enables the use of the TimeTZ data type.
Key: VersionTimeTZType,
Version: roachpb.Version{Major: 19, Minor: 2, Unstable: 17},
},
// Add new versions here (step two of two).

})
Expand Down
5 changes: 3 additions & 2 deletions pkg/clusterversion/versionkey_string.go

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

17 changes: 17 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ func (n *alterTableNode) startExec(params runParams) error {
return unimplemented.NewWithIssue(32917,
"adding a REFERENCES constraint while also adding a column via ALTER not supported")
}
version := params.ExecCfg().Settings.Version.ActiveVersionOrEmpty(params.ctx)
if !isTypeSupportedInVersion(version, d.Type) {
return pgerror.Newf(
pgcode.FeatureNotSupported,
"type %s is not supported until version upgrade is finalized",
d.Type.SQLString(),
)
}

newDef, seqDbDesc, seqName, seqOpts, err := params.p.processSerialInColumnDef(params.ctx, d, tn)
if err != nil {
Expand Down Expand Up @@ -870,6 +878,15 @@ func applyColumnMutation(
case *tree.AlterTableAlterColumnType:
typ := t.ToType

version := params.ExecCfg().Settings.Version.ActiveVersionOrEmpty(params.ctx)
if !isTypeSupportedInVersion(version, typ) {
return pgerror.Newf(
pgcode.FeatureNotSupported,
"type %s is not supported until version upgrade is finalized",
typ.SQLString(),
)
}

// Special handling for STRING COLLATE xy to verify that we recognize the language.
if t.Collation != "" {
if types.IsStringType(typ) {
Expand Down
22 changes: 22 additions & 0 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ var storageParamExpectedTypes = map[string]storageParamType{
`user_catalog_table`: storageParamUnimplemented,
}

// minimumTypeUsageVersions defines the minimum version needed for a new
// data type.
var minimumTypeUsageVersions = map[types.Family]clusterversion.VersionKey{
types.TimeTZFamily: clusterversion.VersionTimeTZType,
}

// isTypeSupportedInVersion returns whether a given type is supported in the given version.
func isTypeSupportedInVersion(v clusterversion.ClusterVersion, t *types.T) bool {
minVersion, ok := minimumTypeUsageVersions[t.Family()]
if !ok {
return true
}
return v.IsActive(minVersion)
}

// ReadingOwnWrites implements the planNodeReadingOwnWrites interface.
// This is because CREATE TABLE performs multiple KV operations on descriptors
// and expects to see its own writes.
Expand Down Expand Up @@ -1238,6 +1253,13 @@ func MakeTableDesc(
)
}
}
if !isTypeSupportedInVersion(version, d.Type) {
return desc, pgerror.Newf(
pgcode.FeatureNotSupported,
"type %s is not supported until version upgrade is finalized",
d.Type.SQLString(),
)
}
if d.PrimaryKey.Sharded {
// This function can sometimes be called when `st` is nil,
// and also before the version has been initialized. We only
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_table_mixed_19.2_20.1
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,17 @@ ALTER TABLE t RENAME COLUMN b TO c

statement error schema change cannot be initiated in this version until the version upgrade is finalized
ALTER TABLE t RENAME TO s

subtest regression_47110

statement error type TIMETZ is not supported until version upgrade is finalized
CREATE TABLE regression_47110(a TIMETZ)

statement ok
CREATE TABLE regression_47110(a TIME)

statement error type TIMETZ is not supported until version upgrade is finalized
ALTER TABLE regression_47110 ADD COLUMN b TIMETZ

statement error type TIMETZ is not supported until version upgrade is finalized
ALTER TABLE regression_47110 ALTER a SET DATA TYPE timetz

0 comments on commit af1a68d

Please sign in to comment.