2021-11-04 11:13:50 +00: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 03:30:19 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-04 11:13:50 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 03:30:19 +00:00
|
|
|
//
|
2021-11-04 11:13:50 +00: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 03:30:19 +00:00
|
|
|
|
2020-10-29 12:42:47 +00:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
2021-02-04 06:37:12 +00:00
|
|
|
"context"
|
|
|
|
|
2022-03-03 13:57:56 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream/mqwrapper"
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2020-11-03 06:53:36 +00:00
|
|
|
)
|
2020-10-29 12:42:47 +00:00
|
|
|
|
2021-09-27 15:52:02 +00:00
|
|
|
// UniqueID is an alias for short
|
2020-11-04 09:58:43 +00:00
|
|
|
type UniqueID = typeutil.UniqueID
|
2021-09-27 15:52:02 +00:00
|
|
|
|
|
|
|
// Timestamp is an alias for short
|
2020-11-04 09:58:43 +00:00
|
|
|
type Timestamp = typeutil.Timestamp
|
2021-09-27 15:52:02 +00:00
|
|
|
|
|
|
|
// IntPrimaryKey is an alias for short
|
2020-11-04 09:58:43 +00:00
|
|
|
type IntPrimaryKey = typeutil.IntPrimaryKey
|
2021-09-27 15:52:02 +00:00
|
|
|
|
|
|
|
// MsgPosition is an alias for short
|
2021-03-12 06:22:09 +00:00
|
|
|
type MsgPosition = internalpb.MsgPosition
|
2021-09-27 15:52:02 +00:00
|
|
|
|
|
|
|
// MessageID is an alias for short
|
2022-03-03 13:57:56 +00:00
|
|
|
type MessageID = mqwrapper.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
|
|
|
}
|
|
|
|
|
2021-09-27 15:52:02 +00:00
|
|
|
// RepackFunc is a function type which used to repack message after hash by primary key
|
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()
|
2022-03-15 06:45:22 +00:00
|
|
|
|
2021-02-04 06:37:12 +00:00
|
|
|
AsProducer(channels []string)
|
2022-03-15 06:45:22 +00:00
|
|
|
Produce(*MsgPack) error
|
2021-02-04 06:37:12 +00:00
|
|
|
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-10-11 03:38:57 +00:00
|
|
|
ProduceMark(*MsgPack) (map[string][]MessageID, error)
|
2021-03-25 06:41:46 +00:00
|
|
|
Broadcast(*MsgPack) error
|
2021-09-27 06:10:09 +00:00
|
|
|
BroadcastMark(*MsgPack) (map[string][]MessageID, error)
|
2022-03-15 06:45:22 +00:00
|
|
|
|
|
|
|
AsConsumer(channels []string, subName string)
|
|
|
|
AsConsumerWithPosition(channels []string, subName string, position mqwrapper.SubscriptionInitialPosition)
|
|
|
|
Chan() <-chan *MsgPack
|
2021-05-29 15:21:34 +00:00
|
|
|
Seek(offset []*MsgPosition) error
|
2022-03-15 06:45:22 +00:00
|
|
|
|
|
|
|
GetLatestMsgID(channel string) (MessageID, error)
|
2020-11-12 03:18:23 +00:00
|
|
|
}
|
2021-02-04 06:37:12 +00:00
|
|
|
|
|
|
|
type Factory interface {
|
|
|
|
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)
|
2022-06-16 09:28:11 +00:00
|
|
|
NewMsgStreamDisposer(ctx context.Context) func([]string, string) error
|
2021-02-04 06:37:12 +00:00
|
|
|
}
|