Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
e7f08a83
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
e7f08a83
编写于
10月 28, 2016
作者:
R
Rajan
提交者:
GitHub
10月 28, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: Reset message-header index while verify checksum-strip at Reconnection (#89) (#90)
上级
1868d2ff
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
67 addition
and
3 deletion
+67
-3
pulsar-broker/src/test/java/com/yahoo/pulsar/client/impl/MessageIdTest.java
...test/java/com/yahoo/pulsar/client/impl/MessageIdTest.java
+64
-0
pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/ProducerImpl.java
.../main/java/com/yahoo/pulsar/client/impl/ProducerImpl.java
+3
-3
未找到文件。
pulsar-broker/src/test/java/com/yahoo/pulsar/client/impl/MessageIdTest.java
浏览文件 @
e7f08a83
...
...
@@ -322,6 +322,70 @@ public class MessageIdTest extends BrokerTestBase {
}
@Test
public
void
testChecksumReconnection
()
throws
Exception
{
final
String
topicName
=
"persistent://prop/use/ns-abc/topic1"
;
// 1. producer connect
Producer
prod
=
pulsarClient
.
createProducer
(
topicName
);
ProducerImpl
producer
=
spy
((
ProducerImpl
)
prod
);
// mock: broker-doesn't support checksum (remote_version < brokerChecksumSupportedVersion) so, it forces
// client-producer to perform checksum-strip from msg at reconnection
doReturn
(
producer
.
brokerChecksumSupportedVersion
()
+
1
).
when
(
producer
).
brokerChecksumSupportedVersion
();
Consumer
consumer
=
pulsarClient
.
subscribe
(
topicName
,
"my-sub"
);
stopBroker
();
// stop timer to auto-reconnect as let spy-Producer connect to broker
// manually so, spy-producer object can get
// mock-value from brokerChecksumSupportedVersion
((
PulsarClientImpl
)
pulsarClient
).
timer
().
stop
();
// set clientCnx mock to get non-checksum supported version
ClientCnx
mockClientCnx
=
spy
(
new
ClientCnx
((
PulsarClientImpl
)
pulsarClient
));
doReturn
(
producer
.
brokerChecksumSupportedVersion
()
-
1
).
when
(
mockClientCnx
).
getRemoteEndpointProtocolVersion
();
producer
.
clientCnx
.
set
(
mockClientCnx
);
Message
msg1
=
MessageBuilder
.
create
().
setContent
(
"message-1"
.
getBytes
()).
build
();
CompletableFuture
<
MessageId
>
future1
=
producer
.
sendAsync
(
msg1
);
Message
msg2
=
MessageBuilder
.
create
().
setContent
(
"message-2"
.
getBytes
()).
build
();
CompletableFuture
<
MessageId
>
future2
=
producer
.
sendAsync
(
msg2
);
// corrupt the message
msg2
.
getData
()[
msg2
.
getData
().
length
-
1
]
=
'3'
;
// new content would be
// 'message-3'
// unset mock
producer
.
clientCnx
.
set
(
null
);
// Restart the broker to have the messages published
startBroker
();
// grab broker connection with mocked producer which has higher version
// compare to broker
producer
.
grabCnx
();
try
{
// it should not fail: as due to unsupported version of broker:
// client removes checksum and broker should
// ignore the checksum validation
future1
.
get
(
1
,
TimeUnit
.
SECONDS
);
future2
.
get
(
1
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
fail
(
"Broker shouldn't verify checksum for corrupted message and it shouldn't fail"
);
}
((
ConsumerImpl
)
consumer
).
grabCnx
();
// We should only receive msg1
Message
msg
=
consumer
.
receive
(
1
,
TimeUnit
.
SECONDS
);
assertEquals
(
new
String
(
msg
.
getData
()),
"message-1"
);
msg
=
consumer
.
receive
(
1
,
TimeUnit
.
SECONDS
);
assertEquals
(
new
String
(
msg
.
getData
()),
"message-3"
);
}
/**
* Verifies: if message is corrupted before sending to broker and if broker gives checksum error: then
* 1. Client-Producer recomputes checksum with modified data
...
...
pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/ProducerImpl.java
浏览文件 @
e7f08a83
...
...
@@ -791,9 +791,10 @@ public class ProducerImpl extends ProducerBase implements TimerTask {
log
.
info
(
"[{}] [{}] Re-Sending {} messages to server"
,
topic
,
producerName
,
messagesToResend
);
final
boolean
stripChecksum
=
cnx
.
getRemoteEndpointProtocolVersion
()
<
brokerChecksumSupportedVersion
();
for
(
OpSendMsg
op
:
pendingMessages
)
{
if
(
cnx
.
getRemoteEndpointProtocolVersion
()
<
brokerChecksumSupportedVersion
()
)
{
if
(
stripChecksum
)
{
stripChecksum
(
op
);
}
op
.
cmd
.
retain
();
...
...
@@ -827,10 +828,8 @@ public class ProducerImpl extends ProducerBase implements TimerTask {
DoubleByteBuf
msg
=
getDoubleByteBuf
(
op
.
cmd
);
if
(
msg
!=
null
)
{
ByteBuf
headerFrame
=
msg
.
getFirst
();
ByteBuf
payloadFrame
=
msg
.
getSecond
();
msg
.
markReaderIndex
();
headerFrame
.
markReaderIndex
();
payloadFrame
.
markReaderIndex
();
try
{
headerFrame
.
skipBytes
(
4
);
// skip [total-size]
int
cmdSize
=
(
int
)
headerFrame
.
readUnsignedInt
();
...
...
@@ -839,6 +838,7 @@ public class ProducerImpl extends ProducerBase implements TimerTask {
headerFrame
.
skipBytes
(
cmdSize
);
if
(!
hasChecksum
(
headerFrame
))
{
headerFrame
.
resetReaderIndex
();
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录