Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschemaV2: add ut for v2 and some refine #51507

Merged
merged 8 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/infoschema/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"error.go",
"infoschema.go",
"infoschema_v2.go",
"interface.go",
"metric_table_def.go",
"metrics_schema.go",
"tables.go",
Expand Down Expand Up @@ -76,22 +77,23 @@ go_test(
timeout = "short",
srcs = [
"infoschema_test.go",
"infoschema_v2_test.go",
"main_test.go",
"metrics_schema_test.go",
],
embed = [":infoschema"],
flaky = True,
shard_count = 10,
shard_count = 11,
deps = [
"//pkg/ddl/placement",
"//pkg/domain",
"//pkg/infoschema/internal",
"//pkg/kv",
"//pkg/meta",
"//pkg/meta/autoid",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/sessionctx/variable",
"//pkg/store/mockstore",
"//pkg/table",
"//pkg/testkit",
"//pkg/testkit/testsetup",
Expand Down
26 changes: 6 additions & 20 deletions pkg/infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl/placement"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/meta/autoid"
Expand Down Expand Up @@ -1046,25 +1045,12 @@ func RegisterVirtualTable(dbInfo *model.DBInfo, tableFromMeta tableFromMetaFunc)
// NewBuilder creates a new Builder with a Handle.
func NewBuilder(r autoid.Requirement, factory func() (pools.Resource, error), infoData *Data) *Builder {
return &Builder{
enableV2: variable.SchemaCacheSize.Load() > 0,
Requirement: r,
infoschemaV2: infoschemaV2{
infoSchema: &infoSchema{
infoSchemaMisc: infoSchemaMisc{
policyMap: map[string]*model.PolicyInfo{},
resourceGroupMap: map[string]*model.ResourceGroupInfo{},
ruleBundleMap: map[int64]*placement.Bundle{},
referredForeignKeyMap: make(map[SchemaAndTableName][]*model.ReferredFKInfo),
},
schemaMap: map[string]*schemaTables{},
sortedTablesBuckets: make([]sortedTables, bucketCount),
},
Data: infoData,
r: r,
},
dirtyDB: make(map[string]bool),
factory: factory,
infoData: infoData,
enableV2: variable.SchemaCacheSize.Load() > 0,
Requirement: r,
infoschemaV2: NewInfoSchemaV2(r, infoData),
dirtyDB: make(map[string]bool),
factory: factory,
infoData: infoData,
}
}

Expand Down
35 changes: 0 additions & 35 deletions pkg/infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,6 @@ import (
"github.com/pingcap/tidb/pkg/util/mock"
)

// InfoSchema is the interface used to retrieve the schema information.
// It works as a in memory cache and doesn't handle any schema change.
// InfoSchema is read-only, and the returned value is a copy.
type InfoSchema interface {
SchemaByName(schema model.CIStr) (*model.DBInfo, bool)
SchemaExists(schema model.CIStr) bool
TableByName(schema, table model.CIStr) (table.Table, error)
TableExists(schema, table model.CIStr) bool
SchemaByID(id int64) (*model.DBInfo, bool)
TableByID(id int64) (table.Table, bool)
AllSchemas() []*model.DBInfo
SchemaTables(schema model.CIStr) []table.Table
SchemaMetaVersion() int64
FindTableByPartitionID(partitionID int64) (table.Table, *model.DBInfo, *model.PartitionDefinition)
Misc
}

// Misc contains the methods that are not closely related to InfoSchema.
type Misc interface {
PolicyByName(name model.CIStr) (*model.PolicyInfo, bool)
ResourceGroupByName(name model.CIStr) (*model.ResourceGroupInfo, bool)
// PlacementBundleByPhysicalTableID is used to get a rule bundle.
PlacementBundleByPhysicalTableID(id int64) (*placement.Bundle, bool)
// AllPlacementBundles is used to get all placement bundles
AllPlacementBundles() []*placement.Bundle
// AllPlacementPolicies returns all placement policies
AllPlacementPolicies() []*model.PolicyInfo
// AllResourceGroups returns all resource groups
AllResourceGroups() []*model.ResourceGroupInfo
// HasTemporaryTable returns whether information schema has temporary table
HasTemporaryTable() bool
// GetTableReferredForeignKeys gets the table's ReferredFKInfo by lowercase schema and table name.
GetTableReferredForeignKeys(schema, table string) []*model.ReferredFKInfo
}

var _ Misc = &infoSchemaMisc{}

type sortedTables []table.Table
Expand Down
Loading