mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
163 lines
4.1 KiB
Go
163 lines
4.1 KiB
Go
package util
|
|
|
|
import (
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
|
)
|
|
|
|
type TsMsg = msgstream.TsMsg
|
|
type MsgPack = msgstream.MsgPack
|
|
type MsgType = msgstream.MsgType
|
|
type UniqueID = msgstream.UniqueID
|
|
type BaseMsg = msgstream.BaseMsg
|
|
type Timestamp = msgstream.Timestamp
|
|
type IntPrimaryKey = msgstream.IntPrimaryKey
|
|
type TimeTickMsg = msgstream.TimeTickMsg
|
|
type QueryNodeStatsMsg = msgstream.QueryNodeStatsMsg
|
|
|
|
func RepackFunc(msgs []TsMsg, hashKeys [][]int32) (map[int32]*MsgPack, error) {
|
|
result := make(map[int32]*MsgPack)
|
|
for i, request := range msgs {
|
|
keys := hashKeys[i]
|
|
for _, channelID := range keys {
|
|
_, ok := result[channelID]
|
|
if !ok {
|
|
msgPack := MsgPack{}
|
|
result[channelID] = &msgPack
|
|
}
|
|
result[channelID].Msgs = append(result[channelID].Msgs, request)
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func GetTsMsg(msgType MsgType, reqID UniqueID, hashValue uint32) TsMsg {
|
|
baseMsg := BaseMsg{
|
|
BeginTimestamp: 0,
|
|
EndTimestamp: 0,
|
|
HashValues: []uint32{hashValue},
|
|
}
|
|
switch msgType {
|
|
case commonpb.MsgType_kInsert:
|
|
insertRequest := internalpb2.InsertRequest{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kInsert,
|
|
MsgID: reqID,
|
|
Timestamp: 11,
|
|
SourceID: reqID,
|
|
},
|
|
CollectionName: "Collection",
|
|
PartitionName: "Partition",
|
|
SegmentID: 1,
|
|
ChannelID: "0",
|
|
Timestamps: []Timestamp{1},
|
|
RowIDs: []int64{1},
|
|
RowData: []*commonpb.Blob{{}},
|
|
}
|
|
insertMsg := &msgstream.InsertMsg{
|
|
BaseMsg: baseMsg,
|
|
InsertRequest: insertRequest,
|
|
}
|
|
return insertMsg
|
|
case commonpb.MsgType_kDelete:
|
|
deleteRequest := internalpb2.DeleteRequest{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kDelete,
|
|
MsgID: reqID,
|
|
Timestamp: 11,
|
|
SourceID: reqID,
|
|
},
|
|
CollectionName: "Collection",
|
|
ChannelID: "1",
|
|
Timestamps: []Timestamp{1},
|
|
PrimaryKeys: []IntPrimaryKey{1},
|
|
}
|
|
deleteMsg := &msgstream.DeleteMsg{
|
|
BaseMsg: baseMsg,
|
|
DeleteRequest: deleteRequest,
|
|
}
|
|
return deleteMsg
|
|
case commonpb.MsgType_kSearch:
|
|
searchRequest := internalpb2.SearchRequest{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kSearch,
|
|
MsgID: reqID,
|
|
Timestamp: 11,
|
|
SourceID: reqID,
|
|
},
|
|
Query: nil,
|
|
ResultChannelID: "0",
|
|
}
|
|
searchMsg := &msgstream.SearchMsg{
|
|
BaseMsg: baseMsg,
|
|
SearchRequest: searchRequest,
|
|
}
|
|
return searchMsg
|
|
case commonpb.MsgType_kSearchResult:
|
|
searchResult := internalpb2.SearchResults{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kSearchResult,
|
|
MsgID: reqID,
|
|
Timestamp: 1,
|
|
SourceID: reqID,
|
|
},
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_SUCCESS},
|
|
ResultChannelID: "0",
|
|
}
|
|
searchResultMsg := &msgstream.SearchResultMsg{
|
|
BaseMsg: baseMsg,
|
|
SearchResults: searchResult,
|
|
}
|
|
return searchResultMsg
|
|
case commonpb.MsgType_kTimeTick:
|
|
timeTickResult := internalpb2.TimeTickMsg{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kTimeTick,
|
|
MsgID: reqID,
|
|
Timestamp: 1,
|
|
SourceID: reqID,
|
|
},
|
|
}
|
|
timeTickMsg := &TimeTickMsg{
|
|
BaseMsg: baseMsg,
|
|
TimeTickMsg: timeTickResult,
|
|
}
|
|
return timeTickMsg
|
|
case commonpb.MsgType_kQueryNodeStats:
|
|
queryNodeSegStats := internalpb2.QueryNodeStats{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kQueryNodeStats,
|
|
SourceID: reqID,
|
|
},
|
|
}
|
|
queryNodeSegStatsMsg := &QueryNodeStatsMsg{
|
|
BaseMsg: baseMsg,
|
|
QueryNodeStats: queryNodeSegStats,
|
|
}
|
|
return queryNodeSegStatsMsg
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetTimeTickMsg(reqID UniqueID, hashValue uint32, time uint64) TsMsg {
|
|
baseMsg := BaseMsg{
|
|
BeginTimestamp: 0,
|
|
EndTimestamp: 0,
|
|
HashValues: []uint32{hashValue},
|
|
}
|
|
timeTickResult := internalpb2.TimeTickMsg{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_kTimeTick,
|
|
MsgID: reqID,
|
|
Timestamp: time,
|
|
SourceID: reqID,
|
|
},
|
|
}
|
|
timeTickMsg := &TimeTickMsg{
|
|
BaseMsg: baseMsg,
|
|
TimeTickMsg: timeTickResult,
|
|
}
|
|
return timeTickMsg
|
|
}
|