milvus/internal/master/stats_processor.go
sunby a03ab05c6c Add DescribeIndex and DescribeIndexProgress RPC
Signed-off-by: sunby <bingyi.sun@zilliz.com>
2020-12-25 15:39:56 +08:00

86 lines
2.3 KiB
Go

package master
import (
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/msgstream"
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
)
type StatsProcessor struct {
metaTable *metaTable
runtimeStats *RuntimeStats
segmentThreshold float64
segmentThresholdFactor float64
globalTSOAllocator func() (Timestamp, error)
}
func (processor *StatsProcessor) ProcessQueryNodeStats(msgPack *msgstream.MsgPack) error {
for _, msg := range msgPack.Msgs {
statsMsg, ok := msg.(*msgstream.QueryNodeStatsMsg)
if !ok {
return errors.Errorf("Type of message is not QueryNodeSegStatsMsg")
}
for _, segStat := range statsMsg.GetSegStats() {
if err := processor.processSegmentStat(segStat); err != nil {
return err
}
}
for _, fieldStat := range statsMsg.GetFieldStats() {
if err := processor.processFieldStat(statsMsg.PeerID, fieldStat); err != nil {
return err
}
}
}
return nil
}
func (processor *StatsProcessor) processSegmentStat(segStats *internalpb.SegmentStats) error {
if !segStats.GetRecentlyModified() {
return nil
}
segID := segStats.GetSegmentID()
segMeta, err := processor.metaTable.GetSegmentByID(segID)
if err != nil {
return err
}
segMeta.NumRows = segStats.NumRows
segMeta.MemSize = segStats.MemorySize
return processor.metaTable.UpdateSegment(segMeta)
}
func (processor *StatsProcessor) processFieldStat(peerID int64, fieldStats *internalpb.FieldStats) error {
collID := fieldStats.CollectionID
fieldID := fieldStats.FieldID
for _, stat := range fieldStats.IndexStats {
fieldStats := &FieldIndexRuntimeStats{
peerID: peerID,
indexParams: stat.IndexParams,
numOfRelatedSegments: stat.NumRelatedSegments,
}
if err := processor.runtimeStats.UpdateFieldStat(collID, fieldID, fieldStats); err != nil {
return err
}
}
return nil
}
func NewStatsProcessor(mt *metaTable, runTimeStats *RuntimeStats, globalTSOAllocator func() (Timestamp, error)) *StatsProcessor {
return &StatsProcessor{
metaTable: mt,
runtimeStats: runTimeStats,
segmentThreshold: Params.SegmentSize * 1024 * 1024,
segmentThresholdFactor: Params.SegmentSizeFactor,
globalTSOAllocator: globalTSOAllocator,
}
}