You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/03/22 06:51:20 UTC
[GitHub] [rocketmq] sunxi92 opened a new pull request #2741: [#2740]optimize some methods
sunxi92 opened a new pull request #2741:
URL: https://github.com/apache/rocketmq/pull/2741
While reading the RocketMQ source code, I found that there are some areas that could be optimized
1.The getData(final long offset) function in the DledgerCommitLog.java is used to get data according to the offset. In Dledger, dividedCommitlogOffset is used to separate the old commitlog from dledger commitlog, so the getData(final long offset) function should judge if offset is in old commitlog or dledger commitlog. But getData(final long offset) function repeats the judgment of whether the offset is in old commitlog or dledger commitlog. So the if statement can be deleted.
2.The checkMessageAndReturnSize(ByteBuffer byteBuffer, final boolean checkCRC,final boolean readBody) function in the DledgerCommitLog.java is called when build the DispatchRequest. The same with getData function, it should judge whether the byteBuffer is in old commitlog or dledger commitlog.The following figure shows the data format in both modes,we can see that the first field is magic in dledger, the value of magic has two value: DLedgerMmapFileStore.CURRENT_MAGIC(1) or MmapFileList.BLANK_MAGIC_CODE(-1). In old commitlog, this field is TOTALSIZE and the value in this field must be gt 1(every commitlog will be free at least 8 bytes). So we can judge the bytebuffer from the first four bytes,if the value of the first four bytes is gt 1,then the bytebuffer is in old commitlog.

In addition,isInrecoveringOldCommitlog is used to indicate that it is the first time to load mixed commitlog, need to recover the commitlog. It has nothing to do with whether the byteBuffer is in old commitlog or dledger commitlog. So I think the if statement can be deleted.
#2740
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] coveralls commented on pull request #2741: [#2740]optimize some methods
Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #2741:
URL: https://github.com/apache/rocketmq/pull/2741#issuecomment-803816421
[](https://coveralls.io/builds/38127889)
Coverage decreased (-0.004%) to 51.897% when pulling **6fd5c6b608206258d9a2ff957cf7172e1b192a4d on sunxi92:Optimize** into **3ae251751586b940b7467284966ec4fe93f86be1 on apache:master**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] sunxi92 closed pull request #2741: [#2740]optimize some methods
Posted by GitBox <gi...@apache.org>.
sunxi92 closed pull request #2741:
URL: https://github.com/apache/rocketmq/pull/2741
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org