@@ -285,10 +285,12 @@ func TestShouldDiscardDDL(t *testing.T) {
285285 table string
286286 query string
287287 ddlType timodel.ActionType
288+ startTs uint64
288289 ignore bool
289290 }
290291 rules []string
291292 eventFilters []* config.EventFilterRule
293+ ignoredTs []uint64
292294 }{
293295 {
294296 // Discard by not allowed DDL type cases.
@@ -297,11 +299,12 @@ func TestShouldDiscardDDL(t *testing.T) {
297299 table string
298300 query string
299301 ddlType timodel.ActionType
302+ startTs uint64
300303 ignore bool
301304 }{
302- {"sns" , "" , "create database test" , timodel .ActionCreateSchema , false },
303- {"sns" , "" , "drop database test" , timodel .ActionDropSchema , false },
304- {"test" , "" , "create database test" , timodel .ActionCreateSequence , true },
305+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
306+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 0 , false },
307+ {"test" , "" , "create database test" , timodel .ActionCreateSequence , 0 , true },
305308 },
306309 rules : []string {"*.*" },
307310 },
@@ -312,18 +315,19 @@ func TestShouldDiscardDDL(t *testing.T) {
312315 table string
313316 query string
314317 ddlType timodel.ActionType
318+ startTs uint64
315319 ignore bool
316320 }{
317- {"sns" , "" , "create database test" , timodel .ActionCreateSchema , false },
318- {"sns" , "" , "drop database test" , timodel .ActionDropSchema , false },
321+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
322+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 0 , false },
319323 {
320324 "sns" , "" , "ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci" ,
321- timodel .ActionModifySchemaCharsetAndCollate , false ,
325+ timodel .ActionModifySchemaCharsetAndCollate , 0 , false ,
322326 },
323- {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , false },
324- {"ecom" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , false },
325- {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , false },
326- {"test" , "" , "create database test" , timodel .ActionCreateSchema , true },
327+ {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
328+ {"ecom" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , false },
329+ {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
330+ {"test" , "" , "create database test" , timodel .ActionCreateSchema , 0 , true },
327331 },
328332 rules : []string {"sns.*" , "ecom.*" , "!sns.log" , "!ecom.test" },
329333 },
@@ -334,32 +338,51 @@ func TestShouldDiscardDDL(t *testing.T) {
334338 table string
335339 query string
336340 ddlType timodel.ActionType
341+ startTs uint64
337342 ignore bool
338343 }{
339- {"schema" , "C1" , "create database test" , timodel .ActionCreateSchema , false },
340- {"test" , "" , "drop database test1" , timodel .ActionDropSchema , true },
344+ {"schema" , "C1" , "create database test" , timodel .ActionCreateSchema , 0 , false },
345+ {"test" , "" , "drop database test1" , timodel .ActionDropSchema , 0 , true },
341346 {
342347 "dbname" , "" , "ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci" ,
343- timodel .ActionModifySchemaCharsetAndCollate , true ,
348+ timodel .ActionModifySchemaCharsetAndCollate , 0 , true ,
344349 },
345- {"test" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , true },
346- {"schema" , "C1" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , false },
347- {"schema" , "" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , true },
350+ {"test" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , true },
351+ {"schema" , "C1" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , false },
352+ {"schema" , "" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , true },
348353 },
349354 rules : []string {"schema.C1" },
350355 },
356+ {
357+ // Discard by startTs cases.
358+ cases : []struct {
359+ schema string
360+ table string
361+ query string
362+ ddlType timodel.ActionType
363+ startTs uint64
364+ ignore bool
365+ }{
366+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 1 , false },
367+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 2 , true },
368+ {"test" , "" , "create database test" , timodel .ActionCreateSequence , 3 , true },
369+ },
370+ rules : []string {"*.*" },
371+ ignoredTs : []uint64 {2 , 3 },
372+ },
351373 }
352374
353375 for _ , ftc := range testCases {
354376 filter , err := NewFilter (& config.ReplicaConfig {
355377 Filter : & config.FilterConfig {
356- Rules : ftc .rules ,
357- EventFilters : ftc .eventFilters ,
378+ Rules : ftc .rules ,
379+ EventFilters : ftc .eventFilters ,
380+ IgnoreTxnStartTs : ftc .ignoredTs ,
358381 },
359382 }, "" )
360383 require .Nil (t , err )
361384 for _ , tc := range ftc .cases {
362- ignore := filter .ShouldDiscardDDL (tc .ddlType , tc .schema , tc .table )
385+ ignore := filter .ShouldDiscardDDL (tc .ddlType , tc .schema , tc .table , tc . startTs )
363386 require .Equal (t , tc .ignore , ignore , "%#v" , tc )
364387 }
365388 }
0 commit comments