2021-11-04 19:15:41 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 11:30:19 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-04 19:15:41 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:30:19 +08:00
|
|
|
//
|
2021-11-04 19:15:41 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 11:30:19 +08:00
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
2021-03-05 10:15:27 +08:00
|
|
|
"errors"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-02-03 17:30:10 +08:00
|
|
|
)
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// UnmarshalFunc is an interface that has been implemented by each Msg
|
2021-02-03 17:30:10 +08:00
|
|
|
type UnmarshalFunc func(interface{}) (TsMsg, error)
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// UnmarshalDispatcher is an interface contains method Unmarshal
|
2021-02-03 17:30:10 +08:00
|
|
|
type UnmarshalDispatcher interface {
|
|
|
|
Unmarshal(input interface{}, msgType commonpb.MsgType) (TsMsg, error)
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// UnmarshalDispatcherFactory is a factory to generate an object which implement interface UnmarshalDispatcher
|
2021-02-03 17:30:10 +08:00
|
|
|
type UnmarshalDispatcherFactory interface {
|
|
|
|
NewUnmarshalDispatcher() *UnmarshalDispatcher
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// ProtoUnmarshalDispatcher is Unmarshal Dispatcher which used for data of proto type
|
2021-02-03 17:30:10 +08:00
|
|
|
type ProtoUnmarshalDispatcher struct {
|
|
|
|
TempMap map[commonpb.MsgType]UnmarshalFunc
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// Unmarshal will forward unmarshal request to msg type specified unmarshal function
|
2021-02-03 17:30:10 +08:00
|
|
|
func (p *ProtoUnmarshalDispatcher) Unmarshal(input interface{}, msgType commonpb.MsgType) (TsMsg, error) {
|
|
|
|
unmarshalFunc, ok := p.TempMap[msgType]
|
|
|
|
if !ok {
|
2021-03-05 10:15:27 +08:00
|
|
|
return nil, errors.New("not set unmarshalFunc for this messageType")
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
|
|
|
return unmarshalFunc(input)
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:52:02 +08:00
|
|
|
// ProtoUDFactory is a factory to generate ProtoUnmarshalDispatcher object
|
2021-02-03 17:30:10 +08:00
|
|
|
type ProtoUDFactory struct{}
|
|
|
|
|
2021-12-22 21:33:09 +08:00
|
|
|
// NewUnmarshalDispatcher returns a new UnmarshalDispatcher
|
2021-02-03 17:30:10 +08:00
|
|
|
func (pudf *ProtoUDFactory) NewUnmarshalDispatcher() *ProtoUnmarshalDispatcher {
|
|
|
|
insertMsg := InsertMsg{}
|
|
|
|
deleteMsg := DeleteMsg{}
|
|
|
|
searchMsg := SearchMsg{}
|
|
|
|
searchResultMsg := SearchResultMsg{}
|
2021-06-23 20:26:10 +08:00
|
|
|
retrieveMsg := RetrieveMsg{}
|
|
|
|
retrieveResultMsg := RetrieveResultMsg{}
|
2021-02-03 17:30:10 +08:00
|
|
|
timeTickMsg := TimeTickMsg{}
|
|
|
|
createCollectionMsg := CreateCollectionMsg{}
|
|
|
|
dropCollectionMsg := DropCollectionMsg{}
|
|
|
|
createPartitionMsg := CreatePartitionMsg{}
|
|
|
|
dropPartitionMsg := DropPartitionMsg{}
|
|
|
|
queryNodeSegStatsMsg := QueryNodeStatsMsg{}
|
2021-05-25 15:35:37 +08:00
|
|
|
dataNodeTtMsg := DataNodeTtMsg{}
|
2021-10-09 14:45:00 +08:00
|
|
|
sealedSegmentsChangeInfoMsg := SealedSegmentsChangeInfoMsg{}
|
2021-02-03 17:30:10 +08:00
|
|
|
|
|
|
|
p := &ProtoUnmarshalDispatcher{}
|
|
|
|
p.TempMap = make(map[commonpb.MsgType]UnmarshalFunc)
|
2021-03-10 14:45:35 +08:00
|
|
|
p.TempMap[commonpb.MsgType_Insert] = insertMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_Delete] = deleteMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_Search] = searchMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_SearchResult] = searchResultMsg.Unmarshal
|
2021-06-23 20:26:10 +08:00
|
|
|
p.TempMap[commonpb.MsgType_Retrieve] = retrieveMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_RetrieveResult] = retrieveResultMsg.Unmarshal
|
2021-03-10 14:45:35 +08:00
|
|
|
p.TempMap[commonpb.MsgType_TimeTick] = timeTickMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_QueryNodeStats] = queryNodeSegStatsMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_CreateCollection] = createCollectionMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_DropCollection] = dropCollectionMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_CreatePartition] = createPartitionMsg.Unmarshal
|
|
|
|
p.TempMap[commonpb.MsgType_DropPartition] = dropPartitionMsg.Unmarshal
|
2021-05-25 15:35:37 +08:00
|
|
|
p.TempMap[commonpb.MsgType_DataNodeTt] = dataNodeTtMsg.Unmarshal
|
2021-10-09 14:45:00 +08:00
|
|
|
p.TempMap[commonpb.MsgType_SealedSegmentsChangeInfo] = sealedSegmentsChangeInfoMsg.Unmarshal
|
2021-02-03 17:30:10 +08:00
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// MemUnmarshalDispatcher ant its factory
|
|
|
|
|
|
|
|
//type MemUDFactory struct {
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
//func (mudf *MemUDFactory) NewUnmarshalDispatcher() *UnmarshalDispatcher {
|
|
|
|
//
|
|
|
|
//}
|