2020-09-16 15:21:10 +08:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
2020-11-05 10:52:50 +08:00
|
|
|
"context"
|
2020-09-16 15:21:10 +08:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2020-11-03 14:53:36 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
|
|
|
|
2020-11-03 14:53:36 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2020-09-16 15:21:10 +08:00
|
|
|
)
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
type statsService struct {
|
2020-11-05 10:52:50 +08:00
|
|
|
ctx context.Context
|
|
|
|
msgStream *msgstream.PulsarMsgStream
|
2020-11-09 16:27:11 +08:00
|
|
|
container *ColSegContainer
|
2020-11-05 10:52:50 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func newStatsService(ctx context.Context, container *ColSegContainer, pulsarAddress string) *statsService {
|
2020-11-05 10:52:50 +08:00
|
|
|
// TODO: add pulsar message stream init
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
return &statsService{
|
|
|
|
ctx: ctx,
|
|
|
|
container: container,
|
2020-11-05 10:52:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func (sService *statsService) start() {
|
2020-11-05 10:52:50 +08:00
|
|
|
sleepMillisecondTime := 1000
|
|
|
|
fmt.Println("do segments statistic in ", strconv.Itoa(sleepMillisecondTime), "ms")
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-sService.ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
time.Sleep(time.Duration(sleepMillisecondTime) * time.Millisecond)
|
|
|
|
sService.sendSegmentStatistic()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 15:21:10 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func (sService *statsService) sendSegmentStatistic() {
|
2020-11-13 14:20:51 +08:00
|
|
|
var statisticData = make([]internalpb.SegmentStats, 0)
|
2020-09-16 15:21:10 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
for segmentID, segment := range sService.container.segments {
|
2020-11-05 10:52:50 +08:00
|
|
|
currentMemSize := segment.getMemSize()
|
2020-11-09 16:27:11 +08:00
|
|
|
segment.lastMemSize = currentMemSize
|
2020-09-22 11:21:19 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
segmentNumOfRows := segment.getRowCount()
|
2020-09-22 11:21:19 +08:00
|
|
|
|
2020-11-13 14:20:51 +08:00
|
|
|
stat := internalpb.SegmentStats{
|
2020-09-22 11:21:19 +08:00
|
|
|
// TODO: set master pb's segment id type from uint64 to int64
|
2020-11-13 15:17:18 +08:00
|
|
|
SegmentID: segmentID,
|
2020-09-22 11:21:19 +08:00
|
|
|
MemorySize: currentMemSize,
|
2020-11-03 14:53:36 +08:00
|
|
|
NumRows: segmentNumOfRows,
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
2020-09-22 11:21:19 +08:00
|
|
|
|
|
|
|
statisticData = append(statisticData, stat)
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
|
2020-09-25 14:53:06 +08:00
|
|
|
// fmt.Println("Publish segment statistic")
|
|
|
|
// fmt.Println(statisticData)
|
2020-11-05 10:52:50 +08:00
|
|
|
sService.publicStatistic(&statisticData)
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-13 14:20:51 +08:00
|
|
|
func (sService *statsService) publicStatistic(statistic *[]internalpb.SegmentStats) {
|
2020-11-05 10:52:50 +08:00
|
|
|
// TODO: publish statistic
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|