mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
fd562f9f9c
Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package timesync
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
ms "github.com/zilliztech/milvus-distributed/internal/msgstream"
|
|
)
|
|
|
|
type TimeTickWatcher interface {
|
|
Watch(msg *ms.TimeTickMsg)
|
|
StartBackgroundLoop(ctx context.Context)
|
|
}
|
|
|
|
type MsgTimeTickWatcher struct {
|
|
streams []ms.MsgStream
|
|
msgQueue chan *ms.TimeTickMsg
|
|
}
|
|
|
|
func NewMsgTimeTickWatcher(streams ...ms.MsgStream) *MsgTimeTickWatcher {
|
|
watcher := &MsgTimeTickWatcher{
|
|
streams: streams,
|
|
msgQueue: make(chan *ms.TimeTickMsg),
|
|
}
|
|
return watcher
|
|
}
|
|
|
|
func (watcher *MsgTimeTickWatcher) Watch(msg *ms.TimeTickMsg) {
|
|
watcher.msgQueue <- msg
|
|
}
|
|
|
|
func (watcher *MsgTimeTickWatcher) StartBackgroundLoop(ctx context.Context) {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
log.Println("msg time tick watcher closed")
|
|
return
|
|
case msg := <-watcher.msgQueue:
|
|
msgPack := &ms.MsgPack{}
|
|
msgPack.Msgs = append(msgPack.Msgs, msg)
|
|
for _, stream := range watcher.streams {
|
|
if err := stream.Broadcast(ctx, msgPack); err != nil {
|
|
log.Printf("stream broadcast failed %s", err.Error())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (watcher *MsgTimeTickWatcher) Close() {
|
|
}
|