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 utf8 charset upgrade compatibility #9820

Merged
merged 24 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3924856
add ignore-column-utf8-charset to toml config file and default is true
crazycs520 Mar 20, 2019
d96be67
make ignore-column-utf8-charset take effect in check no-utf8mb4 and s…
crazycs520 Mar 20, 2019
3a77bc6
add test and fix test
crazycs520 Mar 20, 2019
16494b2
treat utf8 as utf8mb4 for old version table/column
crazycs520 Mar 20, 2019
c8e5b9d
add test and modify/change column should not change column version
crazycs520 Mar 21, 2019
15c43af
update variable name
crazycs520 Mar 21, 2019
18125dc
refine code
crazycs520 Mar 21, 2019
40c68dc
refine code
crazycs520 Mar 21, 2019
e4f71a1
add column version for view column
crazycs520 Mar 21, 2019
1ed6ef6
increase table and column version
crazycs520 Mar 21, 2019
655fc6b
add tidb_treat_old_version_utf8_as_utf8mb4 system variable
crazycs520 Mar 22, 2019
adc67a2
address comment
crazycs520 Mar 22, 2019
786c6e8
address comment
crazycs520 Mar 22, 2019
7c1b4f4
update go.mod for parser
crazycs520 Mar 22, 2019
a612ab9
Merge branch 'master' of https://github.com/pingcap/tidb into fix-cha…
crazycs520 Mar 22, 2019
b0512cf
ConvertOldVersionUTF8AsUTF8MB4IfNeed when load schema, TODO: fix chan…
crazycs520 Mar 25, 2019
99de30a
add comment
crazycs520 Mar 25, 2019
e757f21
*: remove http api modify treat-old-version-utf8-as-utf8mb4 and sessi…
crazycs520 Mar 25, 2019
62d49b8
remove redundancy code
crazycs520 Mar 25, 2019
d6b6280
fix alter table charset
crazycs520 Mar 25, 2019
57f22e6
add comment
crazycs520 Mar 25, 2019
2d226d1
Merge branch 'master' into fix-charset-upgrade
winkyao Mar 25, 2019
e520900
Merge branch 'master' of https://github.com/pingcap/tidb into fix-cha…
crazycs520 Mar 25, 2019
44912c8
Merge branch 'fix-charset-upgrade' of https://github.com/crazycs520/t…
crazycs520 Mar 25, 2019
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
54 changes: 28 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ type Config struct {
// TODO: We actually only support mode 2, which keeps the original case, but the comparison is case-insensitive.
LowerCaseTableNames int `toml:"lower-case-table-names" json:"lower-case-table-names"`

Log Log `toml:"log" json:"log"`
Security Security `toml:"security" json:"security"`
Status Status `toml:"status" json:"status"`
Performance Performance `toml:"performance" json:"performance"`
PreparedPlanCache PreparedPlanCache `toml:"prepared-plan-cache" json:"prepared-plan-cache"`
OpenTracing OpenTracing `toml:"opentracing" json:"opentracing"`
ProxyProtocol ProxyProtocol `toml:"proxy-protocol" json:"proxy-protocol"`
TiKVClient TiKVClient `toml:"tikv-client" json:"tikv-client"`
Binlog Binlog `toml:"binlog" json:"binlog"`
CompatibleKillQuery bool `toml:"compatible-kill-query" json:"compatible-kill-query"`
Plugin Plugin `toml:"plugin" json:"plugin"`
CheckMb4ValueInUtf8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"`
Log Log `toml:"log" json:"log"`
Security Security `toml:"security" json:"security"`
Status Status `toml:"status" json:"status"`
Performance Performance `toml:"performance" json:"performance"`
PreparedPlanCache PreparedPlanCache `toml:"prepared-plan-cache" json:"prepared-plan-cache"`
OpenTracing OpenTracing `toml:"opentracing" json:"opentracing"`
ProxyProtocol ProxyProtocol `toml:"proxy-protocol" json:"proxy-protocol"`
TiKVClient TiKVClient `toml:"tikv-client" json:"tikv-client"`
Binlog Binlog `toml:"binlog" json:"binlog"`
CompatibleKillQuery bool `toml:"compatible-kill-query" json:"compatible-kill-query"`
Plugin Plugin `toml:"plugin" json:"plugin"`
CheckMb4ValueInUtf8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"`
TreadOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"`
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
}

// Log is the log section of config.
Expand Down Expand Up @@ -267,20 +268,21 @@ type Plugin struct {
}

