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

*: fix TestBuildSchemaWithGlobalTemporaryTable with infoschema v2 #52096

Merged
merged 2 commits into from
Mar 27, 2024
Merged
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
24 changes: 16 additions & 8 deletions pkg/infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
}
dbInfos := []*model.DBInfo{dbInfo}
builder, err := infoschema.NewBuilder(re, nil, nil).InitWithDBInfos(dbInfos, nil, nil, 1)
data := infoschema.NewData()
builder, err := infoschema.NewBuilder(re, nil, data).InitWithDBInfos(dbInfos, nil, nil, 1)
require.NoError(t, err)
is := builder.Build(math.MaxUint64)
require.False(t, is.HasTemporaryTable())
Expand All @@ -320,7 +321,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
err := kv.RunInNewTxn(ctx, re.Store(), true, func(ctx context.Context, txn kv.Transaction) error {
m := meta.NewMeta(txn)
for _, change := range changes {
builder, err := infoschema.NewBuilder(re, nil, nil).InitWithOldInfoSchema(curIs)
builder, err := infoschema.NewBuilder(re, nil, data).InitWithOldInfoSchema(curIs)
require.NoError(t, err)
change(m, builder)
curIs = builder.Build(math.MaxUint64)
Expand All @@ -339,7 +340,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -351,7 +352,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -360,7 +361,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
return func(m *meta.Meta, builder *infoschema.Builder) {
err := m.DropTableOrView(db.ID, db.Name.L, tblID, "")
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionDropTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionDropTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -376,14 +377,14 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionTruncateTable, SchemaID: db.ID, OldTableID: tblID, TableID: newTblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionTruncateTable, SchemaID: db.ID, OldTableID: tblID, TableID: newTblID, Version: 1})
require.NoError(t, err)
}
}

alterTableChange := func(tblID int64) func(m *meta.Meta, builder *infoschema.Builder) {
return func(m *meta.Meta, builder *infoschema.Builder) {
_, err := builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionAddColumn, SchemaID: db.ID, TableID: tblID})
_, err := builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionAddColumn, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -397,9 +398,16 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
require.True(t, newIS.HasTemporaryTable())

// full load
data = infoschema.NewData()
newDB, ok := newIS.SchemaByName(model.NewCIStr("test"))
tables := newIS.SchemaTables(newDB.Name)
tblInfos := make([]*model.TableInfo, 0, len(tables))
for _, table := range tables {
tblInfos = append(tblInfos, table.Meta())
}
newDB.Tables = tblInfos
require.True(t, ok)
builder, err = infoschema.NewBuilder(re, nil, nil).InitWithDBInfos([]*model.DBInfo{newDB}, newIS.AllPlacementPolicies(), newIS.AllResourceGroups(), newIS.SchemaMetaVersion())
builder, err = infoschema.NewBuilder(re, nil, data).InitWithDBInfos([]*model.DBInfo{newDB}, newIS.AllPlacementPolicies(), newIS.AllResourceGroups(), newIS.SchemaMetaVersion())
require.NoError(t, err)
require.True(t, builder.Build(math.MaxUint64).HasTemporaryTable())

Expand Down