2020-09-16 15:21:10 +08:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
masterPb "github.com/czs007/suvlim/pkg/master/grpc/master"
|
|
|
|
msgPb "github.com/czs007/suvlim/pkg/master/grpc/message"
|
|
|
|
"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 {
|
|
|
|
log.Println("Segment have been closed")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("timeNow = ", timeNow, "SegmentCloseTime = ", segment.SegmentCloseTime)
|
|
|
|
if timeNow >= segment.SegmentCloseTime {
|
|
|
|
go segment.CloseSegment(collection)
|
2020-09-16 15:21:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *QueryNode) SegmentManagementService() {
|
2020-09-23 19:51:14 +08:00
|
|
|
sleepMillisecondTime := 3000
|
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 {
|
|
|
|
time.Sleep(time.Duration(sleepMillisecondTime) * time.Millisecond)
|
|
|
|
node.SegmentsManagement()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-23 19:51:14 +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-23 19:51:14 +08:00
|
|
|
sleepMillisecondTime := 3000
|
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 {
|
|
|
|
time.Sleep(time.Duration(sleepMillisecondTime) * time.Millisecond)
|
|
|
|
node.SegmentStatistic(sleepMillisecondTime)
|
|
|
|
}
|
|
|
|
}
|