未验证 提交 d429aa24 编写于 作者: W WJL3333 提交者: GitHub

[ISSUE #3375] Lazy init GetMessageResult only when find message

上级 6d78d795
......@@ -537,7 +537,8 @@ public class DefaultMessageStore implements MessageStore {
long minOffset = 0;
long maxOffset = 0;
GetMessageResult getResult = new GetMessageResult();
// lazy init when find msg.
GetMessageResult getResult = null;
final long maxOffsetPy = this.commitLog.getMaxOffset();
......@@ -574,6 +575,9 @@ public class DefaultMessageStore implements MessageStore {
int i = 0;
final int maxFilterMessageCount = Math.max(16000, maxMsgNums * ConsumeQueue.CQ_STORE_UNIT_SIZE);
final boolean diskFallRecorded = this.messageStoreConfig.isDiskFallRecorded();
getResult = new GetMessageResult(maxMsgNums);
ConsumeQueueExt.CqExtUnit cqExtUnit = new ConsumeQueueExt.CqExtUnit();
for (; i < bufferConsumeQueue.getSize() && i < maxFilterMessageCount; i += ConsumeQueue.CQ_STORE_UNIT_SIZE) {
long offsetPy = bufferConsumeQueue.getByteBuffer().getLong();
......@@ -677,6 +681,11 @@ public class DefaultMessageStore implements MessageStore {
long elapsedTime = this.getSystemClock().now() - beginTime;
this.storeStatsService.setGetMessageEntireTimeMax(elapsedTime);
// lazy init no data found.
if (getResult == null) {
getResult = new GetMessageResult(0);
}
getResult.setStatus(status);
getResult.setNextBeginOffset(nextBeginOffset);
getResult.setMaxOffset(maxOffset);
......
......@@ -23,10 +23,8 @@ import org.apache.rocketmq.store.stats.BrokerStatsManager;
public class GetMessageResult {
private final List<SelectMappedBufferResult> messageMapedList =
new ArrayList<SelectMappedBufferResult>(100);
private final List<ByteBuffer> messageBufferList = new ArrayList<ByteBuffer>(100);
private final List<SelectMappedBufferResult> messageMapedList;
private final List<ByteBuffer> messageBufferList;
private GetMessageStatus status;
private long nextBeginOffset;
......@@ -40,6 +38,13 @@ public class GetMessageResult {
private int msgCount4Commercial = 0;
public GetMessageResult() {
messageMapedList = new ArrayList<>(100);
messageBufferList = new ArrayList<>(100);
}
public GetMessageResult(int resultSize) {
messageMapedList = new ArrayList<>(resultSize);
messageBufferList = new ArrayList<>(resultSize);
}
public GetMessageStatus getStatus() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册