Skip to content

Commit

Permalink
infoschema: applyDiff for recover schema in infoschema V2 (#51760)
Browse files Browse the repository at this point in the history
ref #51680
  • Loading branch information
tiancaiamao authored Mar 14, 2024
1 parent d6de964 commit c95a54c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func applyExchangeTablePartition(b *Builder, m *meta.Meta, diff *model.SchemaDif
return append(ptIDs, ntIDs...), nil
}

func (b *Builder) applyRecoverTable(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
func applyRecoverTable(b *Builder, m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
tblIDs, err := applyTableUpdate(b, m, diff)
if err != nil {
return nil, errors.Trace(err)
Expand Down
13 changes: 13 additions & 0 deletions pkg/infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,17 @@ func (tc *infoschemaTestContext) runDropSchema() {
})
}

func (tc *infoschemaTestContext) runRecoverSchema() {
tc.runDropSchema()
// recover schema
internal.AddDB(tc.t, tc.re.Store(), tc.dbInfo)
tc.applyDiffAndCheck(&model.SchemaDiff{Type: model.ActionRecoverSchema, SchemaID: tc.dbInfo.ID}, func(tc *infoschemaTestContext) {
dbInfo, ok := tc.is.SchemaByID(tc.dbInfo.ID)
require.True(tc.t, ok)
require.Equal(tc.t, dbInfo.Name, tc.dbInfo.Name)
})
}

func (tc *infoschemaTestContext) runCreateTable(tblName string) int64 {
if tc.dbInfo == nil {
tc.runCreateSchema()
Expand Down Expand Up @@ -1105,6 +1116,8 @@ func TestApplyDiff(t *testing.T) {
ctx: kv.WithInternalSourceType(context.Background(), kv.InternalTxnDDL),
data: infoschema.NewData(),
}
tc.runRecoverSchema()
tc.clear()
tc.runCreateSchema()
tc.clear()
tc.runDropSchema()
Expand Down
30 changes: 14 additions & 16 deletions pkg/infoschema/infoschema_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@ func applyRecoverSchema(b *Builder, m *meta.Meta, diff *model.SchemaDiff) ([]int
return b.applyRecoverSchema(m, diff)
}

func (b *Builder) applyRecoverSchemaV2(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
if di, ok := b.infoschemaV2.SchemaByID(diff.SchemaID); ok {
return nil, ErrDatabaseExists.GenWithStackByArgs(
fmt.Sprintf("(Schema ID %d)", di.ID),
)
}
di, err := m.GetDatabase(diff.SchemaID)
if err != nil {
return nil, errors.Trace(err)
}
b.infoschemaV2.addDB(diff.Version, di)
return applyCreateTables(b, m, diff)
}

func applyModifySchemaCharsetAndCollate(b *Builder, m *meta.Meta, diff *model.SchemaDiff) error {
if b.enableV2 {
return b.applyModifySchemaCharsetAndCollateV2(m, diff)
Expand All @@ -627,10 +641,6 @@ func applyDropTable(b *Builder, diff *model.SchemaDiff, dbInfo *model.DBInfo, ta
return b.applyDropTable(diff, dbInfo, tableID, affected)
}

func applyRecoverTable(b *Builder, m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
return b.applyRecoverTable(m, diff)
}

func applyCreateTables(b *Builder, m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
return b.applyCreateTables(m, diff)
}
Expand Down Expand Up @@ -716,10 +726,6 @@ func (b *Builder) applyDropTableV2(diff *model.SchemaDiff, dbInfo *model.DBInfo,
return affected
}

func (b *Builder) applyRecoverSchemaV2(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
panic("TODO")
}

func (b *Builder) applyModifySchemaCharsetAndCollateV2(m *meta.Meta, diff *model.SchemaDiff) error {
di, err := m.GetDatabase(diff.SchemaID)
if err != nil {
Expand Down Expand Up @@ -757,14 +763,6 @@ func (b *Builder) applyModifySchemaDefaultPlacementV2(m *meta.Meta, diff *model.
return nil
}

func (b *Builder) applyRecoverTableV2(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
panic("TODO")
}

func (b *Builder) applyCreateTablesV2(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error) {
panic("TODO")
}

func (b *bundleInfoBuilder) updateInfoSchemaBundlesV2(is *infoschemaV2) {
if b.deltaUpdate {
b.completeUpdateTablesV2(is)
Expand Down

0 comments on commit c95a54c

Please sign in to comment.