Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
fb22d122
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
fb22d122
编写于
8月 16, 2021
作者:
C
congqixia
提交者:
GitHub
8月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add EarliestMessageID patch logic (#7119)
Signed-off-by:
N
Congqi Xia
<
congqi.xia@zilliz.com
>
上级
61bda45e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
79 addition
and
2 deletion
+79
-2
internal/util/mqclient/pulsar_consumer.go
internal/util/mqclient/pulsar_consumer.go
+48
-2
internal/util/mqclient/pulsar_consumer_test.go
internal/util/mqclient/pulsar_consumer_test.go
+31
-0
未找到文件。
internal/util/mqclient/pulsar_consumer.go
浏览文件 @
fb22d122
...
...
@@ -12,7 +12,8 @@
package
mqclient
import
(
"time"
"reflect"
"unsafe"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/milvus-io/milvus/internal/log"
...
...
@@ -32,8 +33,18 @@ func (pc *pulsarConsumer) Subscription() string {
func
(
pc
*
pulsarConsumer
)
Chan
()
<-
chan
ConsumerMessage
{
if
pc
.
msgChannel
==
nil
{
pc
.
msgChannel
=
make
(
chan
ConsumerMessage
)
// this part handles msgstream expectation when the consumer is not seeked
// pulsar's default behavior is setting postition to the earliest pointer when client of the same subscription pointer is not acked
// yet, our message stream is to setting to the very start point of the topic
if
!
pc
.
hasSeek
{
pc
.
c
.
SeekByTime
(
time
.
Unix
(
0
,
0
))
// the concrete value of the MessageID is pulsar.messageID{-1,-1,-1,-1}
// but Seek function logic does not allow partitionID -1, See line 618-620 of github.com/apache/pulsar-client-go@v0.5.0 pulsar/consumer_impl.go
mid
:=
pulsar
.
EarliestMessageID
()
// the patch function use unsafe pointer to set partitionIdx to 0, which is the valid default partition index of current use case
// NOTE: when pulsar client version check, do check this logic is fixed or offset is changed!!!
// NOTE: unsafe solution, check implementation asap
patchEarliestMessageID
(
&
mid
)
pc
.
c
.
Seek
(
mid
)
}
go
func
()
{
for
{
//nolint:gosimple
...
...
@@ -72,3 +83,38 @@ func (pc *pulsarConsumer) Close() {
pc
.
c
.
Close
()
close
(
pc
.
closeCh
)
}
// patchEarliestMessageID unsafe patch logic to change messageID partitionIdx to 0
// ONLY used in Chan() function
// DON'T use elsewhere
func
patchEarliestMessageID
(
mid
*
pulsar
.
MessageID
)
{
v
:=
reflect
.
ValueOf
(
mid
)
v
=
v
.
Elem
()
// cannot use field.SetInt(), since partitionIdx is not exported
// this reflect+ unsafe solution is disable by go vet
//ifData := v.InterfaceData() // unwrap interface
//ifData[1] is the pointer to the exact struct
// 20 is the offset of paritionIdx of messageID
//lint:ignore unsafeptr: possible misuse of unsafe.Pointer (govet), hardcoded offset
//*(*int32)(unsafe.Pointer(v.InterfaceData()[1] + 20)) = 0
// use direct unsafe conversion
r
:=
(
*
iface
)(
unsafe
.
Pointer
(
mid
))
id
:=
(
*
messageID
)(
r
.
Data
)
id
.
partitionIdx
=
0
}
// unsafe access pointer, same as pulsar.messageID
type
messageID
struct
{
ledgerID
int64
entryID
int64
batchID
int32
partitionIdx
int32
}
// interface struct mapping
type
iface
struct
{
Type
,
Data
unsafe
.
Pointer
}
internal/util/mqclient/pulsar_consumer_test.go
0 → 100644
浏览文件 @
fb22d122
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.
package
mqclient
import
(
"fmt"
"testing"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/stretchr/testify/assert"
)
func
TestPatchEarliestMessageID
(
t
*
testing
.
T
)
{
mid
:=
pulsar
.
EarliestMessageID
()
// String() -> ledgerID:entryID:partitionIdx
assert
.
Equal
(
t
,
"-1:-1:-1"
,
fmt
.
Sprintf
(
"%v"
,
mid
))
patchEarliestMessageID
(
&
mid
)
assert
.
Equal
(
t
,
"-1:-1:0"
,
fmt
.
Sprintf
(
"%v"
,
mid
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录