Skip to content

sql: Use normal priority for metadata schema change updates#162544

Open
shghasemi wants to merge 1 commit intocockroachdb:masterfrom
shghasemi:schema-change-pri
Open

sql: Use normal priority for metadata schema change updates#162544
shghasemi wants to merge 1 commit intocockroachdb:masterfrom
shghasemi:schema-change-pri

Conversation

@shghasemi
Copy link
Contributor

Previously, all schema change updates were executed with a bulk normal priority. This had unintended side effects on overloaded systems, where trivial schema changes were unable to make progress. With this change, we only apply the low priority for operations that involve doing backfills or validation.

Fixes: #162042

Release note: None

@shghasemi shghasemi requested a review from a team as a code owner February 5, 2026 15:58
@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 5, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@blathers-crl
Copy link

blathers-crl bot commented Feb 5, 2026

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@shghasemi shghasemi requested a review from fqazi February 5, 2026 15:58
@shghasemi shghasemi self-assigned this Feb 5, 2026
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks, good one minor suggestion

@fqazi reviewed 2 files and all commit messages, and made 3 comments.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @shghasemi).


pkg/sql/schema_changer.go line 2905 at r1 (raw file):

// txn is a convenient wrapper around descs.Txn().
func (sc *SchemaChanger) txn(
	ctx context.Context, useBulkPri bool, f func(context.Context, descs.Txn) error,

Lets switch this to use the option pattern:

type txnOptions struct {  
  bulkPri bool
}  
  
type txnOption interface {  
  apply(*txnOptions)  
}

type bulkPriOption bool

bool (b bulkPriOption) apply(t *txnOptions){
    t.bulkPri = bool(b)
}

func WithBulkPri(b bool) txnOption{
 return bulkPriOption(b)
}

func (sc *SchemaChanger)  txn(
	ctx context.Context, f func(context.Context, descs.Txn), txnOptions...) {



pkg/sql/backfill.go line 155 at r1 (raw file):

) historicalTxnRunner {
	runner := func(ctx context.Context, retryable scTxnFn) error {
		return sc.fixedTimestampTxnWithExecutor(ctx, useBulkPri, readAsOf, func(

For simplicity lets exclude the fixed timestamp operations. I know we read descriptors below, but these are mainly for CREATE TABLE AS / REFRESH MATERIALIZED VIEW type backfills.

Copy link
Contributor Author

@shghasemi shghasemi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shghasemi made 2 comments.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi).


pkg/sql/backfill.go line 155 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

For simplicity lets exclude the fixed timestamp operations. I know we read descriptors below, but these are mainly for CREATE TABLE AS / REFRESH MATERIALIZED VIEW type backfills.

They are also used to run validation.

runHistoricalTxn := sc.makeFixedTimestampRunner(readAsOf)

Should we set them to always run with bulkPri?


pkg/sql/schema_changer.go line 2905 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

Lets switch this to use the option pattern:

type txnOptions struct {  
  bulkPri bool
}  
  
type txnOption interface {  
  apply(*txnOptions)  
}

type bulkPriOption bool

bool (b bulkPriOption) apply(t *txnOptions){
    t.bulkPri = bool(b)
}

func WithBulkPri(b bool) txnOption{
 return bulkPriOption(b)
}

func (sc *SchemaChanger)  txn(
	ctx context.Context, f func(context.Context, descs.Txn), txnOptions...) {


Done

Previously, all schema change updates were executed with a bulk normal priority.
This had unintended side effects on overloaded systems, where trivial schema changes
were unable to make progress. With this change, we only apply the low priority for
operations that involve doing backfills or validation.

Fixes: cockroachdb#162042

Release note: None
@shghasemi shghasemi requested a review from fqazi February 5, 2026 20:38
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@fqazi reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @shghasemi).


pkg/sql/backfill.go line 155 at r1 (raw file):

Previously, shghasemi wrote…

They are also used to run validation.

runHistoricalTxn := sc.makeFixedTimestampRunner(readAsOf)

Should we set them to always run with bulkPri?

Yeah, lets leave those at the bulk priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql/schemachanger: ensure legacy schema changes use normal priority for metadata updates

3 participants