var defaultConf = Config{
Host: "0.0.0.0",
AdvertiseAddress: "",
Port: 4000,
Cors: "",
Store: "mocktikv",
Path: "/tmp/tidb",
RunDDL: true,
SplitTable: true,
Lease: "45s",
TokenLimit: 1000,
OOMAction: "log",
MemQuotaQuery: 32 << 30,
EnableStreaming: false,
CheckMb4ValueInUtf8: true,
Host: "0.0.0.0",
AdvertiseAddress: "",
Port: 4000,
Cors: "",
Store: "mocktikv",
Path: "/tmp/tidb",
RunDDL: true,
SplitTable: true,
Lease: "45s",
TokenLimit: 1000,
OOMAction: "log",
MemQuotaQuery: 32 << 30,
EnableStreaming: false,
CheckMb4ValueInUtf8: true,
TreadOldVersionUTF8AsUTF8MB4: true,
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
TxnLocalLatches: TxnLocalLatches{
Enabled: true,
Capacity: 2048000,
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ compatible-kill-query = false
# check mb4 value in utf8 is used to control whether to check the mb4 characters when the charset is utf8.
check-mb4-value-in-utf8 = true

# treat-old-version-utf8-as-utf8mb4 use for upgrade compatibility. Set to true will tread old version table/column UTF8 charset as UTF8MB4.
treat-old-version-utf8-as-utf8mb4 = true

[log]
# Log level: debug, info, warn, error, fatal.
level = "info"
Expand Down
4 changes: 0 additions & 4 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,6 @@ func generateOriginDefaultValue(col *model.ColumnInfo) (interface{}, error) {
if odValue == strings.ToUpper(ast.CurrentTimestamp) {
if col.Tp == mysql.TypeTimestamp {
odValue = time.Now().UTC().Format(types.TimeFormat)
// Version = 1: For OriginDefaultValue and DefaultValue of timestamp column will stores the default time in UTC time zone.
winkyao marked this conversation as resolved.
Show resolved Hide resolved
// This will fix bug in version 0.
// TODO: remove this version field after there is no old version 0.
col.Version = model.ColumnInfoVersion1
} else if col.Tp == mysql.TypeDatetime {
odValue = time.Now().Format(types.TimeFormat)
}
Expand Down
126 changes: 124 additions & 2 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
tmysql "github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
Expand All @@ -40,6 +42,7 @@ import (
"github.com/pingcap/tidb/store/mockstore/mocktikv"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -1221,8 +1224,7 @@ func (s *testIntegrationSuite) assertAlterErrorExec(c *C, sql string) {
func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
s.tk.MustExec("drop table if exists t")
s.tk.MustExec("drop table if exists t1")
s.tk.MustExec("drop table if exists t, t1")
defer s.tk.MustExec("drop table if exists t")

s.tk.MustExec(`create table t(
Expand Down Expand Up @@ -1282,3 +1284,123 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) {
s.assertAlterErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE")
s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT")
}

func (s *testIntegrationSuite) TestIgnoreColumnUTF8Charset(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
s.tk.MustExec("drop table if exists t")
defer s.tk.MustExec("drop table if exists t")

s.tk.MustExec("create table t (a varchar(10) character set utf8, b varchar(10) character set ascii) charset=utf8mb4;")
assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80';", mysql.ErrTruncatedWrongValueForField)
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

// Mock old version table info with column charset is utf8.
db, ok := domain.GetDomain(s.ctx).InfoSchema().SchemaByName(model.NewCIStr("test"))
tbl := testGetTableByName(c, s.ctx, "test", "t")
tblInfo := tbl.Meta().Clone()
tblInfo.Version = model.TableInfoVersion0
tblInfo.Columns[0].Version = model.ColumnInfoVersion0
updateTableInfo := func(tblInfo *model.TableInfo) {
mockCtx := mock.NewContext()
mockCtx.Store = s.store
err := mockCtx.NewTxn(context.Background())
c.Assert(err, IsNil)
txn, err := mockCtx.Txn(true)
c.Assert(err, IsNil)
mt := meta.NewMeta(txn)
c.Assert(ok, IsTrue)
err = mt.UpdateTable(db.ID, tblInfo)
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)
}
updateTableInfo(tblInfo)
s.tk.MustExec("alter table t add column c varchar(10) character set utf8;") // load latest schema.
c.Assert(config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4, IsTrue)
s.tk.MustExec("insert into t set a= x'f09f8c80'")
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,\n" +
" `c` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL\n" +
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = false
assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField)
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,\n" +
" `c` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

// Mock old version table info with table and column charset is utf8.
tbl = testGetTableByName(c, s.ctx, "test", "t")
tblInfo = tbl.Meta().Clone()
tblInfo.Charset = charset.CharsetUTF8
tblInfo.Collate = charset.CollationUTF8
tblInfo.Version = model.TableInfoVersion0
tblInfo.Columns[0].Version = model.ColumnInfoVersion0
updateTableInfo(tblInfo)

s.tk.MustExec("alter table t drop column c;") // load latest schema.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If execute alter table t add column c varchar(10) here, the column will be UTF8, because the table charset actually is UTF8, tidb_treat_old_version_utf8_as_utf8mb4 currently only take effect in insert and show create table. Was this expected in the end? @winkyao

config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = true
s.tk.MustExec("insert into t set a= x'f09f8c80'")
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = false
assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField)
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"))

// Test modify column charset.
config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = true
s.tk.MustExec("alter table t modify column a varchar(10) character set utf8mb4") // change column charset.
tbl = testGetTableByName(c, s.ctx, "test", "t")
c.Assert(tbl.Meta().Columns[0].Charset, Equals, charset.CharsetUTF8MB4)
c.Assert(tbl.Meta().Columns[0].Collate, Equals, charset.CollationUTF8MB4)
c.Assert(tbl.Meta().Columns[0].Version, Equals, model.ColumnInfoVersion0)
s.tk.MustExec("insert into t set a= x'f09f8c80'")
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(10) DEFAULT NULL,\n" +
" `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

// Test for change column should not modify the column version.
s.tk.MustExec("alter table t change column a a varchar(20)") // change column .
tbl = testGetTableByName(c, s.ctx, "test", "t")
c.Assert(tbl.Meta().Columns[0].Charset, Equals, charset.CharsetUTF8MB4)
c.Assert(tbl.Meta().Columns[0].Collate, Equals, charset.CollationUTF8MB4)
c.Assert(tbl.Meta().Columns[0].Version, Equals, model.ColumnInfoVersion0)

// Test for v2.1.5 and v2.1.6 that table version is 1 but column version is 0.
tbl = testGetTableByName(c, s.ctx, "test", "t")
tblInfo = tbl.Meta().Clone()
tblInfo.Charset = charset.CharsetUTF8
tblInfo.Collate = charset.CollationUTF8
tblInfo.Version = model.TableInfoVersion1
tblInfo.Columns[0].Version = model.ColumnInfoVersion0
tblInfo.Columns[0].Charset = charset.CharsetUTF8
tblInfo.Columns[0].Collate = charset.CollationUTF8
updateTableInfo(tblInfo)
s.tk.MustExec("alter table t change column b b varchar(20)") // load latest column.
s.tk.MustExec("insert into t set a= x'f09f8c80'")
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(20) DEFAULT NULL,\n" +
" `b` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = false
assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField)
s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` varchar(20) DEFAULT NULL,\n" +
" `b` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"))
}
25 changes: 13 additions & 12 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,6 @@ func convertTimestampDefaultValToUTC(ctx sessionctx.Context, defaultVal interfac
return defaultVal, errors.Trace(err)
}
defaultVal = t.String()
// Version = 1: For OriginDefaultValue and DefaultValue of timestamp column will stores the default time in UTC time zone.
// This will fix bug in version 0.
// TODO: remove this version field after there is no old version 0.
col.Version = model.ColumnInfoVersion1
}
}
return defaultVal, nil
Expand All @@ -361,6 +357,8 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o
Offset: offset,
Name: colDef.Name.Name,
FieldType: *colDef.Tp,
// TODO: remove this version field after there is no old version.
Version: model.CurrLatestColumnInfoVersion,
})

if !isExplicitTimeStamp() {
Expand Down Expand Up @@ -1294,19 +1292,21 @@ func buildViewInfoWithTableColumns(ctx sessionctx.Context, s *ast.CreateViewStmt
if s.Cols == nil {
for i, v := range schemaCols {
tableColumns[i] = table.ToColumn(&model.ColumnInfo{
Name: v.AsName,
ID: int64(i),
Offset: i,
State: model.StatePublic,
Name: v.AsName,
ID: int64(i),
Offset: i,
State: model.StatePublic,
Version: model.CurrLatestColumnInfoVersion,
})
}
} else {
for i, v := range s.Cols {
tableColumns[i] = table.ToColumn(&model.ColumnInfo{
Name: v,
ID: int64(i),
Offset: i,
State: model.StatePublic,
Name: v,
ID: int64(i),
Offset: i,
State: model.StatePublic,
Version: model.CurrLatestColumnInfoVersion,
})
}
}
Expand Down Expand Up @@ -2208,6 +2208,7 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or
OriginDefaultValue: col.OriginDefaultValue,
FieldType: *specNewColumn.Tp,
Name: newColName,
Version: col.Version,
})

// TODO: Remove it when all table versions are greater than or equal to TableInfoVersion1.
Expand Down
13 changes: 11 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,24 @@ func (e *ShowExec) fetchShowCreateTable() error {
if len(tblCollate) == 0 {
tblCollate = getDefaultCollate(tblCharset)
}
if tb.Meta().Version < model.CurrLatestTableInfoVersion && config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 && tblCharset == charset.CharsetUTF8 {
tblCharset = charset.CharsetUTF8MB4
tblCollate = charset.CollationUTF8MB4
}

fmt.Fprintf(&buf, "CREATE TABLE %s (\n", escape(tb.Meta().Name, sqlMode))
var pkCol *table.Column
var hasAutoIncID bool
for i, col := range tb.Cols() {
fmt.Fprintf(&buf, " %s %s", escape(col.Name, sqlMode), col.GetTypeDesc())
if col.Charset != "binary" {
if col.Charset != tblCharset || col.Collate != tblCollate {
fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", col.Charset, col.Collate)
colCharset, colCollate := col.Charset, col.Collate
if col.Version < model.CurrLatestColumnInfoVersion && config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 && colCharset == charset.CharsetUTF8 {
colCharset = charset.CharsetUTF8MB4
colCollate = charset.CollationUTF8MB4
}
if colCharset != tblCharset || colCollate != tblCollate {
fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", colCharset, colCollate)
}
}
if col.IsGenerated() {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ require (
sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)

replace github.com/pingcap/parser => github.com/crazycs520/parser v0.0.0-20190321071806-bb95b59d5fc3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 h1:3jFq2xL4ZajGK
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/crazycs520/parser v0.0.0-20190321071806-bb95b59d5fc3 h1:4lGW+oj7hr0C0icPqLuuSqWuKaPoD1FA0gmfhWN/hIQ=
github.com/crazycs520/parser v0.0.0-20190321071806-bb95b59d5fc3/go.mod h1:xLjI+gnWYexq011WPMEvCNS8rFM9qe1vdojIEzSKPuc=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65 h1:hxuZop6tSoOi0sxFzoGGYdRqNrPubyaIf9KoBG9tPiE=
Expand Down Expand Up @@ -115,8 +117,6 @@ github.com/pingcap/kvproto v0.0.0-20190215154024-7f2fc73ef562 h1:32oF1/8lVnBR2JV
github.com/pingcap/kvproto v0.0.0-20190215154024-7f2fc73ef562/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/parser v0.0.0-20190312024907-3f6280b08c8b h1:NlvTrxqezIJh6CD5Leky12IZ8E/GtpEEmzgNNb34wbw=
github.com/pingcap/parser v0.0.0-20190312024907-3f6280b08c8b/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE=
github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible h1:e9Gi/LP9181HT3gBfSOeSBA+5JfemuE4aEAhqNgoE4k=
Expand Down
11 changes: 11 additions & 0 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,17 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
}
if treadOldVersionUTF8AsUTF8MB4 := req.Form.Get("treat-old-version-utf8-as-utf8mb4"); treadOldVersionUTF8AsUTF8MB4 != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a session variable to set this config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the "session variable" actually is system scope, not session.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the session variable for need reload schema after change this variable.

switch treadOldVersionUTF8AsUTF8MB4 {
case "0":
config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = false
case "1":
config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4 = true
default:
writeError(w, errors.New("illegal argument"))
return
}
}
} else {
writeData(w, config.GetGlobalConfig())
}
Expand Down
14 changes: 14 additions & 0 deletions server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,20 @@ func (ts *HTTPHandlerTestSuite) TestPostSettings(c *C) {
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(config.GetGlobalConfig().CheckMb4ValueInUtf8, Equals, false)
dbt.mustExec("insert t2 values (unhex('f09f8c80'));")

// Test enable treat-old-version-utf8-as-utf8mb4.
form.Set("treat-old-version-utf8-as-utf8mb4", "0")
resp, err = http.PostForm("http://127.0.0.1:10090/settings", form)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4, Equals, false)

// Test Disable treat-old-version-utf8-as-utf8mb4.
form.Set("treat-old-version-utf8-as-utf8mb4", "1")
resp, err = http.PostForm("http://127.0.0.1:10090/settings", form)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(config.GetGlobalConfig().TreadOldVersionUTF8AsUTF8MB4, Equals, true)
}

func (ts *HTTPHandlerTestSuite) TestPprof(c *C) {
Expand Down
Loading