-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathmvcc_statistics_cache_migration.go
49 lines (44 loc) · 1.49 KB
/
mvcc_statistics_cache_migration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package upgrades
import (
"context"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security/username"
// Import for the side effect of registering the MVCC statistics update job.
_ "github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"github.com/cockroachdb/cockroach/pkg/upgrade"
)
func createMVCCStatisticsCacheTableAndJobMigration(
ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps,
) error {
// Create the table.
err := createSystemTable(
ctx,
d.DB.KV(),
d.Settings,
keys.SystemSQLCodec,
systemschema.SystemMVCCStatisticsCacheTable,
)
if err != nil {
return err
}
// Bake the job.
if d.TestingKnobs != nil && d.TestingKnobs.SkipMVCCStatisticsCacheJobBootstrap {
return nil
}
record := jobs.Record{
JobID: jobs.MVCCStatisticsJobID,
Description: "mvcc statistics cache update job",
Username: username.NodeUserName(),
Details: jobspb.MVCCStatisticsJobDetails{},
Progress: jobspb.MVCCStatisticsJobProgress{},
NonCancelable: true, // The job can't be canceled, but it can be paused.
}
return d.DB.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
return d.JobRegistry.CreateIfNotExistAdoptableJobWithTxn(ctx, record, txn)
})
}