Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
927385be
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看板
提交
927385be
编写于
12月 04, 2018
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enhance tests for mixed commitlog
上级
ed31e74f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
4 deletion
+39
-4
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
...a/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
+7
-2
store/src/test/java/org/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
...g/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
+0
-1
store/src/test/java/org/apache/rocketmq/store/dledger/MessageStoreTestBase.java
...g/apache/rocketmq/store/dledger/MessageStoreTestBase.java
+13
-0
store/src/test/java/org/apache/rocketmq/store/dledger/MixCommitlogTest.java
...a/org/apache/rocketmq/store/dledger/MixCommitlogTest.java
+19
-1
未找到文件。
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
浏览文件 @
927385be
...
...
@@ -234,6 +234,11 @@ public class DLedgerCommitLog extends CommitLog {
dLedgerFileStore
.
load
();
if
(
dLedgerFileList
.
getMappedFiles
().
size
()
>
0
)
{
dLedgerFileStore
.
recover
();
MappedFile
mappedFile
=
this
.
mappedFileQueue
.
getLastMappedFile
();
if
(
mappedFile
!=
null
)
{
dLedgerConfig
.
setEnableDiskForceClean
(
false
);
dividedCommitlogOffset
=
mappedFile
.
getFileFromOffset
()
+
mappedFile
.
getFileSize
();
}
return
;
}
//Indicate that, it is the first time to load mixed commitlog, need to recover the old commitlog
...
...
@@ -248,7 +253,6 @@ public class DLedgerCommitLog extends CommitLog {
if
(
mappedFile
==
null
)
{
return
;
}
dLedgerConfig
.
setEnableDiskForceClean
(
false
);
ByteBuffer
byteBuffer
=
mappedFile
.
sliceByteBuffer
();
byteBuffer
.
position
(
mappedFile
.
getWrotePosition
());
boolean
needWriteMagicCode
=
true
;
...
...
@@ -260,6 +264,7 @@ public class DLedgerCommitLog extends CommitLog {
}
else
{
log
.
info
(
"Recover old commitlog found a illegal magic code={}"
,
magicCode
);
}
dLedgerConfig
.
setEnableDiskForceClean
(
false
);
dividedCommitlogOffset
=
mappedFile
.
getFileFromOffset
()
+
mappedFile
.
getFileSize
();
log
.
info
(
"Recover old commitlog needWriteMagicCode={} pos={} file={} dividedCommitlogOffset={}"
,
needWriteMagicCode
,
mappedFile
.
getFileFromOffset
()
+
mappedFile
.
getWrotePosition
(),
mappedFile
.
getFileName
(),
dividedCommitlogOffset
);
if
(
needWriteMagicCode
)
{
...
...
@@ -465,7 +470,7 @@ public class DLedgerCommitLog extends CommitLog {
@Override
public
SelectMappedBufferResult
getMessage
(
final
long
offset
,
final
int
size
)
{
if
(
offset
<
dividedCommitlogOffset
)
{
return
getMessage
(
offset
,
size
);
return
super
.
getMessage
(
offset
,
size
);
}
int
mappedFileSize
=
this
.
dLedgerServer
.
getdLedgerConfig
().
getMappedFileSizeForEntryData
();
MmapFile
mappedFile
=
this
.
dLedgerFileList
.
findMappedFileByOffset
(
offset
,
offset
==
0
);
...
...
store/src/test/java/org/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
浏览文件 @
927385be
...
...
@@ -23,7 +23,6 @@ public class DLedgerCommitlogTest extends MessageStoreTestBase {
String
base
=
createBaseDir
();
String
peers
=
String
.
format
(
"n0-localhost:%d"
,
nextPort
());
String
group
=
UUID
.
randomUUID
().
toString
();
{
DefaultMessageStore
messageStore
=
createDledgerMessageStore
(
base
,
group
,
"n0"
,
peers
,
null
,
false
);
Thread
.
sleep
(
1000
);
...
...
store/src/test/java/org/apache/rocketmq/store/dledger/MessageStoreTestBase.java
浏览文件 @
927385be
...
...
@@ -3,7 +3,10 @@ package org.apache.rocketmq.store.dledger;
import
io.openmessaging.storage.dledger.DLedgerServer
;
import
java.io.File
;
import
org.apache.rocketmq.common.BrokerConfig
;
import
org.apache.rocketmq.common.message.MessageDecoder
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.apache.rocketmq.store.DefaultMessageStore
;
import
org.apache.rocketmq.store.GetMessageResult
;
import
org.apache.rocketmq.store.MessageExtBrokerInner
;
import
org.apache.rocketmq.store.MessageStore
;
import
org.apache.rocketmq.store.PutMessageResult
;
...
...
@@ -89,4 +92,14 @@ public class MessageStoreTestBase extends StoreTestBase {
}
}
protected
void
doGetMessages
(
MessageStore
messageStore
,
String
topic
,
int
queueId
,
int
num
,
long
beginLogicsOffset
)
{
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
GetMessageResult
getMessageResult
=
messageStore
.
getMessage
(
"group"
,
topic
,
0
,
beginLogicsOffset
+
i
,
3
,
null
);
Assert
.
assertNotNull
(
getMessageResult
);
Assert
.
assertTrue
(!
getMessageResult
.
getMessageBufferList
().
isEmpty
());
MessageExt
messageExt
=
MessageDecoder
.
decode
(
getMessageResult
.
getMessageBufferList
().
get
(
0
));
Assert
.
assertEquals
(
beginLogicsOffset
+
i
,
messageExt
.
getQueueOffset
());
}
}
}
store/src/test/java/org/apache/rocketmq/store/dledger/MixCommitlogTest.java
浏览文件 @
927385be
...
...
@@ -5,7 +5,7 @@ import org.apache.rocketmq.store.DefaultMessageStore;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
MixCommitlogTest
extends
DLedgerCommitlogTest
{
public
class
MixCommitlogTest
extends
MessageStoreTestBase
{
@Test
...
...
@@ -25,6 +25,7 @@ public class MixCommitlogTest extends DLedgerCommitlogTest {
Assert
.
assertEquals
(
0
,
originalStore
.
dispatchBehindBytes
());
dividedOffset
=
originalStore
.
getCommitLog
().
getMaxOffset
();
dividedOffset
=
dividedOffset
-
dividedOffset
%
originalStore
.
getMessageStoreConfig
().
getMapedFileSizeCommitLog
()
+
originalStore
.
getMessageStoreConfig
().
getMapedFileSizeCommitLog
();
doGetMessages
(
originalStore
,
topic
,
0
,
1000
,
0
);
originalStore
.
shutdown
();
}
{
...
...
@@ -33,11 +34,13 @@ public class MixCommitlogTest extends DLedgerCommitlogTest {
Assert
.
assertEquals
(
0
,
recoverOriginalStore
.
getMinOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
1000
,
recoverOriginalStore
.
getMaxOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
0
,
recoverOriginalStore
.
dispatchBehindBytes
());
doGetMessages
(
recoverOriginalStore
,
topic
,
0
,
1000
,
0
);
recoverOriginalStore
.
shutdown
();
}
{
DefaultMessageStore
dledgerStore
=
createDledgerMessageStore
(
base
,
group
,
"n0"
,
peers
,
null
,
true
);
DLedgerCommitLog
dLedgerCommitLog
=
(
DLedgerCommitLog
)
dledgerStore
.
getCommitLog
();
Assert
.
assertFalse
(
dLedgerCommitLog
.
getdLedgerServer
().
getdLedgerConfig
().
isEnableDiskForceClean
());
Assert
.
assertEquals
(
dividedOffset
,
dLedgerCommitLog
.
getDividedCommitlogOffset
());
Thread
.
sleep
(
2000
);
doPutMessages
(
dledgerStore
,
topic
,
0
,
1000
,
1000
);
...
...
@@ -45,8 +48,23 @@ public class MixCommitlogTest extends DLedgerCommitlogTest {
Assert
.
assertEquals
(
0
,
dledgerStore
.
getMinOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
2000
,
dledgerStore
.
getMaxOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
0
,
dledgerStore
.
dispatchBehindBytes
());
doGetMessages
(
dledgerStore
,
topic
,
0
,
2000
,
0
);
dledgerStore
.
shutdown
();
}
{
DefaultMessageStore
recoverDledgerStore
=
createDledgerMessageStore
(
base
,
group
,
"n0"
,
peers
,
null
,
true
);
DLedgerCommitLog
dLedgerCommitLog
=
(
DLedgerCommitLog
)
recoverDledgerStore
.
getCommitLog
();
Assert
.
assertFalse
(
dLedgerCommitLog
.
getdLedgerServer
().
getdLedgerConfig
().
isEnableDiskForceClean
());
Assert
.
assertEquals
(
dividedOffset
,
dLedgerCommitLog
.
getDividedCommitlogOffset
());
Thread
.
sleep
(
2000
);
doPutMessages
(
recoverDledgerStore
,
topic
,
0
,
1000
,
2000
);
Thread
.
sleep
(
500
);
Assert
.
assertEquals
(
0
,
recoverDledgerStore
.
getMinOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
3000
,
recoverDledgerStore
.
getMaxOffsetInQueue
(
topic
,
0
));
Assert
.
assertEquals
(
0
,
recoverDledgerStore
.
dispatchBehindBytes
());
doGetMessages
(
recoverDledgerStore
,
topic
,
0
,
3000
,
0
);
recoverDledgerStore
.
shutdown
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录