chyezh cc8f7aa110
fix: streaming service related fix patch (#34696)
issue: #33285

- add idAlloc interface
- fix binary unsafe bug for message
- fix service discovery lost when repeated address with different server
id

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2024-07-16 15:49:38 +08:00

96 lines
2.5 KiB
Go

package options
import (
"github.com/milvus-io/milvus/pkg/streaming/util/message"
)
const (
DeliverPolicyTypeAll deliverPolicyType = 1
DeliverPolicyTypeLatest deliverPolicyType = 2
DeliverPolicyTypeStartFrom deliverPolicyType = 3
DeliverPolicyTypeStartAfter deliverPolicyType = 4
DeliverFilterTypeTimeTickGT deliverFilterType = 1
DeliverFilterTypeTimeTickGTE deliverFilterType = 2
DeliverFilterTypeVChannel deliverFilterType = 3
)
type (
deliverPolicyType int
deliverFilterType int
)
// DeliverPolicy is the policy of delivering messages.
type DeliverPolicy interface {
Policy() deliverPolicyType
MessageID() message.MessageID
}
// DeliverPolicyAll delivers all messages.
func DeliverPolicyAll() DeliverPolicy {
return &deliverPolicyWithoutMessageID{
policy: DeliverPolicyTypeAll,
}
}
// DeliverLatest delivers the latest message.
func DeliverPolicyLatest() DeliverPolicy {
return &deliverPolicyWithoutMessageID{
policy: DeliverPolicyTypeLatest,
}
}
// DeliverEarliest delivers the earliest message.
func DeliverPolicyStartFrom(messageID message.MessageID) DeliverPolicy {
return &deliverPolicyWithMessageID{
policy: DeliverPolicyTypeStartFrom,
messageID: messageID,
}
}
// DeliverPolicyStartAfter delivers the message after the specified message.
func DeliverPolicyStartAfter(messageID message.MessageID) DeliverPolicy {
return &deliverPolicyWithMessageID{
policy: DeliverPolicyTypeStartAfter,
messageID: messageID,
}
}
// DeliverFilter is the filter of delivering messages.
type DeliverFilter interface {
Type() deliverFilterType
Filter(message.ImmutableMessage) bool
}
//
// DeliverFilters
//
// DeliverFilterTimeTickGT delivers messages by time tick greater than the specified time tick.
func DeliverFilterTimeTickGT(timeTick uint64) DeliverFilter {
return &deliverFilterTimeTickGT{
timeTick: timeTick,
}
}
// DeliverFilterTimeTickGTE delivers messages by time tick greater than or equal to the specified time tick.
func DeliverFilterTimeTickGTE(timeTick uint64) DeliverFilter {
return &deliverFilterTimeTickGTE{
timeTick: timeTick,
}
}
// DeliverFilterVChannel delivers messages filtered by vchannel.
func DeliverFilterVChannel(vchannel string) DeliverFilter {
return &deliverFilterVChannel{
vchannel: vchannel,
}
}
// IsDeliverFilterTimeTick checks if the filter is time tick filter.
func IsDeliverFilterTimeTick(filter DeliverFilter) bool {
return filter.Type() == DeliverFilterTypeTimeTickGT || filter.Type() == DeliverFilterTypeTimeTickGTE
}