Skip to content
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
1 change: 1 addition & 0 deletions br/pkg/restore/log_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go_library(
"//br/pkg/version",
"//pkg/ddl/util",
"//pkg/domain",
"//pkg/infoschema/issyncer",
"//pkg/kv",
"//pkg/meta",
"//pkg/meta/model",
Expand Down
3 changes: 2 additions & 1 deletion br/pkg/restore/log_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/pingcap/tidb/br/pkg/version"
ddlutil "github.com/pingcap/tidb/pkg/ddl/util"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/infoschema/issyncer"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/meta/model"
Expand Down Expand Up @@ -1330,7 +1331,7 @@ func (rc *LogClient) UpdateSchemaVersionFullReload(ctx context.Context) error {
var e error
// To trigger full-reload instead of diff-reload, we need to increase the schema version
// by at least `domain.LoadSchemaDiffVersionGapThreshold`.
schemaVersion, e = t.GenSchemaVersions(64 + domain.LoadSchemaDiffVersionGapThreshold)
schemaVersion, e = t.GenSchemaVersions(64 + issyncer.LoadSchemaDiffVersionGapThreshold)
if e != nil {
return e
}
Expand Down
2 changes: 1 addition & 1 deletion br/tests/br_pitr_long_running_schema_loading/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ echo "wait checkpoint advance"

restart_services

export GO_FAILPOINTS="github.com/pingcap/tidb/pkg/domain/mock-load-schema-long-time=return(true);github.com/pingcap/tidb/br/pkg/task/post-restore-kv-pending=return(true)"
export GO_FAILPOINTS="github.com/pingcap/tidb/pkg/infoschema/issyncer/mock-load-schema-long-time=return(true);github.com/pingcap/tidb/br/pkg/task/post-restore-kv-pending=return(true)"
run_br --pd "$PD_ADDR" restore point -s "local://$TEST_DIR/$TASK_NAME/log" --full-backup-storage "local://$TEST_DIR/$TASK_NAME/full"
export GO_FAILPOINTS=""
1 change: 1 addition & 0 deletions pkg/ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ go_test(
"//pkg/expression",
"//pkg/expression/exprstatic",
"//pkg/infoschema",
"//pkg/infoschema/validatorapi",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/lightning/backend/external",
Expand Down
23 changes: 12 additions & 11 deletions pkg/ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/infoschema/validatorapi"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/meta/model"
Expand Down Expand Up @@ -730,37 +731,37 @@ func TestSchemaValidator(t *testing.T) {
require.NoError(t, err)

ts := ver.Ver
_, res := dom.SchemaValidator.Check(ts, schemaVer, nil, true)
require.Equal(t, domain.ResultSucc, res)
_, res := dom.GetSchemaValidator().Check(ts, schemaVer, nil, true)
require.Equal(t, validatorapi.ResultSucc, res)

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/domain/ErrorMockReloadFailed", `return(true)`))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/infoschema/issyncer/ErrorMockReloadFailed", `return(true)`))

err = dom.Reload()
require.Error(t, err)
_, res = dom.SchemaValidator.Check(ts, schemaVer, nil, true)
require.Equal(t, domain.ResultSucc, res)
_, res = dom.GetSchemaValidator().Check(ts, schemaVer, nil, true)
require.Equal(t, validatorapi.ResultSucc, res)
time.Sleep(dbTestLease)

ver, err = store.CurrentVersion(kv.GlobalTxnScope)
require.NoError(t, err)
ts = ver.Ver
_, res = dom.SchemaValidator.Check(ts, schemaVer, nil, true)
require.Equal(t, domain.ResultUnknown, res)
_, res = dom.GetSchemaValidator().Check(ts, schemaVer, nil, true)
require.Equal(t, validatorapi.ResultUnknown, res)

require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/ErrorMockReloadFailed"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/infoschema/issyncer/ErrorMockReloadFailed"))
err = dom.Reload()
require.NoError(t, err)

_, res = dom.SchemaValidator.Check(ts, schemaVer, nil, true)
require.Equal(t, domain.ResultSucc, res)
_, res = dom.GetSchemaValidator().Check(ts, schemaVer, nil, true)
require.Equal(t, validatorapi.ResultSucc, res)

