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

infoschema,domain: introduce InfoSchemaV2, core data struct etc #51058

Merged
merged 18 commits into from
Feb 23, 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
26 changes: 26 additions & 0 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6439,6 +6439,19 @@ def go_deps():
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/sashamelentyev/usestdlibvars/com_github_sashamelentyev_usestdlibvars-v1.24.0.zip",
],
)
go_repository(
name = "com_github_scalalang2_golang_fifo",
build_file_proto_mode = "disable_global",
importpath = "github.com/scalalang2/golang-fifo",
sha256 = "48ed9feefc3680b12116a212eaac53af5d6c7183ffe80ed1427eb8504a3b05cc",
strip_prefix = "github.com/scalalang2/[email protected]",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/scalalang2/golang-fifo/com_github_scalalang2_golang_fifo-v0.1.5.zip",
"http://ats.apps.svc/gomod/github.com/scalalang2/golang-fifo/com_github_scalalang2_golang_fifo-v0.1.5.zip",
"https://cache.hawkingrei.com/gomod/github.com/scalalang2/golang-fifo/com_github_scalalang2_golang_fifo-v0.1.5.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/scalalang2/golang-fifo/com_github_scalalang2_golang_fifo-v0.1.5.zip",
],
)
go_repository(
name = "com_github_scaleway_scaleway_sdk_go",
build_file_proto_mode = "disable_global",
Expand Down Expand Up @@ -7050,6 +7063,19 @@ def go_deps():
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tiancaiamao/gp/com_github_tiancaiamao_gp-v0.0.0-20221230034425-4025bc8a4d4a.zip",
],
)
go_repository(
name = "com_github_tidwall_btree",
build_file_proto_mode = "disable_global",
importpath = "github.com/tidwall/btree",
sha256 = "4a6619eb936c836841702933a9d66f27abe83b7ffb541de44d12db4aa3a809d5",
strip_prefix = "github.com/tidwall/[email protected]",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tidwall/btree/com_github_tidwall_btree-v1.7.0.zip",
"http://ats.apps.svc/gomod/github.com/tidwall/btree/com_github_tidwall_btree-v1.7.0.zip",
"https://cache.hawkingrei.com/gomod/github.com/tidwall/btree/com_github_tidwall_btree-v1.7.0.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tidwall/btree/com_github_tidwall_btree-v1.7.0.zip",
],
)
go_repository(
name = "com_github_tikv_client_go_v2",
build_file_proto_mode = "disable_global",
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/restore/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestGetExistedUserDBs(t *testing.T) {
dbs := restore.GetExistedUserDBs(dom)
require.Equal(t, 0, len(dbs))

builder, err := infoschema.NewBuilder(dom, nil).InitWithDBInfos(
builder, err := infoschema.NewBuilder(dom, nil, nil).InitWithDBInfos(
[]*model.DBInfo{
{Name: model.NewCIStr("mysql")},
{Name: model.NewCIStr("test")},
Expand All @@ -387,7 +387,7 @@ func TestGetExistedUserDBs(t *testing.T) {
dbs = restore.GetExistedUserDBs(dom)
require.Equal(t, 0, len(dbs))

builder, err = infoschema.NewBuilder(dom, nil).InitWithDBInfos(
builder, err = infoschema.NewBuilder(dom, nil, nil).InitWithDBInfos(
[]*model.DBInfo{
{Name: model.NewCIStr("mysql")},
{Name: model.NewCIStr("test")},
Expand All @@ -399,7 +399,7 @@ func TestGetExistedUserDBs(t *testing.T) {
dbs = restore.GetExistedUserDBs(dom)
require.Equal(t, 1, len(dbs))

builder, err = infoschema.NewBuilder(dom, nil).InitWithDBInfos(
builder, err = infoschema.NewBuilder(dom, nil, nil).InitWithDBInfos(
[]*model.DBInfo{
{Name: model.NewCIStr("mysql")},
{Name: model.NewCIStr("d1")},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ require (
github.com/prometheus/prometheus v0.49.1
github.com/robfig/cron/v3 v3.0.1
github.com/sasha-s/go-deadlock v0.3.1
github.com/scalalang2/golang-fifo v0.1.5
github.com/shirou/gopsutil/v3 v3.24.1
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
github.com/soheilhy/cmux v0.1.5
Expand All @@ -107,6 +108,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tdakkota/asciicheck v0.2.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tidwall/btree v1.7.0
github.com/tikv/client-go/v2 v2.0.8-0.20240205071126-11cb7985f0ec
github.com/tikv/pd/client v0.0.0-20240126020320-567c7d43a008
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/scalalang2/golang-fifo v0.1.5 h1:cl70TQhlMGGpI2DZGcr+7/GFTJOjHMeor0t7wynEEoA=
github.com/scalalang2/golang-fifo v0.1.5/go.mod h1:IK3OZBg7iHbVdQVGPDjcW1MWPb6JcWjaS/w0iRBS8gs=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
Expand Down Expand Up @@ -864,6 +866,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tikv/client-go/v2 v2.0.8-0.20240205071126-11cb7985f0ec h1:j/1OKeXulUHDlfm7uHb6PTlNdagwrHzoHZGPQNK0y68=
github.com/tikv/client-go/v2 v2.0.8-0.20240205071126-11cb7985f0ec/go.mod h1:jZLZhtui1Po+x616K7jxVAMe+aQfAuWqUZluRdO75Kc=
github.com/tikv/pd/client v0.0.0-20240126020320-567c7d43a008 h1:McTV/45piKWPinw0m7gFospPEGBW8AfK5J0RB/G9DP4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestOptions(t *testing.T) {
callback := &ddl.BaseCallback{}
lease := time.Second * 3
store := &mock.Store{}
infoHandle := infoschema.NewCache(16)
infoHandle := infoschema.NewCache(nil, 16)

options := []ddl.Option{
ddl.WithEtcdClient(client),
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/placement_policy_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestPlacementPolicyInUse(t *testing.T) {
t4.State = model.StatePublic
db1.Tables = append(db1.Tables, t4)

builder, err := infoschema.NewBuilder(dom, nil).InitWithDBInfos(
builder, err := infoschema.NewBuilder(dom, nil, nil).InitWithDBInfos(
[]*model.DBInfo{db1, db2, dbP},
[]*model.PolicyInfo{p1, p2, p3, p4, p5},
nil,
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/syncer/state_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestStateSyncerSimple(t *testing.T) {
cli := cluster.RandClient()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ic := infoschema.NewCache(2)
ic := infoschema.NewCache(nil, 2)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d := NewDDL(
ctx,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSyncerSimple(t *testing.T) {
cli := cluster.RandClient()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ic := infoschema.NewCache(2)
ic := infoschema.NewCache(nil, 2)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d := NewDDL(
ctx,
Expand All @@ -88,7 +88,7 @@ func TestSyncerSimple(t *testing.T) {
key := util2.DDLAllSchemaVersions + "/" + d.OwnerManager().ID()
checkRespKV(t, 1, key, syncer.InitialVersion, resp.Kvs...)

ic2 := infoschema.NewCache(2)
ic2 := infoschema.NewCache(nil, 2)
ic2.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d1 := NewDDL(
ctx,
Expand Down
12 changes: 6 additions & 6 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ func init() {

// NewMockDomain is only used for test
func NewMockDomain() *Domain {
do := &Domain{
infoCache: infoschema.NewCache(1),
}
do := &Domain{}
do.infoCache = infoschema.NewCache(do, 1)
do.infoCache.Insert(infoschema.MockInfoSchema(nil), 0)
return do
}
Expand Down Expand Up @@ -301,7 +300,7 @@ func (do *Domain) loadInfoSchema(startTS uint64) (infoschema.InfoSchema, bool, i
return nil, false, currentSchemaVersion, nil, err
}

newISBuilder, err := infoschema.NewBuilder(do, do.sysFacHack).InitWithDBInfos(schemas, policies, resourceGroups, neededSchemaVersion)
newISBuilder, err := infoschema.NewBuilder(do, do.sysFacHack, do.infoCache.Data).InitWithDBInfos(schemas, policies, resourceGroups, neededSchemaVersion)
if err != nil {
return nil, false, currentSchemaVersion, nil, err
}
Expand Down Expand Up @@ -450,7 +449,7 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64
}
diffs = append(diffs, diff)
}
builder := infoschema.NewBuilder(do, do.sysFacHack).InitWithOldInfoSchema(do.infoCache.GetLatest())
builder := infoschema.NewBuilder(do, do.sysFacHack, do.infoCache.Data).InitWithOldInfoSchema(do.infoCache.GetLatest())
builder.SetDeltaUpdateBundles()
phyTblIDs := make([]int64, 0, len(diffs))
actions := make([]uint64, 0, len(diffs))
Expand Down Expand Up @@ -1073,7 +1072,6 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
exit: make(chan struct{}),
sysSessionPool: newSessionPool(capacity, factory),
statsLease: statsLease,
infoCache: infoschema.NewCache(int(variable.SchemaVersionCacheLimit.Load())),
slowQuery: newTopNSlowQueries(config.GetGlobalConfig().InMemSlowQueryTopNNum, time.Hour*24*7, config.GetGlobalConfig().InMemSlowQueryRecentNum),
dumpFileGcChecker: &dumpFileGcChecker{gcLease: dumpFileGcLease, paths: []string{replayer.GetPlanReplayerDirName(), GetOptimizerTraceDirName(), GetExtractTaskDirName()}},
mdlCheckTableInfo: &mdlCheckTableInfo{
Expand All @@ -1083,6 +1081,8 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
},
mdlCheckCh: make(chan struct{}),
}

do.infoCache = infoschema.NewCache(do, int(variable.SchemaVersionCacheLimit.Load()))
do.stopAutoAnalyze.Store(false)
do.wg = util.NewWaitGroupEnhancedWrapper("domain", do.exit, config.GetGlobalConfig().TiDBEnableExitCheck)
do.SchemaValidator = NewSchemaValidator(ddlLease, do)
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/ru_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestWriteRUStatistics(t *testing.T) {
testInfo := &testInfoschema{
groups: infoGroups,
}
testInfoCache := infoschema.NewCache(1)
testInfoCache := infoschema.NewCache(nil, 1)
testInfoCache.Insert(testInfo, uint64(time.Now().Unix()))
testRUWriter.RMClient = testRMClient
testRUWriter.InfoCache = testInfoCache
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func parseLog(retriever *slowQueryRetriever, sctx sessionctx.Context, reader *bu
}

func newSlowQueryRetriever() (*slowQueryRetriever, error) {
newISBuilder, err := infoschema.NewBuilder(nil, nil).InitWithDBInfos(nil, nil, nil, 0)
newISBuilder, err := infoschema.NewBuilder(nil, nil, nil).InitWithDBInfos(nil, nil, nil, 0)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/executor/stmtsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestStmtSummaryRetriverV2_TableStatementsSummary(t *testing.T) {
infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil).InitWithDBInfos(nil, nil, nil, 0)
infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil, nil).InitWithDBInfos(nil, nil, nil, 0)
require.NoError(t, err)
infoSchema := infoSchemaBuilder.Build()
table, err := infoSchema.TableByName(util.InformationSchemaName, model.NewCIStr(infoschema.TableStatementsSummary))
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestStmtSummaryRetriverV2_TableStatementsSummary(t *testing.T) {
}

func TestStmtSummaryRetriverV2_TableStatementsSummaryEvicted(t *testing.T) {
infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil).InitWithDBInfos(nil, nil, nil, 0)
infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil, nil).InitWithDBInfos(nil, nil, nil, 0)
require.NoError(t, err)
infoSchema := infoSchemaBuilder.Build()
table, err := infoSchema.TableByName(util.InformationSchemaName, model.NewCIStr(infoschema.TableStatementsSummaryEvicted))
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestStmtSummaryRetriverV2_TableStatementsSummaryHistory(t *testing.T) {
stmtSummary.Add(stmtsummaryv2.GenerateStmtExecInfo4Test("digest3"))
stmtSummary.Add(stmtsummaryv2.GenerateStmtExecInfo4Test("digest3"))

infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil).InitWithDBInfos(nil, nil, nil, 0)
infoSchemaBuilder, err := infoschema.NewBuilder(nil, nil, nil).InitWithDBInfos(nil, nil, nil, 0)
require.NoError(t, err)
infoSchema := infoSchemaBuilder.Build()
table, err := infoSchema.TableByName(util.InformationSchemaName, model.NewCIStr(infoschema.TableStatementsSummaryHistory))
Expand Down
5 changes: 5 additions & 0 deletions pkg/infoschema/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"cluster.go",
"error.go",
"infoschema.go",
"infoschema_v2.go",
"metric_table_def.go",
"metrics_schema.go",
"tables.go",
Expand Down Expand Up @@ -54,11 +55,15 @@ go_library(
"@com_github_pingcap_kvproto//pkg/diagnosticspb",
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_pingcap_log//:log",
"@com_github_scalalang2_golang_fifo//:golang-fifo",
"@com_github_scalalang2_golang_fifo//sieve",
"@com_github_tidwall_btree//:btree",
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_pd_client//http",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//credentials",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_x_sync//singleflight",
"@org_uber_go_zap//:zap",
],
)
Expand Down
Loading
Loading