Skip to content

Commit

Permalink
clusterversion,kvserver,sql: remove AutoStatsTableSettings
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
celiala committed Aug 11, 2022
1 parent 9be7cf5 commit b752c83
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 86 deletions.
11 changes: 4 additions & 7 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ const (
// ClusterLocksVirtualTable enables querying the crdb_internal.cluster_locks
// virtual table, which sends a QueryLocksRequest RPC to all cluster ranges.
ClusterLocksVirtualTable
// AutoStatsTableSettings is the version where we allow auto stats related
// table settings.
AutoStatsTableSettings
// SuperRegions enables the usage on super regions.
SuperRegions
// EnableNewChangefeedOptions enables the usage of new changefeed options
Expand Down Expand Up @@ -354,6 +351,10 @@ const (
// previously referenced a < 21.2 version until that check/gate can be removed.
const TODOPreV21_2 = V21_2

// TODOPreV22_1 is an alias for V22_1 for use in any version gate/check that
// previously referenced a < 22.1 version until that check/gate can be removed.
const TODOPreV22_1 = V22_1

// versionsSingleton lists all historical versions here in chronological order,
// with comments describing what backwards-incompatible features were
// introduced.
Expand Down Expand Up @@ -486,10 +487,6 @@ var versionsSingleton = keyedVersions{
Key: ClusterLocksVirtualTable,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 98},
},
{
Key: AutoStatsTableSettings,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 100},
},
{
Key: SuperRegions,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 104},
Expand Down
61 changes: 30 additions & 31 deletions pkg/clusterversion/key_string.go

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

8 changes: 2 additions & 6 deletions pkg/kv/kvserver/allocator/allocatorimpl/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,12 +1605,8 @@ func (a *Allocator) leaseholderShouldMoveDueToPreferences(
// stores as targets) when enforcementLevel is set to storeHealthNoAction or
// storeHealthLogOnly. By default storeHealthBlockRebalanceTo is the action taken. When
// there is a mixed version cluster, storeHealthNoAction is set instead.
func (a *Allocator) StoreHealthOptions(ctx context.Context) StoreHealthOptions {
enforcementLevel := StoreHealthNoAction
if a.StorePool.St.Version.IsActive(ctx, clusterversion.AutoStatsTableSettings) {
enforcementLevel = StoreHealthEnforcement(l0SublevelsThresholdEnforce.Get(&a.StorePool.St.SV))
}

func (a *Allocator) StoreHealthOptions(_ context.Context) StoreHealthOptions {
enforcementLevel := StoreHealthEnforcement(l0SublevelsThresholdEnforce.Get(&a.StorePool.St.SV))
return StoreHealthOptions{
EnforcementLevel: enforcementLevel,
L0SublevelThreshold: l0SublevelsThreshold.Get(&a.StorePool.St.SV),
Expand Down
25 changes: 0 additions & 25 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ func (n *alterTableNode) startExec(params runParams) error {
}

case *tree.AlterTableSetStorageParams:
oldTableHasAutoStatsSettings := n.tableDesc.GetAutoStatsSettings() != nil
var ttlBefore *catpb.RowLevelTTL
if ttl := n.tableDesc.GetRowLevelTTL(); ttl != nil {
ttlBefore = protoutil.Clone(ttl).(*catpb.RowLevelTTL)
Expand All @@ -754,15 +753,7 @@ func (n *alterTableNode) startExec(params runParams) error {
return err
}

newTableHasAutoStatsSettings := n.tableDesc.GetAutoStatsSettings() != nil
if err := checkDisallowedAutoStatsSettingChange(
params, oldTableHasAutoStatsSettings, newTableHasAutoStatsSettings,
); err != nil {
return err
}

case *tree.AlterTableResetStorageParams:
oldTableHasAutoStatsSettings := n.tableDesc.GetAutoStatsSettings() != nil
var ttlBefore *catpb.RowLevelTTL
if ttl := n.tableDesc.GetRowLevelTTL(); ttl != nil {
ttlBefore = protoutil.Clone(ttl).(*catpb.RowLevelTTL)
Expand All @@ -786,13 +777,6 @@ func (n *alterTableNode) startExec(params runParams) error {
return err
}

newTableHasAutoStatsSettings := n.tableDesc.GetAutoStatsSettings() != nil
if err := checkDisallowedAutoStatsSettingChange(
params, oldTableHasAutoStatsSettings, newTableHasAutoStatsSettings,
); err != nil {
return err
}

case *tree.AlterTableRenameColumn:
descChanged, err := params.p.renameColumn(params.ctx, n.tableDesc, t.Column, t.NewName)
if err != nil {
Expand Down Expand Up @@ -1970,15 +1954,6 @@ func handleTTLStorageParamChange(
func checkDisallowedAutoStatsSettingChange(
params runParams, oldTableHasAutoStatsSettings, newTableHasAutoStatsSettings bool,
) error {
if !oldTableHasAutoStatsSettings && !newTableHasAutoStatsSettings {
// Do not have to do anything here.
return nil
}

if err := checkAutoStatsTableSettingsEnabledForCluster(params.ctx, params.p.ExecCfg().Settings); err != nil {
return err
}

return nil
}

Expand Down
16 changes: 0 additions & 16 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,12 +1467,6 @@ func NewTableDesc(
primaryIndexColumnSet[string(regionalByRowCol)] = struct{}{}
}

if autoStatsSettings := desc.GetAutoStatsSettings(); autoStatsSettings != nil {
if err := checkAutoStatsTableSettingsEnabledForCluster(ctx, st); err != nil {
return nil, err
}
}

// Create the TTL automatic column (crdb_internal_expiration) if one does not already exist.
if ttl := desc.GetRowLevelTTL(); ttl != nil && ttl.HasDurationExpr() {
if err := checkTTLEnabledForCluster(ctx, st); err != nil {
Expand Down Expand Up @@ -2442,16 +2436,6 @@ func checkTTLEnabledForCluster(ctx context.Context, st *cluster.Settings) error
return nil
}

func checkAutoStatsTableSettingsEnabledForCluster(ctx context.Context, st *cluster.Settings) error {
if !st.Version.IsActive(ctx, clusterversion.AutoStatsTableSettings) {
return pgerror.Newf(
pgcode.FeatureNotSupported,
"auto stats table settings are 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
2 changes: 1 addition & 1 deletion pkg/sql/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func TestAutoStatsTableSettingsDisallowedOnOldCluster(t *testing.T) {
sqlDB.ExpectErr(t, "pq: auto stats table settings are only available once the cluster is fully upgraded", "ALTER TABLE t2 SET (sql_stats_automatic_collection_enabled = true)")

// Run the upgrade.
sqlDB.Exec(t, "SET CLUSTER SETTING version = $1", clusterversion.ByKey(clusterversion.AutoStatsTableSettings).String())
sqlDB.Exec(t, "SET CLUSTER SETTING version = $1", clusterversion.ByKey(clusterversion.TODOPreV22_1).String())

sqlDB.Exec(t,
`CREATE TABLE t1 (a int) WITH (sql_stats_automatic_collection_enabled = true)`)
Expand Down

0 comments on commit b752c83

Please sign in to comment.