// For schema check, it tests for getting the result of "ResultUnknown".
is := dom.InfoSchema()
schemaChecker := domain.NewSchemaChecker(dom, is.SchemaMetaVersion(), nil, true)
// Make sure it will retry one time and doesn't take a long time.
domain.SchemaOutOfDateRetryTimes.Store(1)
domain.SchemaOutOfDateRetryInterval.Store(time.Millisecond * 1)
dom.SchemaValidator.Stop()
dom.GetSchemaValidator().Stop()
_, err = schemaChecker.Check(uint64(123456))
require.EqualError(t, err, domain.ErrInfoSchemaExpired.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/placement_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestPlacementPolicy(t *testing.T) {

// Test again with failpoint.
// For https://github.com/pingcap/tidb/issues/54796
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/domain/MockTryLoadDiffError", `return("exchangepartition")`)
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/infoschema/issyncer/MockTryLoadDiffError", `return("exchangepartition")`)
testPlacementPolicy(t)
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/ddl/tests/fail/fail_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,34 +236,34 @@ func TestFailSchemaSyncer(t *testing.T) {
defer func() {
domain.SchemaOutOfDateRetryTimes.Store(originalRetryTimes)
}()
require.True(t, s.dom.SchemaValidator.IsStarted())
require.True(t, s.dom.GetSchemaValidator().IsStarted())
mockSyncer, ok := s.dom.DDL().SchemaSyncer().(*schemaver.MemSyncer)
require.True(t, ok)

// make reload failed.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/domain/ErrorMockReloadFailed", `return(true)`))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/infoschema/issyncer/ErrorMockReloadFailed", `return(true)`))
mockSyncer.CloseSession()
// wait the schemaValidator is stopped.
for range 50 {
if !s.dom.SchemaValidator.IsStarted() {
if !s.dom.GetSchemaValidator().IsStarted() {
break
}
time.Sleep(20 * time.Millisecond)
}

require.False(t, s.dom.SchemaValidator.IsStarted())
require.False(t, s.dom.GetSchemaValidator().IsStarted())
_, err := tk.Exec("insert into t values(1)")
require.Error(t, err)
require.EqualError(t, err, "[domain:8027]Information schema is out of date: schema failed to update in 1 lease, please make sure TiDB can connect to TiKV")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/ErrorMockReloadFailed"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/infoschema/issyncer/ErrorMockReloadFailed"))
// wait the schemaValidator is started.
for range 50 {
if s.dom.SchemaValidator.IsStarted() {
if s.dom.GetSchemaValidator().IsStarted() {
break
}
time.Sleep(100 * time.Millisecond)
}
require.True(t, s.dom.SchemaValidator.IsStarted())
require.True(t, s.dom.GetSchemaValidator().IsStarted())
err = tk.ExecToErr("insert into t values(1)")
require.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tests/indexmerge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestAddPrimaryKeyMergeProcess(t *testing.T) {
var checkErr error
var runDML, backfillDone bool
// only trigger reload when schema version changed
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/domain/disableOnTickReload", "return(true)")
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/infoschema/issyncer/disableOnTickReload", "return(true)")
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeWaitSchemaSynced", func(job *model.Job, _ int64) {
if !runDML && job.Type == model.ActionAddPrimaryKey && job.SchemaState == model.StateWriteReorganization {
idx := testutil.FindIdxInfo(dom, "test", "t", "primary")
Expand Down
15 changes: 6 additions & 9 deletions pkg/domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ go_library(
"ru_stats.go",
"runaway.go",
"schema_checker.go",
"schema_validator.go",
"sysvar_cache.go",
"test_helper.go",
"topn_slow_query.go",
Expand Down Expand Up @@ -42,8 +41,10 @@ go_library(
"//pkg/domain/metrics",
"//pkg/errno",
"//pkg/infoschema",
"//pkg/infoschema/issyncer",
"//pkg/infoschema/metrics",
"//pkg/infoschema/perfschema",
"//pkg/infoschema/validatorapi",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/lightning/common",
Expand Down Expand Up @@ -73,7 +74,6 @@ go_library(
"//pkg/statistics/handle/util",
"//pkg/statistics/util",
"//pkg/store",
"//pkg/store/helper",
"//pkg/ttl/ttlworker",
"//pkg/types",
"//pkg/util",
Expand All @@ -83,7 +83,6 @@ go_library(
"//pkg/util/cpu",
"//pkg/util/dbterror",
"//pkg/util/disttask",
"//pkg/util/domainutil",
"//pkg/util/engine",
"//pkg/util/etcd",
"//pkg/util/execdetails",
Expand All @@ -92,7 +91,6 @@ go_library(
"//pkg/util/globalconn",
"//pkg/util/intest",
"//pkg/util/logutil",
"//pkg/util/mathutil",
"//pkg/util/memory",
"//pkg/util/memoryusagealarm",
"//pkg/util/printer",
Expand All @@ -112,7 +110,6 @@ go_library(
"@com_github_pingcap_kvproto//pkg/pdpb",
"@com_github_pingcap_log//:log",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_client_go_v2//txnkv/transaction",
"@com_github_tikv_pd_client//:client",
Expand Down Expand Up @@ -142,18 +139,19 @@ go_test(
"plan_replayer_test.go",
"ru_stats_test.go",
"schema_checker_test.go",
"schema_validator_test.go",
"topn_slow_query_test.go",
],
embed = [":domain"],
flaky = True,
shard_count = 30,
shard_count = 28,
deps = [
"//pkg/config",
"//pkg/ddl",
"//pkg/domain/infosync",
"//pkg/errno",
"//pkg/infoschema",
"//pkg/infoschema/isvalidator",
"//pkg/infoschema/validatorapi",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/meta",
Expand All @@ -169,9 +167,9 @@ go_test(
"//pkg/sessionctx/variable",
"//pkg/store/mockstore",
"//pkg/testkit",
"//pkg/testkit/testfailpoint",
"//pkg/testkit/testsetup",
"//pkg/types",
"//pkg/util",
"//pkg/util/mathutil",
"//pkg/util/mock",
"//pkg/util/replayer",
Expand All @@ -183,7 +181,6 @@ go_test(
"@com_github_pingcap_kvproto//pkg/resource_manager",
"@com_github_prometheus_client_model//go",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//txnkv/transaction",
"@com_github_tikv_pd_client//:client",
"@com_github_tikv_pd_client//opt",
Expand Down
6 changes: 2 additions & 4 deletions pkg/domain/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/pkg/sessionctx/vardef"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
"github.com/pingcap/tidb/pkg/util/mathutil"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -194,10 +195,7 @@ func TestFetchAllSchemasWithTablesWithFailpoint(t *testing.T) {
require.Equal(t, len(dbs), 1003)

// inject the failpoint
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/domain/failed-fetch-schemas-with-tables", "return()"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/failed-fetch-schemas-with-tables"))
}()
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/infoschema/issyncer/failed-fetch-schemas-with-tables", "return()")
dbs, err = domain.FetchAllSchemasWithTables(m)
require.Error(t, err)
require.Equal(t, err.Error(), "failpoint: failed to fetch schemas with tables")
Expand Down
Loading
Loading