未验证 提交 3630eec9 编写于 作者: X xige-16 提交者: GitHub

Fix receving wrong msg after seek (#5441)

Signed-off-by: Nxige-16 <xi.ge@zilliz.com>
上级 9aa1fd25
...@@ -102,8 +102,7 @@ func (ms *mqMsgStream) AsProducer(channels []string) { ...@@ -102,8 +102,7 @@ func (ms *mqMsgStream) AsProducer(channels []string) {
} }
} }
func (ms *mqMsgStream) AsConsumer(channels []string, func (ms *mqMsgStream) AsConsumer(channels []string, subName string) {
subName string) {
for _, channel := range channels { for _, channel := range channels {
if _, ok := ms.consumers[channel]; ok { if _, ok := ms.consumers[channel]; ok {
continue continue
...@@ -190,14 +189,14 @@ func (ms *mqMsgStream) GetProduceChannels() []string { ...@@ -190,14 +189,14 @@ func (ms *mqMsgStream) GetProduceChannels() []string {
} }
func (ms *mqMsgStream) Produce(msgPack *MsgPack) error { func (ms *mqMsgStream) Produce(msgPack *MsgPack) error {
tsMsgs := msgPack.Msgs if msgPack == nil || len(msgPack.Msgs) <= 0 {
if len(tsMsgs) <= 0 {
log.Debug("Warning: Receive empty msgPack") log.Debug("Warning: Receive empty msgPack")
return nil return nil
} }
if len(ms.producers) <= 0 { if len(ms.producers) <= 0 {
return errors.New("nil producer in msg stream") return errors.New("nil producer in msg stream")
} }
tsMsgs := msgPack.Msgs
reBucketValues := ms.ComputeProduceChannelIndexes(msgPack.Msgs) reBucketValues := ms.ComputeProduceChannelIndexes(msgPack.Msgs)
var result map[int32]*MsgPack var result map[int32]*MsgPack
var err error var err error
...@@ -251,6 +250,10 @@ func (ms *mqMsgStream) Produce(msgPack *MsgPack) error { ...@@ -251,6 +250,10 @@ func (ms *mqMsgStream) Produce(msgPack *MsgPack) error {
} }
func (ms *mqMsgStream) Broadcast(msgPack *MsgPack) error { func (ms *mqMsgStream) Broadcast(msgPack *MsgPack) error {
if msgPack == nil || len(msgPack.Msgs) <= 0 {
log.Debug("Warning: Receive empty msgPack")
return nil
}
for _, v := range msgPack.Msgs { for _, v := range msgPack.Msgs {
sp, spanCtx := MsgSpanFromCtx(v.TraceCtx(), v) sp, spanCtx := MsgSpanFromCtx(v.TraceCtx(), v)
...@@ -479,7 +482,6 @@ func (ms *MqTtMsgStream) Close() { ...@@ -479,7 +482,6 @@ func (ms *MqTtMsgStream) Close() {
func (ms *MqTtMsgStream) bufMsgPackToChannel() { func (ms *MqTtMsgStream) bufMsgPackToChannel() {
defer ms.wait.Done() defer ms.wait.Done()
ms.unsolvedBuf = make(map[mqclient.Consumer][]TsMsg)
isChannelReady := make(map[mqclient.Consumer]bool) isChannelReady := make(map[mqclient.Consumer]bool)
eofMsgTimeStamp := make(map[mqclient.Consumer]Timestamp) eofMsgTimeStamp := make(map[mqclient.Consumer]Timestamp)
...@@ -503,11 +505,11 @@ func (ms *MqTtMsgStream) bufMsgPackToChannel() { ...@@ -503,11 +505,11 @@ func (ms *MqTtMsgStream) bufMsgPackToChannel() {
wg.Add(1) wg.Add(1)
go ms.findTimeTick(consumer, eofMsgTimeStamp, &wg, &findMapMutex) go ms.findTimeTick(consumer, eofMsgTimeStamp, &wg, &findMapMutex)
} }
ms.consumerLock.Unlock()
wg.Wait() wg.Wait()
timeStamp, ok := checkTimeTickMsg(eofMsgTimeStamp, isChannelReady, &findMapMutex) timeStamp, ok := checkTimeTickMsg(eofMsgTimeStamp, isChannelReady, &findMapMutex)
if !ok || timeStamp <= ms.lastTimeStamp { if !ok || timeStamp <= ms.lastTimeStamp {
//log.Printf("All timeTick's timestamps are inconsistent") //log.Printf("All timeTick's timestamps are inconsistent")
ms.consumerLock.Unlock()
continue continue
} }
timeTickBuf := make([]TsMsg, 0) timeTickBuf := make([]TsMsg, 0)
...@@ -553,6 +555,7 @@ func (ms *MqTtMsgStream) bufMsgPackToChannel() { ...@@ -553,6 +555,7 @@ func (ms *MqTtMsgStream) bufMsgPackToChannel() {
ms.msgPositions[consumer] = newPos ms.msgPositions[consumer] = newPos
} }
ms.unsolvedMutex.Unlock() ms.unsolvedMutex.Unlock()
ms.consumerLock.Unlock()
msgPack := MsgPack{ msgPack := MsgPack{
BeginTs: ms.lastTimeStamp, BeginTs: ms.lastTimeStamp,
...@@ -712,9 +715,9 @@ func (ms *MqTtMsgStream) Seek(mp *internalpb.MsgPosition) error { ...@@ -712,9 +715,9 @@ func (ms *MqTtMsgStream) Seek(mp *internalpb.MsgPosition) error {
ms.addConsumer(consumer, seekChannel) ms.addConsumer(consumer, seekChannel)
//TODO: May cause problem //TODO: May cause problem
if len(consumer.Chan()) == 0 { //if len(consumer.Chan()) == 0 {
return nil // return nil
} //}
for { for {
select { select {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册