Skip to content

Commit

Permalink
sql: fix flake in schemachange.TestWorkload
Browse files Browse the repository at this point in the history
As soon as cockroachdb#79580 merged, it tickled flakes. These flakes were caused by
operations to alter the database which would build new mutable tables from
immutable tables and thus overwrite existing entries.

The test is very flakey without this patch.

Release note: None
  • Loading branch information
ajwerner committed Apr 8, 2022
1 parent d53a4c0 commit ea992fa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/sql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,28 @@ func (p *planner) forEachMutableTableInDatabase(
return err
}

// TODO(ajwerner): Rewrite this to not use the internalLookupCtx.
lCtx := newInternalLookupCtx(all.OrderedDescriptors(), dbDesc)
var droppedRemoved []descpb.ID
for _, tbID := range lCtx.tbIDs {
desc := lCtx.tbDescs[tbID]
if desc.Dropped() {
continue
}
mutable := tabledesc.NewBuilder(desc.TableDesc()).BuildExistingMutableTable()
schemaName, found, err := lCtx.GetSchemaName(ctx, desc.GetParentSchemaID(), desc.GetParentID(), p.ExecCfg().Settings.Version)
droppedRemoved = append(droppedRemoved, tbID)
}
descs, err := p.Descriptors().GetMutableDescriptorsByID(ctx, p.Txn(), droppedRemoved...)
if err != nil {
return err
}
for _, d := range descs {
mutable := d.(*tabledesc.Mutable)
schemaName, found, err := lCtx.GetSchemaName(ctx, d.GetParentSchemaID(), d.GetParentID(), p.ExecCfg().Settings.Version)
if err != nil {
return err
}
if !found {
return errors.AssertionFailedf("schema id %d not found", desc.GetParentSchemaID())
return errors.AssertionFailedf("schema id %d not found", d.GetParentSchemaID())
}
if err := fn(ctx, schemaName, mutable); err != nil {
return err
Expand Down

0 comments on commit ea992fa

Please sign in to comment.