Skip to content

Commit

Permalink
Merge pull request cockroachdb#71477 from ajwerner/ajwerner/release-2…
Browse files Browse the repository at this point in the history
…1.2-hot-fix

release-21.2: clusterversion,migration: combine migrations for new stats tables
  • Loading branch information
ajwerner authored Oct 12, 2021
2 parents 5377f3d + 7da7d09 commit e67cf96
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 70 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 @@ -166,4 +166,4 @@ trace.datadog.project string CockroachDB the project under which traces will be
trace.debug.enable boolean false if set, traces for recent requests can be seen at https://<ui>/debug/requests
trace.lightstep.token string if set, traces go to Lightstep using this token
trace.zipkin.collector string if set, traces go to the given Zipkin instance (example: '127.0.0.1:9411'). Only one tracer can be configured at a time.
version version 21.1-1168 set the active cluster version in the format '<major>.<minor>'
version version 21.1-1172 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 @@ -171,6 +171,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 at https://<ui>/debug/requests</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'). Only one tracer can be configured at a time.</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>21.1-1168</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.1-1172</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
30 changes: 15 additions & 15 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ const (
DeleteDeprecatedNamespaceTableDescriptorMigration
// FixDescriptors is for the migration to fix all descriptors.
FixDescriptors
// SQLStatsTable adds the system tables for storing persisted SQL statistics
// for statements and transactions.
SQLStatsTable
// DatabaseRoleSettings adds the system table for storing per-user and
// per-role default session settings.
DatabaseRoleSettings
Expand Down Expand Up @@ -268,10 +265,6 @@ const (
SpanConfigurationsTable
// BoundedStaleness adds capabilities to perform bounded staleness reads.
BoundedStaleness
// SQLStatsCompactionScheduledJob creates a ScheduledJob for SQL Stats
// compaction on cluster startup and ensures that there is only one entry for
// the schedule.
SQLStatsCompactionScheduledJob
// DateAndIntervalStyle enables DateStyle and IntervalStyle to be changed.
DateAndIntervalStyle
// PebbleFormatVersioned ratchets Pebble's format major version to
Expand All @@ -288,6 +281,13 @@ const (
// TenantUsageSingleConsumptionColumn changes the tenant_usage system table to
// use a single consumption column (encoding a proto).
TenantUsageSingleConsumptionColumn
// SQLStatsTables adds the system table for storing persisted SQL statistics
// for statements.
SQLStatsTables
// SQLStatsCompactionScheduledJob creates a ScheduledJob for SQL Stats
// compaction on cluster startup and ensures that there is only one entry for
// the schedule.
SQLStatsCompactionScheduledJob

// *************************************************
// Step (1): Add new versions here.
Expand Down Expand Up @@ -382,10 +382,6 @@ var versionsSingleton = keyedVersions{
Key: FixDescriptors,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1114},
},
{
Key: SQLStatsTable,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1116},
},
{
Key: DatabaseRoleSettings,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1118},
Expand Down Expand Up @@ -465,10 +461,6 @@ var versionsSingleton = keyedVersions{
Key: BoundedStaleness,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1156},
},
{
Key: SQLStatsCompactionScheduledJob,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1158},
},
{
Key: DateAndIntervalStyle,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1160},
Expand All @@ -489,6 +481,14 @@ var versionsSingleton = keyedVersions{
Key: TenantUsageSingleConsumptionColumn,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1168},
},
{
Key: SQLStatsTables,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1170},
},
{
Key: SQLStatsCompactionScheduledJob,
Version: roachpb.Version{Major: 21, Minor: 1, Internal: 1172},
},
// *************************************************
// Step (2): Add new versions here.
// Do not add new versions to a patch release.
Expand Down
58 changes: 29 additions & 29 deletions pkg/clusterversion/key_string.go

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

22 changes: 10 additions & 12 deletions pkg/migration/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/migration"
"github.com/cockroachdb/errors"
)

// GetMigration returns the migration corresponding to this version if
Expand Down Expand Up @@ -72,18 +73,6 @@ var migrations = []migration.Migration{
NoPrecondition,
fixDescriptorMigration,
),
migration.NewTenantMigration(
"add the system.sql_statement_stats table",
toCV(clusterversion.SQLStatsTable),
NoPrecondition,
sqlStatementStatsTableMigration,
),
migration.NewTenantMigration(
"add the system.sql_transaction_stats table",
toCV(clusterversion.SQLStatsTable),
NoPrecondition,
sqlTransactionStatsTableMigration,
),
migration.NewTenantMigration(
"add the system.database_role_settings table",
toCV(clusterversion.DatabaseRoleSettings),
Expand Down Expand Up @@ -145,10 +134,19 @@ var migrations = []migration.Migration{
NoPrecondition,
tenantUsageSingleConsumptionColumn,
),
migration.NewTenantMigration(
"add the system.statement_statistics and system.transaction_statistics tables",
toCV(clusterversion.SQLStatsTables),
NoPrecondition,
sqlStatsTablesMigration,
),
}

func init() {
for _, m := range migrations {
if _, exists := registry[m.ClusterVersion()]; exists {
panic(errors.AssertionFailedf("duplicate migration registration for %v", m.ClusterVersion()))
}
registry[m.ClusterVersion()] = m
}
}
Expand Down
25 changes: 13 additions & 12 deletions pkg/migration/migrations/sql_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ import (
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/migration"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
"github.com/cockroachdb/cockroach/pkg/startupmigrations"
)

func sqlStatementStatsTableMigration(
func sqlStatsTablesMigration(
ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job,
) error {
return startupmigrations.CreateSystemTable(
ctx, d.DB, d.Codec, d.Settings, systemschema.StatementStatisticsTable,
)
}

func sqlTransactionStatsTableMigration(
ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job,
) error {
return startupmigrations.CreateSystemTable(
ctx, d.DB, d.Codec, d.Settings, systemschema.TransactionStatisticsTable,
)
for _, tab := range []catalog.TableDescriptor{
systemschema.StatementStatisticsTable,
systemschema.TransactionStatisticsTable,
} {
if err := startupmigrations.CreateSystemTable(
ctx, d.DB, d.Codec, d.Settings, tab,
); err != nil {
return err
}
}
return nil
}

0 comments on commit e67cf96

Please sign in to comment.