queryCoord的checkerController分析
milvus版本:v2.3.2
启动queryCoordv2的时候会启动几种类型的checker。
堆栈:
Run()(cmd\components\query_coord.go) |--qs.svr.Run()(同上) |--s.start()(\internal\distributed\querycoord\service.go) |--s.queryCoord.Start()(同上) |--Start()(internal\querycoordv2\server.go) |--s.startQueryCoord()(同上) |--s.startServerLoop()(同上) |--s.checkerController.Start()(同上) |--go controller.startChecker
AI 代码解读
代码如下:
func (controller *CheckerController) Start() {
ctx, cancel := context.WithCancel(context.Background())
controller.cancel = cancel
for checkerType := range controller.checkers {
go controller.startChecker(ctx, checkerType)
}
}
AI 代码解读
controller.checkers有4个值:
channel_checker、segment_checker、balance_checker、index_checker。
每种类型的checker启动一个goroutine。
按类型启动checker:
func (controller *CheckerController) startChecker(ctx context.Context, checkerType string) {
interval := getCheckerInterval(checkerType)
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
log.Info("Checker stopped",
zap.String("type", checkerType))
return
case <-ticker.C:
controller.check(ctx, checkerType)
case <-controller.manualCheckChs[checkerType]:
ticker.Stop()
controller.check(ctx, checkerType)
ticker.Reset(interval)
}
}
}
AI 代码解读
interval控制参数:
func getCheckerInterval(checkerType string) time.Duration {
switch checkerType {
case segmentChecker:
return Params.QueryCoordCfg.SegmentCheckInterval.GetAsDuration(time.Millisecond)
case channelChecker:
return Params.QueryCoordCfg.ChannelCheckInterval.GetAsDuration(time.Millisecond)
case balanceChecker:
return Params.QueryCoordCfg.BalanceCheckInterval.GetAsDuration(time.Millisecond)
case indexChecker:
return Params.QueryCoordCfg.IndexCheckInterval.GetAsDuration(time.Millisecond)
default:
return Params.QueryCoordCfg.CheckInterval.GetAsDuration(time.Millisecond)
}
}
AI 代码解读
代码中默认值:
单位毫秒 queryCoord.checkSegmentInterval = 1000 queryCoord.checkChannelInterval = 1000 queryCoord.BalanceCheckInterval = 10000 queryCoord.checkIndexInterval = 10000
AI 代码解读
CheckInterval参数已废弃。