-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: scaffolding for db metadata update job
This commit creates a new forever running BG job called UpdateCachedTableMetadata. This is just some scaffolding - the job doesn't do anything right now but it will be used to populate the system table storing cached table metadata used by obs surfaces. Epic: none Release note: None
- Loading branch information
Showing
17 changed files
with
182 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/jobs" | ||
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
type tableMetadataUpdateJobResumer struct { | ||
job *jobs.Job | ||
} | ||
|
||
var _ jobs.Resumer = (*tableMetadataUpdateJobResumer)(nil) | ||
|
||
// Resume is part of the jobs.Resumer interface. | ||
func (j *tableMetadataUpdateJobResumer) Resume(ctx context.Context, execCtxI interface{}) error { | ||
log.Infof(ctx, "starting table metadata update job") | ||
j.job.MarkIdle(true) | ||
|
||
<-ctx.Done() | ||
return nil | ||
} | ||
|
||
// OnFailOrCancel implements jobs.Resumer. | ||
func (j *tableMetadataUpdateJobResumer) OnFailOrCancel( | ||
ctx context.Context, execCtx interface{}, jobErr error, | ||
) error { | ||
if jobs.HasErrJobCanceled(jobErr) { | ||
err := errors.NewAssertionErrorWithWrappedErrf( | ||
jobErr, "mvcc statistics update job is not cancelable", | ||
) | ||
log.Errorf(ctx, "%v", err) | ||
} | ||
return nil | ||
} | ||
|
||
// CollectProfile implements jobs.Resumer. | ||
func (j *tableMetadataUpdateJobResumer) CollectProfile( | ||
ctx context.Context, execCtx interface{}, | ||
) error { | ||
return nil | ||
} | ||
|
||
func init() { | ||
jobs.RegisterConstructor( | ||
jobspb.TypeUpdateCachedTableMetadata, | ||
func(job *jobs.Job, settings *cluster.Settings) jobs.Resumer { | ||
return &tableMetadataUpdateJobResumer{job: job} | ||
}, jobs.DisablesTenantCostControl, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
pkg/upgrade/upgrades/permanent_create_update_cached_table_metadata_job.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
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/jobs/metricspoller" // Ensure job implementation is linked. | ||
"github.com/cockroachdb/cockroach/pkg/security/username" | ||
"github.com/cockroachdb/cockroach/pkg/sql/isql" | ||
"github.com/cockroachdb/cockroach/pkg/upgrade" | ||
) | ||
|
||
func createUpdateCachedTableMetadataJob( | ||
ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, | ||
) error { | ||
if d.TestingKnobs != nil && d.TestingKnobs.SkipUpdateCachedTableMetadataBootstrap { | ||
return nil | ||
} | ||
|
||
return d.DB.Txn(ctx, func(ctx context.Context, txn isql.Txn) error { | ||
jr := jobs.Record{ | ||
JobID: jobs.UpdateCachedTableMetadataJobID, | ||
Description: jobspb.TypeUpdateCachedTableMetadata.String(), | ||
Details: jobspb.UpdateCachedTableMetadataDetails{}, | ||
Progress: jobspb.UpdateCachedTableMetadataProgress{}, | ||
CreatedBy: &jobs.CreatedByInfo{Name: username.NodeUser, ID: username.NodeUserID}, | ||
Username: username.NodeUserName(), | ||
NonCancelable: true, | ||
} | ||
return d.JobRegistry.CreateIfNotExistAdoptableJobWithTxn(ctx, jr, txn) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.