@@ -292,10 +292,12 @@ func TestShouldDiscardDDL(t *testing.T) {
292
292
table string
293
293
query string
294
294
ddlType timodel.ActionType
295
+ startTs uint64
295
296
ignore bool
296
297
}
297
298
rules []string
298
299
eventFilters []* config.EventFilterRule
300
+ ignoredTs []uint64
299
301
}{
300
302
{
301
303
// Discard by not allowed DDL type cases.
@@ -304,11 +306,12 @@ func TestShouldDiscardDDL(t *testing.T) {
304
306
table string
305
307
query string
306
308
ddlType timodel.ActionType
309
+ startTs uint64
307
310
ignore bool
308
311
}{
309
- {"sns" , "" , "create database test" , timodel .ActionCreateSchema , false },
310
- {"sns" , "" , "drop database test" , timodel .ActionDropSchema , false },
311
- {"test" , "" , "create database test" , timodel .ActionCreateSequence , true },
312
+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
313
+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 0 , false },
314
+ {"test" , "" , "create database test" , timodel .ActionCreateSequence , 0 , true },
312
315
},
313
316
rules : []string {"*.*" },
314
317
},
@@ -319,18 +322,19 @@ func TestShouldDiscardDDL(t *testing.T) {
319
322
table string
320
323
query string
321
324
ddlType timodel.ActionType
325
+ startTs uint64
322
326
ignore bool
323
327
}{
324
- {"sns" , "" , "create database test" , timodel .ActionCreateSchema , false },
325
- {"sns" , "" , "drop database test" , timodel .ActionDropSchema , false },
328
+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
329
+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 0 , false },
326
330
{
327
331
"sns" , "" , "ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci" ,
328
- timodel .ActionModifySchemaCharsetAndCollate , false ,
332
+ timodel .ActionModifySchemaCharsetAndCollate , 0 , false ,
329
333
},
330
- {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , false },
331
- {"ecom" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , false },
332
- {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , false },
333
- {"test" , "" , "create database test" , timodel .ActionCreateSchema , true },
334
+ {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
335
+ {"ecom" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , false },
336
+ {"ecom" , "" , "create database test" , timodel .ActionCreateSchema , 0 , false },
337
+ {"test" , "" , "create database test" , timodel .ActionCreateSchema , 0 , true },
334
338
},
335
339
rules : []string {"sns.*" , "ecom.*" , "!sns.log" , "!ecom.test" },
336
340
},
@@ -341,32 +345,51 @@ func TestShouldDiscardDDL(t *testing.T) {
341
345
table string
342
346
query string
343
347
ddlType timodel.ActionType
348
+ startTs uint64
344
349
ignore bool
345
350
}{
346
- {"schema" , "C1" , "create database test" , timodel .ActionCreateSchema , false },
347
- {"test" , "" , "drop database test1" , timodel .ActionDropSchema , true },
351
+ {"schema" , "C1" , "create database test" , timodel .ActionCreateSchema , 0 , false },
352
+ {"test" , "" , "drop database test1" , timodel .ActionDropSchema , 0 , true },
348
353
{
349
354
"dbname" , "" , "ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci" ,
350
- timodel .ActionModifySchemaCharsetAndCollate , true ,
355
+ timodel .ActionModifySchemaCharsetAndCollate , 0 , true ,
351
356
},
352
- {"test" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , true },
353
- {"schema" , "C1" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , false },
354
- {"schema" , "" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , true },
357
+ {"test" , "aa" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , true },
358
+ {"schema" , "C1" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , false },
359
+ {"schema" , "" , "create table test.t1(a int primary key)" , timodel .ActionCreateTable , 0 , true },
355
360
},
356
361
rules : []string {"schema.C1" },
357
362
},
363
+ {
364
+ // Discard by startTs cases.
365
+ cases : []struct {
366
+ schema string
367
+ table string
368
+ query string
369
+ ddlType timodel.ActionType
370
+ startTs uint64
371
+ ignore bool
372
+ }{
373
+ {"sns" , "" , "create database test" , timodel .ActionCreateSchema , 1 , false },
374
+ {"sns" , "" , "drop database test" , timodel .ActionDropSchema , 2 , true },
375
+ {"test" , "" , "create database test" , timodel .ActionCreateSequence , 3 , true },
376
+ },
377
+ rules : []string {"*.*" },
378
+ ignoredTs : []uint64 {2 , 3 },
379
+ },
358
380
}
359
381
360
382
for _ , ftc := range testCases {
361
383
filter , err := NewFilter (& config.ReplicaConfig {
362
384
Filter : & config.FilterConfig {
363
- Rules : ftc .rules ,
364
- EventFilters : ftc .eventFilters ,
385
+ Rules : ftc .rules ,
386
+ EventFilters : ftc .eventFilters ,
387
+ IgnoreTxnStartTs : ftc .ignoredTs ,
365
388
},
366
389
}, "" )
367
390
require .Nil (t , err )
368
391
for _ , tc := range ftc .cases {
369
- ignore := filter .ShouldDiscardDDL (tc .ddlType , tc .schema , tc .table )
392
+ ignore := filter .ShouldDiscardDDL (tc .ddlType , tc .schema , tc .table , tc . startTs )
370
393
require .Equal (t , tc .ignore , ignore , "%#v" , tc )
371
394
}
372
395
}
0 commit comments