Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
58496c2f
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看板
提交
58496c2f
编写于
12月 04, 2018
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename dleger to dledger
上级
b31c17f9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
77 deletion
+43
-77
broker/src/main/java/org/apache/rocketmq/broker/dledger/DLedgerRoleChangeHandler.java
...che/rocketmq/broker/dledger/DLedgerRoleChangeHandler.java
+8
-8
store/pom.xml
store/pom.xml
+1
-1
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
...a/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
+31
-29
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerSelectMappedBufferResult.java
...cketmq/store/dledger/DLedgerSelectMappedBufferResult.java
+0
-36
store/src/test/java/org/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
...g/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
+3
-3
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/dledger/DLedgerRoleChangeHandler.java
浏览文件 @
58496c2f
...
...
@@ -21,24 +21,24 @@ import java.util.concurrent.Executors;
import
org.apache.rocketmq.broker.BrokerController
;
import
org.apache.rocketmq.common.ThreadFactoryImpl
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
io.openmessaging.storage.dle
ger.DLe
gerLeaderElector
;
import
io.openmessaging.storage.dle
ger.DLe
gerServer
;
import
io.openmessaging.storage.dleger.MemberState
;
import
io.openmessaging.storage.dleger.utils.UtilAll
;
import
io.openmessaging.storage.dle
dger.DLed
gerLeaderElector
;
import
io.openmessaging.storage.dle
dger.DLed
gerServer
;
import
io.openmessaging.storage.dle
d
ger.MemberState
;
import
io.openmessaging.storage.dle
d
ger.utils.UtilAll
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
import
org.apache.rocketmq.store.DefaultMessageStore
;
import
org.apache.rocketmq.store.config.BrokerRole
;
import
org.apache.rocketmq.store.dledger.DLedgerCommitLog
;
public
class
DLedgerRoleChangeHandler
implements
DLegerLeaderElector
.
RoleChangeHandler
{
public
class
DLedgerRoleChangeHandler
implements
DLe
d
gerLeaderElector
.
RoleChangeHandler
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
BROKER_LOGGER_NAME
);
private
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
(
new
ThreadFactoryImpl
(
"DLegerRoleChangeHandler_"
));
private
BrokerController
brokerController
;
private
DefaultMessageStore
messageStore
;
private
DLedgerCommitLog
dLedgerCommitLog
;
private
DLegerServer
dLegerServer
;
private
DLe
d
gerServer
dLegerServer
;
public
DLedgerRoleChangeHandler
(
BrokerController
brokerController
,
DefaultMessageStore
messageStore
)
{
this
.
brokerController
=
brokerController
;
this
.
messageStore
=
messageStore
;
...
...
@@ -63,11 +63,11 @@ public class DLedgerRoleChangeHandler implements DLegerLeaderElector.RoleChangeH
break
;
case
LEADER:
while
(
dLegerServer
.
getMemberState
().
isLeader
()
&&
(
dLegerServer
.
getdLe
gerStore
().
getLegerEndIndex
()
!=
dLegerServer
.
getdLe
gerStore
().
getCommittedIndex
()
||
messageStore
.
dispatchBehindBytes
()
!=
0
))
{
&&
(
dLegerServer
.
getdLe
dgerStore
().
getLedgerEndIndex
()
!=
dLegerServer
.
getdLed
gerStore
().
getCommittedIndex
()
||
messageStore
.
dispatchBehindBytes
()
!=
0
))
{
UtilAll
.
sleep
(
100
);
}
boolean
succ
=
dLegerServer
.
getMemberState
().
isLeader
()
&&
dLegerServer
.
getdLe
gerStore
().
getLegerEndIndex
()
==
dLegerServer
.
getdLe
gerStore
().
getCommittedIndex
()
&&
dLegerServer
.
getdLe
dgerStore
().
getLedgerEndIndex
()
==
dLegerServer
.
getdLed
gerStore
().
getCommittedIndex
()
&&
messageStore
.
dispatchBehindBytes
()
==
0
;
if
(
succ
)
{
messageStore
.
recoverTopicQueueTable
();
...
...
store/pom.xml
浏览文件 @
58496c2f
...
...
@@ -30,7 +30,7 @@
<dependencies>
<dependency>
<groupId>
io.openmessaging.storage
</groupId>
<artifactId>
dleger
</artifactId>
<artifactId>
dle
d
ger
</artifactId>
<version>
0.1-SNAPSHOT
</version>
<exclusions>
<exclusion>
...
...
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
浏览文件 @
58496c2f
...
...
@@ -16,16 +16,16 @@
*/
package
org.apache.rocketmq.store.dledger
;
import
io.openmessaging.storage.dle
ger.DLe
gerConfig
;
import
io.openmessaging.storage.dle
ger.DLe
gerServer
;
import
io.openmessaging.storage.dle
ger.entry.DLe
gerEntry
;
import
io.openmessaging.storage.dleger.protocol.AppendEntryRequest
;
import
io.openmessaging.storage.dleger.protocol.AppendEntryResponse
;
import
io.openmessaging.storage.dle
ger.protocol.DLe
gerResponseCode
;
import
io.openmessaging.storage.dle
ger.store.file.DLe
gerMmapFileStore
;
import
io.openmessaging.storage.dleger.store.file.MmapFile
;
import
io.openmessaging.storage.dleger.store.file.MmapFileList
;
import
io.openmessaging.storage.dleger.store.file.SelectMmapBufferResult
;
import
io.openmessaging.storage.dle
dger.DLed
gerConfig
;
import
io.openmessaging.storage.dle
dger.DLed
gerServer
;
import
io.openmessaging.storage.dle
dger.entry.DLed
gerEntry
;
import
io.openmessaging.storage.dle
d
ger.protocol.AppendEntryRequest
;
import
io.openmessaging.storage.dle
d
ger.protocol.AppendEntryResponse
;
import
io.openmessaging.storage.dle
dger.protocol.DLed
gerResponseCode
;
import
io.openmessaging.storage.dle
dger.store.file.DLed
gerMmapFileStore
;
import
io.openmessaging.storage.dle
d
ger.store.file.MmapFile
;
import
io.openmessaging.storage.dle
d
ger.store.file.MmapFileList
;
import
io.openmessaging.storage.dle
d
ger.store.file.SelectMmapBufferResult
;
import
java.nio.ByteBuffer
;
import
java.util.HashMap
;
import
java.util.concurrent.CompletableFuture
;
...
...
@@ -53,9 +53,9 @@ import org.apache.rocketmq.store.schedule.ScheduleMessageService;
* Store all metadata downtime for recovery, data protection reliability
*/
public
class
DLedgerCommitLog
extends
CommitLog
{
private
final
DLegerServer
dLedgerServer
;
private
final
DLegerConfig
dLedgerConfig
;
private
final
DLegerMmapFileStore
dLedgerFileStore
;
private
final
DLe
d
gerServer
dLedgerServer
;
private
final
DLe
d
gerConfig
dLedgerConfig
;
private
final
DLe
d
gerMmapFileStore
dLedgerFileStore
;
private
final
MmapFileList
dLedgerFileList
;
//The id identifies the broker role, 0 means master, others means slave
...
...
@@ -73,7 +73,7 @@ public class DLedgerCommitLog extends CommitLog {
public
DLedgerCommitLog
(
final
DefaultMessageStore
defaultMessageStore
)
{
super
(
defaultMessageStore
);
dLedgerConfig
=
new
DLegerConfig
();
dLedgerConfig
=
new
DLe
d
gerConfig
();
dLedgerConfig
.
setEnableDiskForceClean
(
defaultMessageStore
.
getMessageStoreConfig
().
isCleanFileForciblyEnable
());
dLedgerConfig
.
setSelfId
(
defaultMessageStore
.
getMessageStoreConfig
().
getdLegerSelfId
());
dLedgerConfig
.
setGroup
(
defaultMessageStore
.
getMessageStoreConfig
().
getdLegerGroup
());
...
...
@@ -82,10 +82,10 @@ public class DLedgerCommitLog extends CommitLog {
dLedgerConfig
.
setMappedFileSizeForEntryData
(
defaultMessageStore
.
getMessageStoreConfig
().
getMapedFileSizeCommitLog
());
originalDledgerEnableForceClean
=
dLedgerConfig
.
isEnableDiskForceClean
();
id
=
Integer
.
valueOf
(
dLedgerConfig
.
getSelfId
().
substring
(
1
))
+
1
;
dLedgerServer
=
new
DLegerServer
(
dLedgerConfig
);
dLedgerFileStore
=
(
DLe
gerMmapFileStore
)
dLedgerServer
.
getdLe
gerStore
();
DLegerMmapFileStore
.
AppendHook
appendHook
=
(
entry
,
buffer
,
bodyOffset
)
->
{
assert
bodyOffset
==
DLegerEntry
.
BODY_OFFSET
;
dLedgerServer
=
new
DLe
d
gerServer
(
dLedgerConfig
);
dLedgerFileStore
=
(
DLe
dgerMmapFileStore
)
dLedgerServer
.
getdLed
gerStore
();
DLe
d
gerMmapFileStore
.
AppendHook
appendHook
=
(
entry
,
buffer
,
bodyOffset
)
->
{
assert
bodyOffset
==
DLe
d
gerEntry
.
BODY_OFFSET
;
buffer
.
position
(
buffer
.
position
()
+
bodyOffset
+
MessageDecoder
.
PHY_POS_POSITION
);
buffer
.
putLong
(
entry
.
getPos
()
+
bodyOffset
);
};
...
...
@@ -215,7 +215,7 @@ public class DLedgerCommitLog extends CommitLog {
if
(
sbr
==
null
)
{
return
null
;
}
else
{
return
new
DLegerSelectMappedBufferResult
(
sbr
);
return
new
DLe
d
gerSelectMappedBufferResult
(
sbr
);
}
}
...
...
@@ -250,7 +250,7 @@ public class DLedgerCommitLog extends CommitLog {
if
(
offset
>=
dLedgerFileStore
.
getCommittedPos
())
{
return
null
;
}
int
mappedFileSize
=
this
.
dLedgerServer
.
getdLegerConfig
().
getMappedFileSizeForEntryData
();
int
mappedFileSize
=
this
.
dLedgerServer
.
getdLe
d
gerConfig
().
getMappedFileSizeForEntryData
();
MmapFile
mappedFile
=
this
.
dLedgerFileList
.
findMappedFileByOffset
(
offset
,
returnFirstOnNotFound
);
if
(
mappedFile
!=
null
)
{
int
pos
=
(
int
)
(
offset
%
mappedFileSize
);
...
...
@@ -288,7 +288,7 @@ public class DLedgerCommitLog extends CommitLog {
public
DispatchRequest
checkMessageAndReturnSize
(
ByteBuffer
byteBuffer
,
final
boolean
checkCRC
,
final
boolean
readBody
)
{
try
{
int
bodyOffset
=
DLegerEntry
.
BODY_OFFSET
;
int
bodyOffset
=
DLe
d
gerEntry
.
BODY_OFFSET
;
int
pos
=
byteBuffer
.
position
();
int
magic
=
byteBuffer
.
getInt
();
if
(
magic
==
MmapFileList
.
BLANK_MAGIC_CODE
)
{
...
...
@@ -383,7 +383,7 @@ public class DLedgerCommitLog extends CommitLog {
request
.
setRemoteId
(
dLedgerServer
.
getMemberState
().
getSelfId
());
request
.
setBody
(
encodeResult
.
data
);
dlegerFuture
=
dLedgerServer
.
handleAppend
(
request
);
if
(
dlegerFuture
.
isDone
()
&&
dlegerFuture
.
get
().
getCode
()
!=
DLegerResponseCode
.
SUCCESS
.
getCode
())
{
if
(
dlegerFuture
.
isDone
()
&&
dlegerFuture
.
get
().
getCode
()
!=
DLe
d
gerResponseCode
.
SUCCESS
.
getCode
())
{
//TO DO make sure the local store is ok
appendResult
=
new
AppendMessageResult
(
AppendMessageStatus
.
UNKNOWN_ERROR
);
}
else
{
...
...
@@ -417,10 +417,10 @@ public class DLedgerCommitLog extends CommitLog {
if
(
dlegerFuture
!=
null
)
{
try
{
AppendEntryResponse
appendEntryResponse
=
dlegerFuture
.
get
(
3
,
TimeUnit
.
SECONDS
);
switch
(
DLegerResponseCode
.
valueOf
(
appendEntryResponse
.
getCode
()))
{
switch
(
DLe
d
gerResponseCode
.
valueOf
(
appendEntryResponse
.
getCode
()))
{
case
SUCCESS:
putMessageStatus
=
PutMessageStatus
.
PUT_OK
;
long
wroteOffset
=
appendEntryResponse
.
getPos
()
+
DLegerEntry
.
BODY_OFFSET
;
long
wroteOffset
=
appendEntryResponse
.
getPos
()
+
DLe
d
gerEntry
.
BODY_OFFSET
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
MessageDecoder
.
MSG_ID_LENGTH
);
String
msgId
=
MessageDecoder
.
createMessageId
(
buffer
,
msg
.
getStoreHostBytes
(),
wroteOffset
);
appendResult
=
new
AppendMessageResult
(
AppendMessageStatus
.
PUT_OK
,
wroteOffset
,
encodeResult
.
data
.
length
,
msgId
,
System
.
currentTimeMillis
(),
queueOffset
,
0
);
...
...
@@ -465,7 +465,7 @@ public class DLedgerCommitLog extends CommitLog {
if
(
offset
<
dividedCommitlogOffset
)
{
return
getMessage
(
offset
,
size
);
}
int
mappedFileSize
=
this
.
dLedgerServer
.
getdLegerConfig
().
getMappedFileSizeForEntryData
();
int
mappedFileSize
=
this
.
dLedgerServer
.
getdLe
d
gerConfig
().
getMappedFileSizeForEntryData
();
MmapFile
mappedFile
=
this
.
dLedgerFileList
.
findMappedFileByOffset
(
offset
,
offset
==
0
);
if
(
mappedFile
!=
null
)
{
int
pos
=
(
int
)
(
offset
%
mappedFileSize
);
...
...
@@ -678,22 +678,24 @@ public class DLedgerCommitLog extends CommitLog {
}
static
class
DLe
gerSelectMappedBufferResult
extends
SelectMappedBufferResult
{
public
static
class
DLed
gerSelectMappedBufferResult
extends
SelectMappedBufferResult
{
private
SelectMmapBufferResult
sbr
;
public
DLegerSelectMappedBufferResult
(
SelectMmapBufferResult
sbr
)
{
public
DLe
d
gerSelectMappedBufferResult
(
SelectMmapBufferResult
sbr
)
{
super
(
sbr
.
getStartOffset
(),
sbr
.
getByteBuffer
(),
sbr
.
getSize
(),
null
);
this
.
sbr
=
sbr
;
}
public
synchronized
void
release
()
{
super
.
release
();
sbr
.
release
();
if
(
sbr
!=
null
)
{
sbr
.
release
();
}
}
}
public
DLegerServer
getdLedgerServer
()
{
public
DLe
d
gerServer
getdLedgerServer
()
{
return
dLedgerServer
;
}
...
...
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerSelectMappedBufferResult.java
已删除
100644 → 0
浏览文件 @
b31c17f9
/*
* 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.store.dledger
;
import
io.openmessaging.storage.dleger.store.file.SelectMmapBufferResult
;
import
org.apache.rocketmq.store.SelectMappedBufferResult
;
public
class
DLedgerSelectMappedBufferResult
extends
SelectMappedBufferResult
{
private
SelectMmapBufferResult
sbr
;
public
DLedgerSelectMappedBufferResult
(
SelectMmapBufferResult
sbr
)
{
super
(
sbr
.
getStartOffset
(),
sbr
.
getByteBuffer
(),
sbr
.
getSize
(),
null
);
this
.
sbr
=
sbr
;
}
@Override
public
synchronized
void
release
()
{
super
.
release
();
sbr
.
release
();
}
}
store/src/test/java/org/apache/rocketmq/store/dledger/DLedgerCommitlogTest.java
浏览文件 @
58496c2f
...
...
@@ -8,7 +8,7 @@ import java.util.UUID;
import
org.apache.rocketmq.common.BrokerConfig
;
import
org.apache.rocketmq.common.message.MessageDecoder
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
io.openmessaging.storage.dle
ger.DLe
gerServer
;
import
io.openmessaging.storage.dle
dger.DLed
gerServer
;
import
org.apache.rocketmq.store.DefaultMessageStore
;
import
org.apache.rocketmq.store.GetMessageResult
;
import
org.apache.rocketmq.store.GetMessageStatus
;
...
...
@@ -43,8 +43,8 @@ public class DLedgerCommitlogTest extends StoreTestBase {
},
new
BrokerConfig
());
if
(
leaderId
!=
null
)
{
DLegerServer
dLegerServer
=
((
DLedgerCommitLog
)
defaultMessageStore
.
getCommitLog
()).
getdLedgerServer
();
dLegerServer
.
getdLegerConfig
().
setEnableLeaderElector
(
false
);
DLe
d
gerServer
dLegerServer
=
((
DLedgerCommitLog
)
defaultMessageStore
.
getCommitLog
()).
getdLedgerServer
();
dLegerServer
.
getdLe
d
gerConfig
().
setEnableLeaderElector
(
false
);
if
(
selfId
.
equals
(
leaderId
))
{
dLegerServer
.
getMemberState
().
changeToLeader
(-
1
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录