Skip to content

Commit

Permalink
ddl: Implement basic version of TiFlash replica management (#30842)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinNeo authored Jan 19, 2022
1 parent a4e8ed5 commit 493fe78
Show file tree
Hide file tree
Showing 14 changed files with 1,208 additions and 33 deletions.
37 changes: 31 additions & 6 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ type ddl struct {
limitJobCh chan *limitJobTask

*ddlCtx
workers map[workerType]*worker
sessPool *sessionPool
delRangeMgr delRangeManager
workers map[workerType]*worker
sessPool *sessionPool
delRangeMgr delRangeManager
enableTiFlashPoll bool
}

// ddlCtx is the context when we use worker to handle DDL jobs.
Expand Down Expand Up @@ -225,6 +226,25 @@ func (dc *ddlCtx) isOwner() bool {
return isOwner
}

// EnableTiFlashPoll enables TiFlash poll loop aka PollTiFlashReplicaStatus.
func EnableTiFlashPoll(d interface{}) {
if dd, ok := d.(*ddl); ok {
dd.enableTiFlashPoll = true
}
}

// DisableTiFlashPoll disables TiFlash poll loop aka PollTiFlashReplicaStatus.
func DisableTiFlashPoll(d interface{}) {
if dd, ok := d.(*ddl); ok {
dd.enableTiFlashPoll = false
}
}

// IsTiFlashPollEnabled reveals enableTiFlashPoll
func (d *ddl) IsTiFlashPollEnabled() bool {
return d.enableTiFlashPoll
}

// RegisterStatsHandle registers statistics handle and its corresponding even channel for ddl.
func (d *ddl) RegisterStatsHandle(h *handle.Handle) {
d.ddlCtx.statsHandle = h
Expand Down Expand Up @@ -307,9 +327,10 @@ func newDDL(ctx context.Context, options ...Option) *ddl {
ddlCtx.mu.hook = opt.Hook
ddlCtx.mu.interceptor = &BaseInterceptor{}
d := &ddl{
ctx: ctx,
ddlCtx: ddlCtx,
limitJobCh: make(chan *limitJobTask, batchAddingJobs),
ctx: ctx,
ddlCtx: ddlCtx,
limitJobCh: make(chan *limitJobTask, batchAddingJobs),
enableTiFlashPoll: true,
}

return d
Expand Down Expand Up @@ -382,6 +403,10 @@ func (d *ddl) Start(ctxPool *pools.ResourcePool) error {
variable.RegisterStatistics(d)

metrics.DDLCounter.WithLabelValues(metrics.CreateDDLInstance).Inc()

// Start some background routine to manage TiFlash replica.
go d.PollTiFlashRoutine()

return nil
}

Expand Down
Loading

0 comments on commit 493fe78

Please sign in to comment.