Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/schemachanger: block legacy schema changer operations earlier #99438

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/sql/drop_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/iterutil"
Expand Down Expand Up @@ -83,6 +84,12 @@ func (n *dropSequenceNode) startExec(params runParams) error {
ctx := params.ctx
for _, toDel := range n.td {
droppedDesc := toDel.desc
// Exit early with an error if the table is undergoing a declarative schema
// change, before we try to get job IDs and update job statuses later. See
// createOrUpdateSchemaChangeJob.
if catalog.HasConcurrentDeclarativeSchemaChange(droppedDesc) {
return scerrors.ConcurrentSchemaChangeError(droppedDesc)
}
err := params.p.dropSequenceImpl(
ctx, droppedDesc, true /* queueJob */, tree.AsStringWithFQNames(n.n, params.Ann()), n.n.DropBehavior,
)
Expand Down
14 changes: 6 additions & 8 deletions pkg/sql/drop_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ func (p *planner) dropTableImpl(
behavior tree.DropBehavior,
) ([]string, error) {
var droppedViews []string

// Exit early with an error if the table is undergoing a declarative schema
// change, before we try to get job IDs and update job statuses later. See
// createOrUpdateSchemaChangeJob.
if catalog.HasConcurrentDeclarativeSchemaChange(tableDesc) {
return nil, scerrors.ConcurrentSchemaChangeError(tableDesc)
}
// Remove foreign key back references from tables that this table has foreign
// keys to.
// Copy out the set of outbound fks as it may be overwritten in the loop.
Expand Down Expand Up @@ -353,13 +358,6 @@ func (p *planner) initiateDropTable(
return errors.Errorf("table %q is already being dropped", tableDesc.Name)
}

// Exit early with an error if the table is undergoing a declarative schema
// change, before we try to get job IDs and update job statuses later. See
// createOrUpdateSchemaChangeJob.
if catalog.HasConcurrentDeclarativeSchemaChange(tableDesc) {
return scerrors.ConcurrentSchemaChangeError(tableDesc)
}

// Use the delayed GC mechanism to schedule usage of the more efficient
// ClearRange pathway.
if tableDesc.IsTable() {
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/drop_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -236,6 +237,12 @@ func (p *planner) dropViewImpl(
) ([]string, error) {
var cascadeDroppedViews []string

// Exit early with an error if the table is undergoing a declarative schema
// change, before we try to get job IDs and update job statuses later. See
// createOrUpdateSchemaChangeJob.
if catalog.HasConcurrentDeclarativeSchemaChange(viewDesc) {
return nil, scerrors.ConcurrentSchemaChangeError(viewDesc)
}
// Remove back-references from the tables/views this view depends on.
dependedOn := append([]descpb.ID(nil), viewDesc.DependsOn...)
for _, depID := range dependedOn {
Expand Down