Skip to content

Commit 01f9e61

Browse files
craig[bot]spilchen
andcommitted
Merge #137868
137868: sql: Check for concurrent DSC job in legacy schema changer r=spilchen a=spilchen 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 Closes: #137828 Release note (bug fix): Fixed a timing issue between `ALTER VIEW .. RENAME` and `DROP VIEW` that caused repeated failures in the `DROP VIEW` job. Co-authored-by: Matt Spilchen <[email protected]>
2 parents 0806ee4 + 53ee43c commit 01f9e61

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/sql/schema_changer.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
4747
"github.com/cockroachdb/cockroach/pkg/sql/regionliveness"
4848
"github.com/cockroachdb/cockroach/pkg/sql/regions"
49+
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors"
4950
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
5051
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
5152
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
@@ -798,6 +799,13 @@ func (sc *SchemaChanger) exec(ctx context.Context) (retErr error) {
798799
if err := sc.checkForMVCCCompliantAddIndexMutations(ctx, desc); err != nil {
799800
return err
800801
}
802+
// Check that the DSC is not active for this descriptor.
803+
if catalog.HasConcurrentDeclarativeSchemaChange(desc) {
804+
log.Infof(ctx,
805+
"aborting legacy schema change job execution because DSC was already active for %q (%d)",
806+
desc.GetName(), desc.GetID())
807+
return scerrors.ConcurrentSchemaChangeError(desc)
808+
}
801809

802810
log.Infof(ctx,
803811
"schema change on %q (v%d) starting execution...",
@@ -3162,7 +3170,8 @@ func (sc *SchemaChanger) applyZoneConfigChangeForMutation(
31623170
func DeleteTableDescAndZoneConfig(
31633171
ctx context.Context, execCfg *ExecutorConfig, tableDesc catalog.TableDescriptor,
31643172
) error {
3165-
log.Infof(ctx, "removing table descriptor and zone config for table %d", tableDesc.GetID())
3173+
log.Infof(ctx, "removing table descriptor and zone config for table %d (has active dsc=%t)",
3174+
tableDesc.GetID(), catalog.HasConcurrentDeclarativeSchemaChange(tableDesc))
31663175
const kvTrace = false
31673176
return DescsTxn(ctx, execCfg, func(ctx context.Context, txn isql.Txn, col *descs.Collection) error {
31683177
b := txn.KV().NewBatch()

0 commit comments

Comments
 (0)