-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: descriptor validation overhaul #60775
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ import ( | |
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/security" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" | ||
|
@@ -219,8 +218,7 @@ func (n *alterDatabaseAddRegionNode) startExec(params runParams) error { | |
|
||
// Validate the type descriptor after the changes. We have to do this explicitly here, because | ||
// we're using an internal call to addEnumValue above which doesn't perform validation. | ||
dg := catalogkv.NewOneLevelUncachedDescGetter(params.p.txn, params.ExecCfg().Codec) | ||
if err := typeDesc.Validate(params.ctx, dg); err != nil { | ||
if err := validateDescriptor(params.ctx, params.p, typeDesc); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This convenience function is defined in planner.go: https://github.com/cockroachdb/cockroach/pull/60775/files#diff-d4a3b2d400fd963e130106b8942783b2abbf757310a2f3904ace7cc5dc4052bfR794f |
||
return err | ||
} | ||
|
||
|
@@ -522,12 +520,6 @@ func (n *alterDatabasePrimaryRegionNode) switchPrimaryRegion(params runParams) e | |
return err | ||
} | ||
|
||
// Validate the type descriptor after the changes. | ||
dg := catalogkv.NewOneLevelUncachedDescGetter(params.p.txn, params.ExecCfg().Codec) | ||
if err := typeDesc.Validate(params.ctx, dg); err != nil { | ||
return err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I believe this was made redundant by validation-on-write. |
||
// Update the database's zone configuration. | ||
if err := ApplyZoneConfigFromDatabaseRegionConfig( | ||
params.ctx, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ import ( | |
"github.com/cockroachdb/cockroach/pkg/security" | ||
"github.com/cockroachdb/cockroach/pkg/server/telemetry" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr" | ||
|
@@ -281,7 +280,7 @@ func (n *alterTableNode) startExec(params runParams) error { | |
case *tree.CheckConstraintTableDef: | ||
var err error | ||
params.p.runWithOptions(resolveFlags{contextDatabaseID: n.tableDesc.ParentID}, func() { | ||
info, infoErr := n.tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, infoErr := n.tableDesc.GetConstraintInfo() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I changed the signatures of GetConstraintInfo and associated methods to cut down on passing nil DescGetters. https://github.com/cockroachdb/cockroach/pull/60775/files#diff-e971105bc05467ef391df9792202d3a8b712d269b5f193a0d94b700414ef281eL180 |
||
if infoErr != nil { | ||
err = infoErr | ||
return | ||
|
@@ -663,14 +662,13 @@ func (n *alterTableNode) startExec(params runParams) error { | |
return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, | ||
"column %q in the middle of being added, try again later", t.Column) | ||
} | ||
if err := n.tableDesc.Validate( | ||
params.ctx, catalogkv.NewOneLevelUncachedDescGetter(params.p.Txn(), params.ExecCfg().Codec), | ||
); err != nil { | ||
|
||
if err := validateDescriptor(params.ctx, params.p, n.tableDesc); err != nil { | ||
return err | ||
} | ||
|
||
case *tree.AlterTableDropConstraint: | ||
info, err := n.tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, err := n.tableDesc.GetConstraintInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -692,14 +690,12 @@ func (n *alterTableNode) startExec(params runParams) error { | |
return err | ||
} | ||
descriptorChanged = true | ||
if err := n.tableDesc.Validate( | ||
params.ctx, catalogkv.NewOneLevelUncachedDescGetter(params.p.Txn(), params.ExecCfg().Codec), | ||
); err != nil { | ||
if err := validateDescriptor(params.ctx, params.p, n.tableDesc); err != nil { | ||
return err | ||
} | ||
|
||
case *tree.AlterTableValidateConstraint: | ||
info, err := n.tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, err := n.tableDesc.GetConstraintInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -889,7 +885,7 @@ func (n *alterTableNode) startExec(params runParams) error { | |
descriptorChanged = descriptorChanged || descChanged | ||
|
||
case *tree.AlterTableRenameConstraint: | ||
info, err := n.tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, err := n.tableDesc.GetConstraintInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -1106,7 +1102,7 @@ func applyColumnMutation( | |
} | ||
} | ||
|
||
info, err := tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, err := tableDesc.GetConstraintInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -1141,7 +1137,7 @@ func applyColumnMutation( | |
"constraint in the middle of being dropped") | ||
} | ||
} | ||
info, err := tableDesc.GetConstraintInfo(params.ctx, nil) | ||
info, err := tableDesc.GetConstraintInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ import ( | |
"fmt" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/kv" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
|
@@ -135,7 +134,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityGlobalToRegionalByTable( | |
|
||
// Finalize the alter by writing a new table descriptor and updating the zone | ||
// configuration. | ||
if err := n.validateAndWriteNewTableLocalityAndZoneConfig( | ||
if err := n.writeNewTableLocalityAndZoneConfig( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: validation made implicit by validate-on-write. |
||
params, | ||
n.dbDesc, | ||
); err != nil { | ||
|
@@ -167,7 +166,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityRegionalByTableToGlobal( | |
|
||
// Finalize the alter by writing a new table descriptor and updating the zone | ||
// configuration. | ||
if err := n.validateAndWriteNewTableLocalityAndZoneConfig( | ||
if err := n.writeNewTableLocalityAndZoneConfig( | ||
params, | ||
n.dbDesc, | ||
); err != nil { | ||
|
@@ -208,7 +207,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityRegionalByTableToRegionalB | |
} | ||
|
||
// Finalize the alter by writing a new table descriptor and updating the zone configuration. | ||
if err := n.validateAndWriteNewTableLocalityAndZoneConfig( | ||
if err := n.writeNewTableLocalityAndZoneConfig( | ||
params, | ||
n.dbDesc, | ||
); err != nil { | ||
|
@@ -539,21 +538,11 @@ func (n *alterTableSetLocalityNode) startExec(params runParams) error { | |
}) | ||
} | ||
|
||
// validateAndWriteNewTableLocalityAndZoneConfig validates the newly updated | ||
// LocalityConfig in a table descriptor, writes that table descriptor, and | ||
// writes a new zone configuration for the given table. | ||
func (n *alterTableSetLocalityNode) validateAndWriteNewTableLocalityAndZoneConfig( | ||
// writeNewTableLocalityAndZoneConfig writes the table descriptor with the newly | ||
// updated LocalityConfig and writes a new zone configuration for the table. | ||
func (n *alterTableSetLocalityNode) writeNewTableLocalityAndZoneConfig( | ||
params runParams, dbDesc *dbdesc.Immutable, | ||
) error { | ||
// Validate the new locality before updating the table descriptor. | ||
dg := catalogkv.NewOneLevelUncachedDescGetter(params.p.txn, params.EvalContext().Codec) | ||
if err := n.tableDesc.ValidateTableLocalityConfig( | ||
params.ctx, | ||
dg, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
// Write out the table descriptor update. | ||
if err := params.p.writeSchemaChange( | ||
params.ctx, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,12 +126,6 @@ func (n *alterTypeNode) startExec(params runParams) error { | |
return err | ||
} | ||
|
||
// Validate the type descriptor after the changes. | ||
dg := catalogkv.NewOneLevelUncachedDescGetter(params.p.txn, params.ExecCfg().Codec) | ||
if err := n.desc.Validate(params.ctx, dg); err != nil { | ||
return err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: validation made implicit by validate-on-write. |
||
if !eventLogDone { | ||
// Write a log event. | ||
if err := params.p.logEvent(params.ctx, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I'm effectively reverting dd90439, that framework is not actually used in any way.