Skip to content

Commit

Permalink
ddl: move syncer to a single package (pingcap#36994)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Aug 9, 2022
1 parent 42935af commit a849cc2
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 125 deletions.
42 changes: 42 additions & 0 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,13 @@ def go_deps():
sum = "h1:ThE+hJP0fEp4zWLkWHWcRyI2Od0p7DlgYG3Uqrmrcpk=",
version = "v0.1.1",
)
go_repository(
name = "com_github_gostaticanalysis_testutil",
build_file_proto_mode = "disable",
importpath = "github.com/gostaticanalysis/testutil",
sum = "h1:d2/eIbH9XjD1fFwD5SHv8x168fjbQ9PB8hvs8DSEC08=",
version = "v0.3.1-0.20210208050101-bfb5c8eec0e4",
)

go_repository(
name = "com_github_grpc_ecosystem_go_grpc_middleware",
Expand Down Expand Up @@ -2641,6 +2648,27 @@ def go_deps():
sum = "h1:yXiysv1CSK7Q5yjGy1710zZGnsbMUIjluWBxtLXHPBo=",
version = "v0.1.6",
)
go_repository(
name = "com_github_otiai10_copy",
build_file_proto_mode = "disable",
importpath = "github.com/otiai10/copy",
sum = "h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=",
version = "v1.2.0",
)
go_repository(
name = "com_github_otiai10_curr",
build_file_proto_mode = "disable",
importpath = "github.com/otiai10/curr",
sum = "h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI=",
version = "v1.0.0",
)
go_repository(
name = "com_github_otiai10_mint",
build_file_proto_mode = "disable",
importpath = "github.com/otiai10/mint",
sum = "h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=",
version = "v1.3.1",
)

go_repository(
name = "com_github_pascaldekloe_goe",
Expand Down Expand Up @@ -3304,6 +3332,20 @@ def go_deps():
sum = "h1:PKzG7JUTUmVspQTDqtkX9eSiLGossXTybutHwTXuO0A=",
version = "v0.1.1",
)
go_repository(
name = "com_github_tenntenn_modver",
build_file_proto_mode = "disable",
importpath = "github.com/tenntenn/modver",
sum = "h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=",
version = "v1.0.1",
)
go_repository(
name = "com_github_tenntenn_text_transform",
build_file_proto_mode = "disable",
importpath = "github.com/tenntenn/text/transform",
sum = "h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=",
version = "v0.0.0-20200319021203-7eef512accb3",
)

