Skip to content

Commit

Permalink
sql: Check for concurrent DSC job in legacy schema changer
Browse files Browse the repository at this point in the history
Running the legacy schema changer and the declarative schema changer
concurrently can cause issues due to their different approaches to
updating descriptors. Normally we have checks to prevent the legacy
schema changer from running in such scenarios, timing issues
persisted—particularly between `ALTER VIEW .. RENAME` (legacy) and `DROP
VIEW` (DSC). In these cases, the view rename could delete the descriptor
being processed by the drop view operation.

This change addresses the timing issue by adding a check for an active
DSC job at the start of the legacy schema changer job. With this fix,
the issue could no longer be reproduced, whereas it was consistently
reproducible before.

Epic: none
Closes: #137487
Release note (bug fix): Fixed a timing issue between `ALTER VIEW ..
RENAME` and `DROP VIEW` that caused repeated failures in the `DROP VIEW`
job.
  • Loading branch information
spilchen committed Dec 21, 2024
1 parent a80ff6a commit be6eb63
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/sql/schema_changer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/regionliveness"
"github.com/cockroachdb/cockroach/pkg/sql/regions"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -795,6 +796,13 @@ func (sc *SchemaChanger) exec(ctx context.Context) error {
if err := sc.checkForMVCCCompliantAddIndexMutations(ctx, desc); err != nil {
return err
}
// Check that the DSC is not active for this descriptor.
if catalog.HasConcurrentDeclarativeSchemaChange(desc) {
log.Infof(ctx,
"aborting legacy schema change job execution because DSC was already active for %q (%d)",
desc.GetName(), desc.GetID())
return scerrors.ConcurrentSchemaChangeError(desc)
}

log.Infof(ctx,
"schema change on %q (v%d) starting execution...",
Expand Down Expand Up @@ -3147,7 +3155,8 @@ func (sc *SchemaChanger) applyZoneConfigChangeForMutation(
func DeleteTableDescAndZoneConfig(
ctx context.Context, execCfg *ExecutorConfig, tableDesc catalog.TableDescriptor,
) error {
log.Infof(ctx, "removing table descriptor and zone config for table %d", tableDesc.GetID())
log.Infof(ctx, "removing table descriptor and zone config for table %d (has active dsc=%t)",
tableDesc.GetID(), catalog.HasConcurrentDeclarativeSchemaChange(tableDesc))
const kvTrace = false
return DescsTxn(ctx, execCfg, func(ctx context.Context, txn isql.Txn, col *descs.Collection) error {
b := txn.KV().NewBatch()
Expand Down

0 comments on commit be6eb63

Please sign in to comment.