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"
|
|
|
|
|
2023-06-08 17:28:37 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
2023-04-06 11:14:32 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
|
|
|
|
"github.com/milvus-io/milvus/pkg/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
|
2023-03-04 15:21:50 +00:00
|
|
|
type MsgPosition = msgpb.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
|
|
|
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-25 11:53:15 +00:00
|
|
|
GetProduceChannels() []string
|
2022-12-05 12:55:17 +00:00
|
|
|
Broadcast(*MsgPack) (map[string][]MessageID, error)
|
2022-03-15 06:45:22 +00:00
|
|
|
|
2023-09-08 01:51:17 +00:00
|
|
|
AsConsumer(ctx context.Context, channels []string, subName string, position mqwrapper.SubscriptionInitialPosition) error
|
2022-03-15 06:45:22 +00:00
|
|
|
Chan() <-chan *MsgPack
|
2023-09-08 01:51:17 +00:00
|
|
|
Seek(ctx context.Context, offset []*MsgPosition) error
|
2022-03-15 06:45:22 +00:00
|
|
|
|
|
|
|
GetLatestMsgID(channel string) (MessageID, error)
|
2023-04-03 08:44:23 +00:00
|
|
|
CheckTopicValid(channel string) error
|
2023-10-20 06:26:09 +00:00
|
|
|
|
|
|
|
EnableProduce(can bool)
|
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)
|
2022-06-16 09:28:11 +00:00
|
|
|
NewMsgStreamDisposer(ctx context.Context) func([]string, string) error
|
2021-02-04 06:37:12 +00:00
|
|
|
}
|