go_repository(
name = "com_github_tetafro_godot",
Expand Down
2 changes: 1 addition & 1 deletion build/linter/filepermission/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "filepermission",
srcs = ["checker.go"],
importpath = "github.com/pingcap/tidb/build/linter/file_permission",
importpath = "github.com/pingcap/tidb/build/linter/filepermission",
visibility = ["//visibility:public"],
deps = ["@org_golang_x_tools//go/analysis"],
)
1 change: 1 addition & 0 deletions ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ go_library(
"//config",
"//ddl/label",
"//ddl/placement",
"//ddl/syncer",
"//ddl/util",
"//distsql",
"//domain/infosync",
Expand Down
15 changes: 8 additions & 7 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl/syncer"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -180,7 +181,7 @@ type DDL interface {
// RegisterStatsHandle registers statistics handle and its corresponding event channel for ddl.
RegisterStatsHandle(*handle.Handle)
// SchemaSyncer gets the schema syncer.
SchemaSyncer() util.SchemaSyncer
SchemaSyncer() syncer.SchemaSyncer
// OwnerManager gets the owner manager.
OwnerManager() owner.Manager
// GetID gets the ddl ID.
Expand Down Expand Up @@ -268,7 +269,7 @@ type ddlCtx struct {
uuid string
store kv.Storage
ownerManager owner.Manager
schemaSyncer util.SchemaSyncer
schemaSyncer syncer.SchemaSyncer
ddlJobDoneCh chan struct{}
ddlEventCh chan<- *util.Event
lease time.Duration // lease is schema lease.
Expand Down Expand Up @@ -513,16 +514,16 @@ func newDDL(ctx context.Context, options ...Option) *ddl {

id := uuid.New().String()
var manager owner.Manager
var syncer util.SchemaSyncer
var schemaSyncer syncer.SchemaSyncer
var deadLockCkr util.DeadTableLockChecker
if etcdCli := opt.EtcdCli; etcdCli == nil {
// The etcdCli is nil if the store is localstore which is only used for testing.
// So we use mockOwnerManager and MockSchemaSyncer.
manager = owner.NewMockManager(ctx, id)
syncer = NewMockSchemaSyncer()
schemaSyncer = NewMockSchemaSyncer()
} else {
manager = owner.NewOwnerManager(ctx, etcdCli, ddlPrompt, id, DDLOwnerKey)
syncer = util.NewSchemaSyncer(etcdCli, id)
schemaSyncer = syncer.NewSchemaSyncer(etcdCli, id)
deadLockCkr = util.NewDeadTableLockChecker(etcdCli)
}

Expand All @@ -541,7 +542,7 @@ func newDDL(ctx context.Context, options ...Option) *ddl {
lease: opt.Lease,
ddlJobDoneCh: make(chan struct{}, 1),
ownerManager: manager,
schemaSyncer: syncer,
schemaSyncer: schemaSyncer,
binlogCli: binloginfo.GetPumpsClient(),
infoCache: opt.InfoCache,
tableLockCkr: deadLockCkr,
Expand Down Expand Up @@ -807,7 +808,7 @@ func (d *ddl) genPlacementPolicyID() (int64, error) {
}

// SchemaSyncer implements DDL.SchemaSyncer interface.
func (d *ddl) SchemaSyncer() util.SchemaSyncer {
func (d *ddl) SchemaSyncer() syncer.SchemaSyncer {
return d.schemaSyncer
}

Expand Down
6 changes: 3 additions & 3 deletions ddl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/ddl/syncer"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/charset"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
clientv3 "go.etcd.io/etcd/client/v3"
)

var _ util.SchemaSyncer = &MockSchemaSyncer{}
var _ syncer.SchemaSyncer = &MockSchemaSyncer{}

const mockCheckVersInterval = 2 * time.Millisecond

Expand All @@ -41,7 +41,7 @@ type MockSchemaSyncer struct {
}

// NewMockSchemaSyncer creates a new mock SchemaSyncer.
func NewMockSchemaSyncer() util.SchemaSyncer {
func NewMockSchemaSyncer() syncer.SchemaSyncer {
return &MockSchemaSyncer{}
}

Expand Down
2 changes: 1 addition & 1 deletion ddl/schematracker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//ddl",
"//ddl/util",
"//ddl/syncer",
"//infoschema",
"//kv",
"//meta/autoid",
Expand Down
4 changes: 2 additions & 2 deletions ddl/schematracker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/ngaut/pools"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/ddl/syncer"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
Expand Down Expand Up @@ -485,7 +485,7 @@ func (d Checker) RegisterStatsHandle(h *handle.Handle) {
}

// SchemaSyncer implements the DDL interface.
func (d Checker) SchemaSyncer() util.SchemaSyncer {
func (d Checker) SchemaSyncer() syncer.SchemaSyncer {
return d.realDDL.SchemaSyncer()
}

Expand Down
4 changes: 2 additions & 2 deletions ddl/schematracker/dm_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/ngaut/pools"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/ddl/syncer"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/owner"
Expand Down Expand Up @@ -1153,7 +1153,7 @@ func (d SchemaTracker) Stop() error {
func (SchemaTracker) RegisterStatsHandle(handle *handle.Handle) {}

// SchemaSyncer implements the DDL interface, it's no-op in DM's case.
func (SchemaTracker) SchemaSyncer() util.SchemaSyncer {
func (SchemaTracker) SchemaSyncer() syncer.SchemaSyncer {
return nil
}

Expand Down
42 changes: 42 additions & 0 deletions ddl/syncer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "syncer",
srcs = ["syncer.go"],
importpath = "github.com/pingcap/tidb/ddl/syncer",
visibility = ["//visibility:public"],
deps = [
"//ddl/util",
"//metrics",
"//util",
"//util/logutil",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@io_etcd_go_etcd_client_v3//:client",
"@io_etcd_go_etcd_client_v3//concurrency",
"@org_uber_go_zap//:zap",
],
)

go_test(
name = "syncer_test",
srcs = ["syncer_test.go"],
flaky = True,
deps = [
":syncer",
"//ddl",
"//ddl/util",
"//infoschema",
"//parser/terror",
"//store/mockstore",
"//util",
"@com_github_pingcap_errors//:errors",
"@com_github_stretchr_testify//require",
"@io_etcd_go_etcd_api_v3//mvccpb",
"@io_etcd_go_etcd_client_v3//:client",
"@io_etcd_go_etcd_server_v3//etcdserver",
"@io_etcd_go_etcd_tests_v3//integration",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
],
)
Loading

0 comments on commit a849cc2

Please sign in to comment.