ddl: don't write binlog for 'ALTER TABLE t CACHE|NOCACHE' (#31106)

close pingcap/tidb#31105
This commit is contained in:
tiancaiamao
2021-12-30 09:59:50 +08:00
committed by GitHub
parent 97c52d0941
commit 075b199011
2 changed files with 38 additions and 0 deletions

View File

@ -621,6 +621,10 @@ func skipWriteBinlog(job *model.Job) bool {
// it's used to update table's TiFlash replica available status.
case model.ActionUpdateTiFlashReplicaStatus:
return true
// Don't sync 'alter table cache|nocache' to other tools.
// It's internal to the current cluster.
case model.ActionAlterCacheTable, model.ActionAlterNoCacheTable:
return true
}
return false

View File

@ -675,6 +675,14 @@ func TestAddSpecialComment(t *testing.T) {
"alter table t force, auto_increment = 12;",
"alter table t force, auto_increment = 12;",
},
{
"alter table t cache",
"alter table t cache",
},
{
"alter table t nocache",
"alter table t nocache",
},
}
for _, ca := range testCase {
re := binloginfo.AddSpecialComment(ca.input)
@ -785,6 +793,32 @@ func TestTempTableBinlog(t *testing.T) {
require.True(t, ok)
}
func TestAlterTableCache(t *testing.T) {
s, clean := createBinlogSuite(t)
defer clean()
// Don't write binlog for 'ALTER TABLE t CACHE|NOCACHE'.
// Cached table is regarded as normal table.
tk := testkit.NewTestKit(t, s.store)
tk.MustExec("use test")
tk.Session().GetSessionVars().BinlogClient = s.client
tk.MustExec("drop table if exists t")
ddlQuery := "create table t (id int)"
tk.MustExec(ddlQuery)
tk.MustExec(`alter table t cache`)
// The latest DDL is still the previous one.
getLatestDDLBinlog(t, s.pump, ddlQuery)
tk.MustExec("insert into t values (?)", 666)
prewriteVal := getLatestBinlogPrewriteValue(t, s.pump)
require.Equal(t, 1, len(prewriteVal.Mutations))
tk.MustExec(`alter table t nocache`)
getLatestDDLBinlog(t, s.pump, ddlQuery)
}
func TestIssue28292(t *testing.T) {
s, clean := createBinlogSuite(t)
defer clean()