2020-09-16 15:21:10 +08:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-19 18:31:00 +08:00
|
|
|
masterPb "github.com/zilliztech/milvus-distributed/internal/proto/master"
|
|
|
|
msgPb "github.com/zilliztech/milvus-distributed/internal/proto/message"
|
2020-09-16 15:21:10 +08:00
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (node *QueryNode) SegmentsManagement() {
|
2020-09-22 11:21:19 +08:00
|
|
|
//node.queryNodeTimeSync.UpdateTSOTimeSync()
|
|
|
|
//var timeNow = node.queryNodeTimeSync.TSOTimeSync
|
|
|
|
|
2020-09-23 19:51:14 +08:00
|
|
|
timeNow := node.messageClient.GetTimeNow() >> 18
|
2020-09-22 11:21:19 +08:00
|
|
|
|
2020-09-16 15:21:10 +08:00
|
|
|
for _, collection := range node.Collections {
|
|
|
|
for _, partition := range collection.Partitions {
|
2020-09-23 19:51:14 +08:00
|
|
|
for _, segment := range partition.Segments {
|
|
|
|
if segment.SegmentStatus != SegmentOpened {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-10-15 21:31:50 +08:00
|
|
|
// fmt.Println("timeNow = ", timeNow, "SegmentCloseTime = ", segment.SegmentCloseTime)
|
2020-09-23 19:51:14 +08:00
|
|
|
if timeNow >= segment.SegmentCloseTime {
|
|
|
|
go segment.CloseSegment(collection)
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *QueryNode) SegmentManagementService() {
|
2020-09-24 14:19:29 +08:00
|
|
|
sleepMillisecondTime := 1000
|
2020-09-18 01:53:18 +08:00
|
|
|
fmt.Println("do segments management in ", strconv.Itoa(sleepMillisecondTime), "ms")
|
2020-09-16 15:21:10 +08:00
|
|
|
for {
|
2020-10-15 21:31:50 +08:00
|
|
|
select {
|
|
|
|
case <-node.ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
time.Sleep(time.Duration(sleepMillisecondTime) * time.Millisecond)
|
|
|
|
node.SegmentsManagement()
|
|
|
|
}
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *QueryNode) SegmentStatistic(sleepMillisecondTime int) {
|
|
|
|
var statisticData = make([]masterPb.SegmentStat, 0)
|
|
|
|
|
2020-09-22 11:21:19 +08:00
|
|
|
//for _, collection := range node.Collections {
|
|
|
|
// for _, partition := range collection.Partitions {
|
|
|
|
// for _, openedSegment := range partition.OpenedSegments {
|
|
|
|
// currentMemSize := openedSegment.GetMemSize()
|
|
|
|
// memIncreaseRate := float32((int64(currentMemSize))-(int64(openedSegment.LastMemSize))) / (float32(sleepMillisecondTime) / 1000)
|
|
|
|
// stat := masterPb.SegmentStat{
|
|
|
|
// // TODO: set master pb's segment id type from uint64 to int64
|
|
|
|
// SegmentId: uint64(openedSegment.SegmentId),
|
|
|
|
// MemorySize: currentMemSize,
|
|
|
|
// MemoryRate: memIncreaseRate,
|
|
|
|
// }
|
|
|
|
// statisticData = append(statisticData, stat)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
for segmentID, segment := range node.SegmentsMap {
|
|
|
|
currentMemSize := segment.GetMemSize()
|
|
|
|
memIncreaseRate := float32((int64(currentMemSize))-(int64(segment.LastMemSize))) / (float32(sleepMillisecondTime) / 1000)
|
|
|
|
segment.LastMemSize = currentMemSize
|
|
|
|
|
2020-09-22 11:47:25 +08:00
|
|
|
segmentStatus := segment.SegmentStatus
|
|
|
|
segmentNumOfRows := segment.GetRowCount()
|
2020-09-22 11:21:19 +08:00
|
|
|
|
|
|
|
stat := masterPb.SegmentStat{
|
|
|
|
// TODO: set master pb's segment id type from uint64 to int64
|
2020-09-22 11:47:25 +08:00
|
|
|
SegmentId: uint64(segmentID),
|
2020-09-22 11:21:19 +08:00
|
|
|
MemorySize: currentMemSize,
|
|
|
|
MemoryRate: memIncreaseRate,
|
2020-09-22 11:47:25 +08:00
|
|
|
Status: masterPb.SegmentStatus(segmentStatus),
|
|
|
|
Rows: 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-09-16 15:21:10 +08:00
|
|
|
var status = node.PublicStatistic(&statisticData)
|
|
|
|
if status.ErrorCode != msgPb.ErrorCode_SUCCESS {
|
|
|
|
log.Printf("Publish segments statistic failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *QueryNode) SegmentStatisticService() {
|
2020-09-24 14:19:29 +08:00
|
|
|
sleepMillisecondTime := 1000
|
2020-09-18 01:53:18 +08:00
|
|
|
fmt.Println("do segments statistic in ", strconv.Itoa(sleepMillisecondTime), "ms")
|
2020-09-16 15:21:10 +08:00
|
|
|
for {
|
2020-10-15 21:31:50 +08:00
|
|
|
select {
|
|
|
|
case <-node.ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
time.Sleep(time.Duration(sleepMillisecondTime) * time.Millisecond)
|
|
|
|
node.SegmentStatistic(sleepMillisecondTime)
|
|
|
|
}
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
}
|