2020-09-16 15:21:10 +08:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-24 18:04:57 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2020-09-16 15:21:10 +08:00
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-10-24 10:45:57 +08:00
|
|
|
//func (node *QueryNode) SegmentsManagement() {
|
|
|
|
// //node.queryNodeTimeSync.UpdateTSOTimeSync()
|
|
|
|
// //var timeNow = node.queryNodeTimeSync.TSOTimeSync
|
|
|
|
//
|
|
|
|
// timeNow := node.messageClient.GetTimeNow() >> 18
|
|
|
|
//
|
|
|
|
// for _, collection := range node.Collections {
|
|
|
|
// for _, partition := range collection.Partitions {
|
|
|
|
// for _, segment := range partition.Segments {
|
|
|
|
// if segment.SegmentStatus != SegmentOpened {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // fmt.Println("timeNow = ", timeNow, "SegmentCloseTime = ", segment.SegmentCloseTime)
|
|
|
|
// if timeNow >= segment.SegmentCloseTime {
|
|
|
|
// go segment.CloseSegment(collection)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//func (node *QueryNode) SegmentManagementService() {
|
|
|
|
// sleepMillisecondTime := 1000
|
|
|
|
// fmt.Println("do segments management in ", strconv.Itoa(sleepMillisecondTime), "ms")
|
|
|
|
// for {
|
|
|
|
// 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) {
|
2020-10-24 18:04:57 +08:00
|
|
|
var statisticData = make([]internalpb.SegmentStatistics, 0)
|
2020-09-16 15:21:10 +08:00
|
|
|
|
2020-09-22 11:21:19 +08:00
|
|
|
for segmentID, segment := range node.SegmentsMap {
|
|
|
|
currentMemSize := segment.GetMemSize()
|
|
|
|
segment.LastMemSize = currentMemSize
|
|
|
|
|
2020-09-22 11:47:25 +08:00
|
|
|
segmentNumOfRows := segment.GetRowCount()
|
2020-09-22 11:21:19 +08:00
|
|
|
|
2020-10-24 18:04:57 +08:00
|
|
|
stat := internalpb.SegmentStatistics{
|
2020-09-22 11:21:19 +08:00
|
|
|
// TODO: set master pb's segment id type from uint64 to int64
|
2020-10-29 19:55:57 +08:00
|
|
|
SegmentId: segmentID,
|
2020-09-22 11:21:19 +08:00
|
|
|
MemorySize: currentMemSize,
|
2020-10-24 18:04:57 +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-09-16 15:21:10 +08:00
|
|
|
var status = node.PublicStatistic(&statisticData)
|
2020-10-24 18:04:57 +08:00
|
|
|
if status.ErrorCode != commonpb.ErrorCode_SUCCESS {
|
2020-09-16 15:21:10 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|