Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
c29d5fd7
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
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看板
提交
c29d5fd7
编写于
3月 09, 2021
作者:
A
ayanamist
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[RIP-19] Pop Consuming (store)
上级
60ad9abd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
282 addition
and
5 deletion
+282
-5
store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
...n/java/org/apache/rocketmq/store/DefaultMessageStore.java
+2
-1
store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java
...main/java/org/apache/rocketmq/store/GetMessageResult.java
+10
-0
store/src/main/java/org/apache/rocketmq/store/MessageStore.java
...src/main/java/org/apache/rocketmq/store/MessageStore.java
+3
-1
store/src/main/java/org/apache/rocketmq/store/pop/AckMsg.java
...e/src/main/java/org/apache/rocketmq/store/pop/AckMsg.java
+87
-0
store/src/main/java/org/apache/rocketmq/store/pop/PopCheckPoint.java
...ain/java/org/apache/rocketmq/store/pop/PopCheckPoint.java
+163
-0
store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java
...pache/rocketmq/store/schedule/ScheduleMessageService.java
+17
-3
未找到文件。
store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
浏览文件 @
c29d5fd7
...
...
@@ -672,7 +672,7 @@ public class DefaultMessageStore implements MessageStore {
}
this
.
storeStatsService
.
getGetMessageTransferedMsgCount
().
incrementAndGet
();
getResult
.
addMessage
(
selectResult
);
getResult
.
addMessage
(
selectResult
,
offset
+
(
i
/
ConsumeQueue
.
CQ_STORE_UNIT_SIZE
)
);
status
=
GetMessageStatus
.
FOUND
;
nextPhyFileStartOffset
=
Long
.
MIN_VALUE
;
}
...
...
@@ -1496,6 +1496,7 @@ public class DefaultMessageStore implements MessageStore {
return
haService
;
}
@Override
public
ScheduleMessageService
getScheduleMessageService
()
{
return
scheduleMessageService
;
}
...
...
store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java
浏览文件 @
c29d5fd7
...
...
@@ -27,6 +27,7 @@ public class GetMessageResult {
new
ArrayList
<
SelectMappedBufferResult
>(
100
);
private
final
List
<
ByteBuffer
>
messageBufferList
=
new
ArrayList
<
ByteBuffer
>(
100
);
private
final
List
<
Long
>
messageQueueOffset
=
new
ArrayList
<>(
100
);
private
GetMessageStatus
status
;
private
long
nextBeginOffset
;
...
...
@@ -90,6 +91,11 @@ public class GetMessageResult {
mapedBuffer
.
getSize
()
/
BrokerStatsManager
.
SIZE_PER_COUNT
);
}
public
void
addMessage
(
final
SelectMappedBufferResult
mapedBuffer
,
final
long
queueOffset
)
{
addMessage
(
mapedBuffer
);
this
.
messageQueueOffset
.
add
(
queueOffset
);
}
public
void
release
()
{
for
(
SelectMappedBufferResult
select
:
this
.
messageMapedList
)
{
select
.
release
();
...
...
@@ -124,6 +130,10 @@ public class GetMessageResult {
this
.
msgCount4Commercial
=
msgCount4Commercial
;
}
public
List
<
Long
>
getMessageQueueOffset
()
{
return
messageQueueOffset
;
}
@Override
public
String
toString
()
{
return
"GetMessageResult [status="
+
status
+
", nextBeginOffset="
+
nextBeginOffset
+
", minOffset="
...
...
store/src/main/java/org/apache/rocketmq/store/MessageStore.java
浏览文件 @
c29d5fd7
...
...
@@ -20,10 +20,10 @@ import java.util.HashMap;
import
java.util.LinkedList
;
import
java.util.Set
;
import
java.util.concurrent.CompletableFuture
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.apache.rocketmq.common.message.MessageExtBatch
;
import
org.apache.rocketmq.store.config.BrokerRole
;
import
org.apache.rocketmq.store.schedule.ScheduleMessageService
;
import
org.apache.rocketmq.store.stats.BrokerStatsManager
;
/**
...
...
@@ -383,6 +383,8 @@ public interface MessageStore {
*/
ConsumeQueue
getConsumeQueue
(
String
topic
,
int
queueId
);
ScheduleMessageService
getScheduleMessageService
();
/**
* Get BrokerStatsManager of the messageStore.
*
...
...
store/src/main/java/org/apache/rocketmq/store/pop/AckMsg.java
0 → 100644
浏览文件 @
c29d5fd7
/*
* 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.pop
;
public
class
AckMsg
{
private
long
ackOffset
;
private
long
startOffset
;
private
String
consumerGroup
;
private
String
topic
;
private
int
queueId
;
private
long
popTime
;
public
long
getPopTime
()
{
return
popTime
;
}
public
void
setPopTime
(
long
popTime
)
{
this
.
popTime
=
popTime
;
}
public
void
setQueueId
(
int
queueId
)
{
this
.
queueId
=
queueId
;
}
public
int
getQueueId
()
{
return
queueId
;
}
public
void
setTopic
(
String
topic
)
{
this
.
topic
=
topic
;
}
public
String
getTopic
()
{
return
topic
;
}
public
long
getAckOffset
()
{
return
ackOffset
;
}
public
String
getConsumerGroup
()
{
return
consumerGroup
;
}
public
void
setConsumerGroup
(
String
consumerGroup
)
{
this
.
consumerGroup
=
consumerGroup
;
}
public
void
setAckOffset
(
long
ackOffset
)
{
this
.
ackOffset
=
ackOffset
;
}
public
long
getStartOffset
()
{
return
startOffset
;
}
public
void
setStartOffset
(
long
startOffset
)
{
this
.
startOffset
=
startOffset
;
}
@Override
public
String
toString
()
{
final
StringBuilder
sb
=
new
StringBuilder
(
"AckMsg{"
);
sb
.
append
(
"ackOffset="
).
append
(
ackOffset
);
sb
.
append
(
", startOffset="
).
append
(
startOffset
);
sb
.
append
(
", consumerGroup='"
).
append
(
consumerGroup
).
append
(
'\''
);
sb
.
append
(
", topic='"
).
append
(
topic
).
append
(
'\''
);
sb
.
append
(
", queueId="
).
append
(
queueId
);
sb
.
append
(
", popTime="
).
append
(
popTime
);
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
}
store/src/main/java/org/apache/rocketmq/store/pop/PopCheckPoint.java
0 → 100644
浏览文件 @
c29d5fd7
/*
* 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.pop
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
PopCheckPoint
{
private
long
startOffset
;
private
long
popTime
;
private
long
invisibleTime
;
private
int
bitMap
;
private
byte
num
;
private
byte
queueId
;
private
String
topic
;
private
String
cid
;
private
long
reviveOffset
;
private
List
<
Integer
>
queueOffsetDiff
;
public
long
getReviveOffset
()
{
return
reviveOffset
;
}
public
void
setReviveOffset
(
long
reviveOffset
)
{
this
.
reviveOffset
=
reviveOffset
;
}
public
long
getStartOffset
()
{
return
startOffset
;
}
public
void
setStartOffset
(
long
startOffset
)
{
this
.
startOffset
=
startOffset
;
}
public
void
getStartOffset
(
long
startOffset
)
{
this
.
startOffset
=
startOffset
;
}
public
void
setPopTime
(
long
popTime
)
{
this
.
popTime
=
popTime
;
}
public
void
setInvisibleTime
(
long
invisibleTime
)
{
this
.
invisibleTime
=
invisibleTime
;
}
public
long
getPopTime
()
{
return
popTime
;
}
public
long
getInvisibleTime
()
{
return
invisibleTime
;
}
public
long
getReviveTime
()
{
return
popTime
+
invisibleTime
;
}
public
int
getBitMap
()
{
return
bitMap
;
}
public
void
setBitMap
(
int
bitMap
)
{
this
.
bitMap
=
bitMap
;
}
public
byte
getNum
()
{
return
num
;
}
public
void
setNum
(
byte
num
)
{
this
.
num
=
num
;
}
public
byte
getQueueId
()
{
return
queueId
;
}
public
void
setQueueId
(
byte
queueId
)
{
this
.
queueId
=
queueId
;
}
public
String
getTopic
()
{
return
topic
;
}
public
void
setTopic
(
String
topic
)
{
this
.
topic
=
topic
;
}
public
String
getCId
()
{
return
cid
;
}
public
void
setCId
(
String
cid
)
{
this
.
cid
=
cid
;
}
public
List
<
Integer
>
getQueueOffsetDiff
()
{
return
queueOffsetDiff
;
}
public
void
setQueueOffsetDiff
(
List
<
Integer
>
queueOffsetDiff
)
{
this
.
queueOffsetDiff
=
queueOffsetDiff
;
}
public
void
addDiff
(
int
diff
)
{
if
(
this
.
queueOffsetDiff
==
null
)
{
this
.
queueOffsetDiff
=
new
ArrayList
<>(
8
);
}
this
.
queueOffsetDiff
.
add
(
diff
);
}
public
int
indexOfAck
(
long
ackOffset
)
{
if
(
ackOffset
<
startOffset
)
{
return
-
1
;
}
// old version of checkpoint
if
(
queueOffsetDiff
==
null
||
queueOffsetDiff
.
isEmpty
())
{
if
(
ackOffset
-
startOffset
<
num
)
{
return
(
int
)
(
ackOffset
-
startOffset
);
}
return
-
1
;
}
// new version of checkpoint
return
queueOffsetDiff
.
indexOf
((
int
)
(
ackOffset
-
startOffset
));
}
public
long
ackOffsetByIndex
(
byte
index
)
{
// old version of checkpoint
if
(
queueOffsetDiff
==
null
||
queueOffsetDiff
.
isEmpty
())
{
return
startOffset
+
index
;
}
return
startOffset
+
queueOffsetDiff
.
get
(
index
);
}
@Override
public
String
toString
()
{
return
"PopCheckPoint [topic="
+
topic
+
", cid="
+
cid
+
", queueId="
+
queueId
+
", startOffset="
+
startOffset
+
", bitMap="
+
bitMap
+
", num="
+
num
+
", reviveTime="
+
getReviveTime
()
+
", reviveOffset="
+
reviveOffset
+
", diff="
+
queueOffsetDiff
+
"]"
;
}
}
store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java
浏览文件 @
c29d5fd7
...
...
@@ -16,25 +16,28 @@
*/
package
org.apache.rocketmq.store.schedule
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.stream.Collectors
;
import
org.apache.rocketmq.common.ConfigManager
;
import
org.apache.rocketmq.common.TopicFilterType
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.topic.TopicValidator
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
import
org.apache.rocketmq.common.message.MessageAccessor
;
import
org.apache.rocketmq.common.message.MessageConst
;
import
org.apache.rocketmq.common.message.MessageDecoder
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.apache.rocketmq.common.running.RunningStats
;
import
org.apache.rocketmq.common.topic.TopicValidator
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
import
org.apache.rocketmq.store.ConsumeQueue
;
import
org.apache.rocketmq.store.ConsumeQueueExt
;
import
org.apache.rocketmq.store.DefaultMessageStore
;
...
...
@@ -221,6 +224,17 @@ public class ScheduleMessageService extends ConfigManager {
return
true
;
}
public
int
computeDelayLevel
(
long
timeMillis
)
{
long
intervalMillis
=
timeMillis
-
System
.
currentTimeMillis
();
List
<
Map
.
Entry
<
Integer
,
Long
>>
sortedLevels
=
delayLevelTable
.
entrySet
().
stream
().
sorted
(
Comparator
.
comparingLong
(
Map
.
Entry
::
getValue
)).
collect
(
Collectors
.
toList
());
for
(
Map
.
Entry
<
Integer
,
Long
>
entry
:
sortedLevels
)
{
if
(
entry
.
getValue
()
>
intervalMillis
)
{
return
entry
.
getKey
();
}
}
return
sortedLevels
.
get
(
sortedLevels
.
size
()
-
1
).
getKey
();
}
class
DeliverDelayedMessageTimerTask
extends
TimerTask
{
private
final
int
delayLevel
;
private
final
long
offset
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录