Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
76777583
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
76777583
编写于
2月 10, 2017
作者:
L
lizhanhui
提交者:
yukon
2月 10, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-74] Fix DataVersion equals defect, closes apache/incubator-rocketmq#50
上级
44ef40ab
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
91 addition
and
13 deletion
+91
-13
common/src/main/java/org/apache/rocketmq/common/DataVersion.java
...src/main/java/org/apache/rocketmq/common/DataVersion.java
+19
-11
common/src/test/java/org/apache/rocketmq/common/DataVersionTest.java
...test/java/org/apache/rocketmq/common/DataVersionTest.java
+70
-0
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java
...e/rocketmq/namesrv/processor/DefaultRequestProcessor.java
+2
-2
未找到文件。
common/src/main/java/org/apache/rocketmq/common/DataVersion.java
浏览文件 @
76777583
...
@@ -20,25 +20,25 @@ import java.util.concurrent.atomic.AtomicLong;
...
@@ -20,25 +20,25 @@ import java.util.concurrent.atomic.AtomicLong;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
public
class
DataVersion
extends
RemotingSerializable
{
public
class
DataVersion
extends
RemotingSerializable
{
private
long
timesta
t
mp
=
System
.
currentTimeMillis
();
private
long
timestamp
=
System
.
currentTimeMillis
();
private
AtomicLong
counter
=
new
AtomicLong
(
0
);
private
AtomicLong
counter
=
new
AtomicLong
(
0
);
public
void
assignNewOne
(
final
DataVersion
dataVersion
)
{
public
void
assignNewOne
(
final
DataVersion
dataVersion
)
{
this
.
timesta
tmp
=
dataVersion
.
timestat
mp
;
this
.
timesta
mp
=
dataVersion
.
timesta
mp
;
this
.
counter
.
set
(
dataVersion
.
counter
.
get
());
this
.
counter
.
set
(
dataVersion
.
counter
.
get
());
}
}
public
void
nextVersion
()
{
public
void
nextVersion
()
{
this
.
timesta
t
mp
=
System
.
currentTimeMillis
();
this
.
timestamp
=
System
.
currentTimeMillis
();
this
.
counter
.
incrementAndGet
();
this
.
counter
.
incrementAndGet
();
}
}
public
long
getTimesta
t
mp
()
{
public
long
getTimestamp
()
{
return
timesta
t
mp
;
return
timestamp
;
}
}
public
void
setTimesta
tmp
(
long
timestat
mp
)
{
public
void
setTimesta
mp
(
long
timesta
mp
)
{
this
.
timesta
tmp
=
timestat
mp
;
this
.
timesta
mp
=
timesta
mp
;
}
}
public
AtomicLong
getCounter
()
{
public
AtomicLong
getCounter
()
{
...
@@ -58,16 +58,24 @@ public class DataVersion extends RemotingSerializable {
...
@@ -58,16 +58,24 @@ public class DataVersion extends RemotingSerializable {
final
DataVersion
that
=
(
DataVersion
)
o
;
final
DataVersion
that
=
(
DataVersion
)
o
;
if
(
timesta
tmp
!=
that
.
timestatmp
)
if
(
timesta
mp
!=
that
.
timestamp
)
{
return
false
;
return
false
;
return
counter
!=
null
?
counter
.
equals
(
that
.
counter
)
:
that
.
counter
==
null
;
}
if
(
counter
!=
null
&&
that
.
counter
!=
null
)
{
return
counter
.
longValue
()
==
that
.
counter
.
longValue
();
}
return
(
null
==
counter
)
&&
(
null
==
that
.
counter
);
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
int
result
=
(
int
)
(
timestatmp
^
(
timestatmp
>>>
32
));
int
result
=
(
int
)
(
timestamp
^
(
timestamp
>>>
32
));
result
=
31
*
result
+
(
counter
!=
null
?
counter
.
hashCode
()
:
0
);
if
(
null
!=
counter
)
{
long
l
=
counter
.
get
();
result
=
31
*
result
+
(
int
)(
l
^
(
l
>>>
32
));
}
return
result
;
return
result
;
}
}
}
}
common/src/test/java/org/apache/rocketmq/common/DataVersionTest.java
0 → 100644
浏览文件 @
76777583
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
org.apache.rocketmq.common
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
DataVersionTest
{
@Test
public
void
testEquals
()
{
DataVersion
dataVersion
=
new
DataVersion
();
DataVersion
other
=
new
DataVersion
();
other
.
setTimestamp
(
dataVersion
.
getTimestamp
());
Assert
.
assertTrue
(
dataVersion
.
equals
(
other
));
}
@Test
public
void
testEquals_falseWhenCounterDifferent
()
{
DataVersion
dataVersion
=
new
DataVersion
();
DataVersion
other
=
new
DataVersion
();
other
.
setCounter
(
new
AtomicLong
(
1L
));
other
.
setTimestamp
(
dataVersion
.
getTimestamp
());
Assert
.
assertFalse
(
dataVersion
.
equals
(
other
));
}
@Test
public
void
testEquals_falseWhenCounterDifferent2
()
{
DataVersion
dataVersion
=
new
DataVersion
();
DataVersion
other
=
new
DataVersion
();
other
.
setCounter
(
null
);
other
.
setTimestamp
(
dataVersion
.
getTimestamp
());
Assert
.
assertFalse
(
dataVersion
.
equals
(
other
));
}
@Test
public
void
testEquals_falseWhenCounterDifferent3
()
{
DataVersion
dataVersion
=
new
DataVersion
();
dataVersion
.
setCounter
(
null
);
DataVersion
other
=
new
DataVersion
();
other
.
setTimestamp
(
dataVersion
.
getTimestamp
());
Assert
.
assertFalse
(
dataVersion
.
equals
(
other
));
}
@Test
public
void
testEquals_trueWhenCountersBothNull
()
{
DataVersion
dataVersion
=
new
DataVersion
();
dataVersion
.
setCounter
(
null
);
DataVersion
other
=
new
DataVersion
();
other
.
setCounter
(
null
);
other
.
setTimestamp
(
dataVersion
.
getTimestamp
());
Assert
.
assertTrue
(
dataVersion
.
equals
(
other
));
}
}
\ No newline at end of file
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java
浏览文件 @
76777583
...
@@ -191,7 +191,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor {
...
@@ -191,7 +191,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor {
registerBrokerBody
=
RegisterBrokerBody
.
decode
(
request
.
getBody
(),
RegisterBrokerBody
.
class
);
registerBrokerBody
=
RegisterBrokerBody
.
decode
(
request
.
getBody
(),
RegisterBrokerBody
.
class
);
}
else
{
}
else
{
registerBrokerBody
.
getTopicConfigSerializeWrapper
().
getDataVersion
().
setCounter
(
new
AtomicLong
(
0
));
registerBrokerBody
.
getTopicConfigSerializeWrapper
().
getDataVersion
().
setCounter
(
new
AtomicLong
(
0
));
registerBrokerBody
.
getTopicConfigSerializeWrapper
().
getDataVersion
().
setTimesta
t
mp
(
0
);
registerBrokerBody
.
getTopicConfigSerializeWrapper
().
getDataVersion
().
setTimestamp
(
0
);
}
}
RegisterBrokerResult
result
=
this
.
namesrvController
.
getRouteInfoManager
().
registerBroker
(
RegisterBrokerResult
result
=
this
.
namesrvController
.
getRouteInfoManager
().
registerBroker
(
...
@@ -227,7 +227,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor {
...
@@ -227,7 +227,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor {
}
else
{
}
else
{
topicConfigWrapper
=
new
TopicConfigSerializeWrapper
();
topicConfigWrapper
=
new
TopicConfigSerializeWrapper
();
topicConfigWrapper
.
getDataVersion
().
setCounter
(
new
AtomicLong
(
0
));
topicConfigWrapper
.
getDataVersion
().
setCounter
(
new
AtomicLong
(
0
));
topicConfigWrapper
.
getDataVersion
().
setTimesta
t
mp
(
0
);
topicConfigWrapper
.
getDataVersion
().
setTimestamp
(
0
);
}
}
RegisterBrokerResult
result
=
this
.
namesrvController
.
getRouteInfoManager
().
registerBroker
(
RegisterBrokerResult
result
=
this
.
namesrvController
.
getRouteInfoManager
().
registerBroker
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录