milvus/internal/timesync/timetick_watcher.go
XuanYang-cn fd562f9f9c Update doc: add proxy graph
Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
2021-02-24 09:48:17 +08:00

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() {
}