github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/entry/validator.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package entry 15 16 import ( 17 "github.com/pingcap/errors" 18 tidbkv "github.com/pingcap/tidb/pkg/kv" 19 "github.com/pingcap/tiflow/cdc/entry/schema" 20 "github.com/pingcap/tiflow/cdc/kv" 21 "github.com/pingcap/tiflow/cdc/model" 22 "github.com/pingcap/tiflow/pkg/filter" 23 ) 24 25 // VerifyTables catalog tables specified by ReplicaConfig into 26 // eligible (has an unique index or primary key) and ineligible tables. 27 func VerifyTables( 28 f filter.Filter, 29 storage tidbkv.Storage, 30 startTs uint64) ( 31 tableInfos []*model.TableInfo, 32 ineligibleTables, 33 eligibleTables []model.TableName, 34 err error, 35 ) { 36 meta := kv.GetSnapshotMeta(storage, startTs) 37 snap, err := schema.NewSingleSnapshotFromMeta( 38 model.ChangeFeedID4Test("api", "verifyTable"), 39 meta, startTs, false /* explicitTables */, f) 40 if err != nil { 41 return nil, nil, nil, errors.Trace(err) 42 } 43 44 snap.IterTables(true, func(tableInfo *model.TableInfo) { 45 if f.ShouldIgnoreTable(tableInfo.TableName.Schema, tableInfo.TableName.Table) { 46 return 47 } 48 // Sequence is not supported yet, TiCDC needs to filter all sequence tables. 49 // See https://github.com/pingcap/tiflow/issues/4559 50 if tableInfo.IsSequence() { 51 return 52 } 53 tableInfos = append(tableInfos, tableInfo) 54 if !tableInfo.IsEligible(false /* forceReplicate */) { 55 ineligibleTables = append(ineligibleTables, tableInfo.TableName) 56 } else { 57 eligibleTables = append(eligibleTables, tableInfo.TableName) 58 } 59 }) 60 return 61 }