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

*: forbid set TiFlash Replica for a table with unsupport charset #30162

Merged
merged 6 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4721,6 +4721,14 @@ func (d *ddl) AlterTableSetTiFlashReplica(ctx sessionctx.Context, ident ast.Iden
return ErrOptOnTemporaryTable.GenWithStackByArgs("set tiflash replica")
}

// Ban setting replica count for tables which has charset not supported by TiFlash
for _, col := range tb.Cols() {
_, ok := charset.TiFlashSupportedCharsets[col.Charset]
if !ok {
return errAlterReplicaForUnsupportedCharsetTable.GenWithStackByArgs(col.Charset)
}
}

tbReplicaInfo := tb.Meta().TiFlashReplica
if tbReplicaInfo != nil && tbReplicaInfo.Count == replicaInfo.Count &&
len(tbReplicaInfo.LocationLabels) == len(replicaInfo.Labels) {
Expand Down
2 changes: 2 additions & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var (
errFkColumnCannotDrop = dbterror.ClassDDL.NewStd(mysql.ErrFkColumnCannotDrop)
errFKIncompatibleColumns = dbterror.ClassDDL.NewStd(mysql.ErrFKIncompatibleColumns)

errAlterReplicaForUnsupportedCharsetTable = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "ALTER table replica for table contain %s charset"), nil))

errOnlyOnRangeListPartition = dbterror.ClassDDL.NewStd(mysql.ErrOnlyOnRangeListPartition)
// errWrongKeyColumn is for table column cannot be indexed.
errWrongKeyColumn = dbterror.ClassDDL.NewStd(mysql.ErrWrongKeyColumn)
Expand Down
18 changes: 18 additions & 0 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sync/atomic"
"time"

"github.com/pingcap/tidb/util/collate"

Defined2014 marked this conversation as resolved.
Show resolved Hide resolved
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
Expand Down Expand Up @@ -84,6 +86,22 @@ func (s *tiflashTestSuite) TearDownSuite(c *C) {
c.Assert(s.store.Close(), IsNil)
}

func (s *tiflashTestSuite) TestNonsupportCharsetTable(c *C) {
collate.SetCharsetFeatEnabledForTest(true)
defer collate.SetCharsetFeatEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b char(10) charset gbk collate gbk_bin)")
err := tk.ExecToErr("alter table t set tiflash replica 1")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported ALTER table replica for table contain gbk charset")

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10) charset utf8)")
tk.MustExec("alter table t set tiflash replica 1")
}

func (s *tiflashTestSuite) TestReadPartitionTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
9 changes: 9 additions & 0 deletions parser/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ var supportedCollationNames = map[string]struct{}{
CollationBin: {},
}

// TiFlashSupportedCharsets is a map which contains TiFlash supports charsets.
var TiFlashSupportedCharsets = map[string]struct{}{
CharsetUTF8: {},
CharsetUTF8MB4: {},
CharsetASCII: {},
CharsetLatin1: {},
CharsetBin: {},
}

// GetSupportedCharsets gets descriptions for all charsets supported so far.
func GetSupportedCharsets() []*Charset {
charsets := make([]*Charset, 0, len(charsetInfos))
Expand Down