Skip to content

Commit

Permalink
Merge pull request #137889 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.3-137868

release-24.3: sql: Check for concurrent DSC job in legacy schema changer
  • Loading branch information
spilchen authored Jan 6, 2025
2 parents 166c0af + d6939a2 commit 45e936c
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 @@ -46,6 +46,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 @@ -793,6 +794,13 @@ func (sc *SchemaChanger) exec(ctx context.Context) (retErr 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 @@ -3157,7 +3165,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 45e936c

Please sign in to comment.