2021-04-19 03:30:19 +00:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-10-29 12:42:47 +00:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
2021-02-04 06:37:12 +00:00
|
|
|
"context"
|
|
|
|
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-09-27 06:10:09 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/mqclient"
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2020-11-03 06:53:36 +00:00
|
|
|
)
|
2020-10-29 12:42:47 +00:00
|
|
|
|
2020-11-04 09:58:43 +00:00
|
|
|
type UniqueID = typeutil.UniqueID
|
|
|
|
type Timestamp = typeutil.Timestamp
|
|
|
|
type IntPrimaryKey = typeutil.IntPrimaryKey
|
2021-03-12 06:22:09 +00:00
|
|
|
type MsgPosition = internalpb.MsgPosition
|
2021-09-27 06:10:09 +00:00
|
|
|
type MessageID = mqclient.MessageID
|
2020-11-04 09:58:43 +00:00
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// MsgPack represents a batch of msg in msgstream
|
2020-10-29 12:42:47 +00:00
|
|
|
type MsgPack struct {
|
2021-01-20 09:34:50 +00:00
|
|
|
BeginTs Timestamp
|
|
|
|
EndTs Timestamp
|
|
|
|
Msgs []TsMsg
|
|
|
|
StartPositions []*MsgPosition
|
2021-03-16 09:55:42 +00:00
|
|
|
EndPositions []*MsgPosition
|
2020-10-29 12:42:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 06:10:07 +00:00
|
|
|
type RepackFunc func(msgs []TsMsg, hashKeys [][]int32) (map[int32]*MsgPack, error)
|
2020-10-29 12:42:47 +00:00
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// MsgStream is an interface that can be used to produce and consume message on message queue
|
2020-10-29 12:42:47 +00:00
|
|
|
type MsgStream interface {
|
2020-11-02 08:01:04 +00:00
|
|
|
Start()
|
|
|
|
Close()
|
2021-02-03 09:30:10 +00:00
|
|
|
Chan() <-chan *MsgPack
|
2021-02-04 06:37:12 +00:00
|
|
|
AsProducer(channels []string)
|
|
|
|
AsConsumer(channels []string, subName string)
|
|
|
|
SetRepackFunc(repackFunc RepackFunc)
|
2021-05-24 08:30:09 +00:00
|
|
|
ComputeProduceChannelIndexes(tsMsgs []TsMsg) [][]int32
|
2021-05-25 11:53:15 +00:00
|
|
|
GetProduceChannels() []string
|
2021-03-25 06:41:46 +00:00
|
|
|
Produce(*MsgPack) error
|
|
|
|
Broadcast(*MsgPack) error
|
2021-09-27 06:10:09 +00:00
|
|
|
BroadcastMark(*MsgPack) (map[string][]MessageID, error)
|
2021-03-25 06:41:46 +00:00
|
|
|
Consume() *MsgPack
|
2021-05-29 15:21:34 +00:00
|
|
|
Seek(offset []*MsgPosition) error
|
2020-11-12 03:18:23 +00:00
|
|
|
}
|
2021-02-04 06:37:12 +00:00
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// Factory is an interface that can be used to generate a new msgstream object
|
2021-02-04 06:37:12 +00:00
|
|
|
type Factory interface {
|
2021-02-08 06:30:54 +00:00
|
|
|
SetParams(params map[string]interface{}) error
|
2021-02-04 06:37:12 +00:00
|
|
|
NewMsgStream(ctx context.Context) (MsgStream, error)
|
|
|
|
NewTtMsgStream(ctx context.Context) (MsgStream, error)
|
2021-03-19 12:16:04 +00:00
|
|
|
NewQueryMsgStream(ctx context.Context) (MsgStream, error)
|
2021-02-04 06:37:12 +00:00
|
|
|
}
|