-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_allow_list.go
58 lines (50 loc) · 1.71 KB
/
block_allow_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
package export
import (
tcontext "github.com/wuhuizuo/tidb6/dumpling/context"
"go.uber.org/zap"
)
func filterDatabases(tctx *tcontext.Context, conf *Config, databases []string) []string {
tctx.L().Debug("start to filter databases")
newDatabases := make([]string, 0, len(databases))
ignoreDatabases := make([]string, 0, len(databases))
for _, database := range databases {
if conf.TableFilter.MatchSchema(database) {
newDatabases = append(newDatabases, database)
} else {
ignoreDatabases = append(ignoreDatabases, database)
}
}
if len(ignoreDatabases) > 0 {
tctx.L().Debug("ignore database", zap.Strings("databases", ignoreDatabases))
}
return newDatabases
}
func filterTables(tctx *tcontext.Context, conf *Config) {
filterTablesFunc(tctx, conf, conf.TableFilter.MatchTable)
}
func filterTablesFunc(tctx *tcontext.Context, conf *Config, matchTable func(string, string) bool) {
tctx.L().Debug("start to filter tables")
dbTables := DatabaseTables{}
ignoredDBTable := DatabaseTables{}
for dbName, tables := range conf.Tables {
for _, table := range tables {
if matchTable(dbName, table.Name) {
dbTables.AppendTable(dbName, table)
} else {
ignoredDBTable.AppendTable(dbName, table)
}
}
// 1. this dbName doesn't match block allow list, don't add
// 2. this dbName matches block allow list, but there is no table in this database, add
if conf.DumpEmptyDatabase {
if _, ok := dbTables[dbName]; !ok && conf.TableFilter.MatchSchema(dbName) {
dbTables[dbName] = make([]*TableInfo, 0)
}
}
}
if len(ignoredDBTable) > 0 {
tctx.L().Debug("ignore table", zap.String("tables", ignoredDBTable.Literal()))
}
conf.Tables = dbTables
}