tidb block_allow_list 源码

  • 2022-09-19
  • 浏览 (544)

tidb block_allow_list 代码

文件路径:/dumpling/export/block_allow_list.go

// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

package export

import (
	tcontext "github.com/pingcap/tidb/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
}

相关信息

tidb 源码目录

相关文章

tidb config 源码

tidb conn 源码

tidb consistency 源码

tidb dump 源码

tidb http_handler 源码

tidb ir 源码

tidb ir_impl 源码

tidb metadata 源码

tidb metrics 源码

tidb prepare 源码

0  赞