Skip to content

Commit c7e7cb7

Browse files
authored
ddl: add more corner tests for active-active (#66252)
ref #64281
1 parent f5ceded commit c7e7cb7

File tree

23 files changed

+508
-195
lines changed

23 files changed

+508
-195
lines changed

br/cmd/br/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ go_library(
3434
"//br/pkg/version/build",
3535
"//pkg/config",
3636
"//pkg/meta/model",
37+
"//pkg/parser/mysql",
3738
"//pkg/session",
3839
"//pkg/util",
3940
"//pkg/util/gctuner",

br/cmd/br/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/pingcap/tidb/br/pkg/utils"
2222
"github.com/pingcap/tidb/br/pkg/version/build"
2323
"github.com/pingcap/tidb/pkg/config"
24+
"github.com/pingcap/tidb/pkg/parser/mysql"
2425
tidbutils "github.com/pingcap/tidb/pkg/util"
2526
"github.com/pingcap/tidb/pkg/util/logutil"
2627
"github.com/pingcap/tidb/pkg/util/memory"
@@ -51,6 +52,7 @@ var (
5152
"mysql.default_roles",
5253
"mysql.role_edges",
5354
"!sys.*",
55+
fmt.Sprintf("!%s.*", mysql.TiCDCSystemDB),
5456
"!INFORMATION_SCHEMA.*",
5557
"!PERFORMANCE_SCHEMA.*",
5658
"!METRICS_SCHEMA.*",

br/pkg/task/stream.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ func RunStreamRestore(
13961396
}
13971397
// TODO: pitr filtered restore doesn't support restore system table yet
13981398
if cfg.ExplicitFilter {
1399-
if cfg.TableFilter.MatchSchema(mysql.SystemDB) || cfg.TableFilter.MatchSchema(mysql.SysDB) {
1399+
if cfg.TableFilter.MatchSchema(mysql.SystemDB) ||
1400+
cfg.TableFilter.MatchSchema(mysql.SysDB) {
14001401
return errors.Annotatef(berrors.ErrInvalidArgument,
14011402
"PiTR doesn't support custom filter to include system db, consider to exclude system db")
14021403
}

br/pkg/utils/schema_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package utils
22

33
import (
44
"testing"
5+
6+
"github.com/pingcap/tidb/pkg/parser/mysql"
57
)
68

79
func TestIsSysOrTempSysDB(t *testing.T) {
@@ -25,6 +27,11 @@ func TestIsSysOrTempSysDB(t *testing.T) {
2527
db: "workload_schema",
2628
expected: false,
2729
},
30+
{
31+
name: "tidb_cdc non-system db",
32+
db: mysql.TiCDCSystemDB,
33+
expected: false,
34+
},
2835
{
2936
name: "temporary mysql db",
3037
db: "__TiDB_BR_Temporary_mysql",
@@ -40,6 +47,11 @@ func TestIsSysOrTempSysDB(t *testing.T) {
4047
db: "__TiDB_BR_Temporary_workload_schema",
4148
expected: false,
4249
},
50+
{
51+
name: "temporary tidb_cdc db",
52+
db: "__TiDB_BR_Temporary_" + mysql.TiCDCSystemDB,
53+
expected: false,
54+
},
4355
{
4456
name: "normal db",
4557
db: "test",

pkg/ddl/create_table.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ func BuildTableInfoWithStmt(ctx *metabuild.Context, s *ast.CreateTableStmt, dbIn
822822
}
823823

824824
var tbInfo *model.TableInfo
825-
tbInfo, err = BuildTableInfo(ctx, s.Table.Name, cols, newConstraints, tableCharset, tableCollate)
825+
tbInfo, err = BuildTableInfo(ctx, s.Table.Name, cols, newConstraints, tableCharset, tableCollate, optInfo)
826826
if err != nil {
827827
return nil, errors.Trace(err)
828828
}
@@ -1416,13 +1416,18 @@ func BuildTableInfo(
14161416
constraints []*ast.Constraint,
14171417
charset string,
14181418
collate string,
1419+
optInfo *model.TableInfo,
14191420
) (tbInfo *model.TableInfo, err error) {
14201421
tbInfo = &model.TableInfo{
14211422
Name: tableName,
14221423
Version: model.CurrLatestTableInfoVersion,
14231424
Charset: charset,
14241425
Collate: collate,
14251426
}
1427+
if optInfo != nil {
1428+
tbInfo.SoftdeleteInfo = optInfo.SoftdeleteInfo
1429+
tbInfo.IsActiveActive = optInfo.IsActiveActive
1430+
}
14261431
tblColumns := make([]*table.Column, 0, len(cols))
14271432
existedColsMap := make(map[string]struct{}, len(cols))
14281433
for _, v := range cols {

pkg/ddl/executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ func (e *executor) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt) (er
15751575
tblCollate = v
15761576
}
15771577

1578-
tbInfo, err := BuildTableInfo(NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, tblCharset, tblCollate)
1578+
tbInfo, err := BuildTableInfo(NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, tblCharset, tblCollate, nil)
15791579
if err != nil {
15801580
return err
15811581
}
@@ -6104,7 +6104,7 @@ func (e *executor) CreateSequence(ctx sessionctx.Context, stmt *ast.CreateSequen
61046104
return err
61056105
}
61066106
// TiDB describe the sequence within a tableInfo, as a same-level object of a table and view.
6107-
tbInfo, err := BuildTableInfo(NewMetaBuildContextWithSctx(ctx), ident.Name, nil, nil, "", "")
6107+
tbInfo, err := BuildTableInfo(NewMetaBuildContextWithSctx(ctx), ident.Name, nil, nil, "", "", nil)
61086108
if err != nil {
61096109
return err
61106110
}

pkg/ddl/index.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ func BuildIndexInfo(
356356
return nil, errors.Trace(err)
357357
}
358358

359+
if !isPrimary && isUnique && (tblInfo.IsActiveActive || tblInfo.SoftdeleteInfo != nil) {
360+
return nil, errors.Trace(dbterror.ErrAlterOperationNotSupported.GenWithStackByArgs("UNIQUE", "Cannot create unique index on ACTIVE_ACTIVE or softdelete table", "removing UNIQUE"))
361+
}
362+
359363
// Create index info.
360364
idxInfo := &model.IndexInfo{
361365
Name: indexName,

pkg/ddl/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func MockTableInfo(sctx sessionctx.Context, stmt *ast.CreateTableStmt, tableID i
6161
if err != nil {
6262
return nil, errors.Trace(err)
6363
}
64-
tbl, err := BuildTableInfo(ctx, stmt.Table.Name, cols, newConstraints, "", "")
64+
tbl, err := BuildTableInfo(ctx, stmt.Table.Name, cols, newConstraints, "", "", nil)
6565
if err != nil {
6666
return nil, errors.Trace(err)
6767
}

pkg/ddl/schematracker/dm_tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (d *SchemaTracker) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt
276276
})
277277
}
278278

279-
tbInfo, err := ddl.BuildTableInfo(ddl.NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, "", "")
279+
tbInfo, err := ddl.BuildTableInfo(ddl.NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, "", "", nil)
280280
if err != nil {
281281
return err
282282
}

pkg/executor/show.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ func (e *ShowExec) fetchShowColumns(ctx context.Context) error {
730730
} else if fieldPatternsLike != nil && !fieldPatternsLike.DoMatch(col.Name.L) {
731731
continue
732732
}
733+
if skipColumnInShowCreateTable(tb.Meta(), col.ColumnInfo, false) {
734+
continue
735+
}
733736
desc := table.NewColDesc(col)
734737
var columnDefault any
735738
if desc.DefaultValue != nil {
@@ -1080,13 +1083,7 @@ func constructResultOfShowCreateTable(ctx sessionctx.Context, dbName *pmodel.CIS
10801083
var hasAutoIncID bool
10811084
needAddComma := false
10821085
for i, col := range tableInfo.Cols() {
1083-
if col == nil || col.Hidden || col.Name == model.ExtraHandleName || col.Name == model.ExtraOriginTSName {
1084-
continue
1085-
}
1086-
if tableInfo.SoftdeleteInfo != nil && model.IsSoftDeleteColumn(col.Name) {
1087-
continue
1088-
}
1089-
if tableInfo.IsActiveActive && model.IsActiveActiveColumn(col.Name) {
1086+
if skipColumnInShowCreateTable(tableInfo, col, true) {
10901087
continue
10911088
}
10921089
if needAddComma {
@@ -1680,6 +1677,27 @@ func fetchShowCreateTable4View(ctx sessionctx.Context, tb *model.TableInfo, buf
16801677
fmt.Fprintf(buf, ") AS %s", tb.View.SelectStmt)
16811678
}
16821679

1680+
func skipColumnInShowCreateTable(tableInfo *model.TableInfo, col *model.ColumnInfo, hidden bool) bool {
1681+
if col == nil || col.Name == model.ExtraHandleName || col.Name == model.ExtraOriginTSName {
1682+
return true
1683+
}
1684+
if hidden && col.Hidden {
1685+
return true
1686+
}
1687+
// Keep the existing show-create-table behavior for base tables.
1688+
if tableInfo.SoftdeleteInfo != nil && model.IsSoftDeleteColumn(col.Name) {
1689+
return true
1690+
}
1691+
if tableInfo.IsActiveActive && model.IsActiveActiveColumn(col.Name) {
1692+
return true
1693+
}
1694+
// Views do not carry softdelete/active-active flags, but should still hide these internal columns.
1695+
if tableInfo.IsView() && (model.IsSoftDeleteColumn(col.Name) || model.IsActiveActiveColumn(col.Name)) {
1696+
return true
1697+
}
1698+
return false
1699+
}
1700+
16831701
// ConstructResultOfShowCreateDatabase constructs the result for show create database.
16841702
func ConstructResultOfShowCreateDatabase(ctx sessionctx.Context, dbInfo *model.DBInfo, ifNotExists bool, buf *bytes.Buffer) (err error) {
16851703
sqlMode := ctx.GetSessionVars().SQLMode

0 commit comments

Comments
 (0)