Skip to content

[#2740]optimize some methods#2741

Closed
sunxi92 wants to merge 1 commit intoapache:masterfrom
sunxi92:Optimize
Closed

[#2740]optimize some methods#2741
sunxi92 wants to merge 1 commit intoapache:masterfrom
sunxi92:Optimize

Conversation

@sunxi92
Copy link
Copy Markdown
Contributor

@sunxi92 sunxi92 commented Mar 22, 2021

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.
1
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

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.004%) to 51.897% when pulling 6fd5c6b on sunxi92:Optimize into 3ae2517 on apache:master.

@sunxi92 sunxi92 closed this Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants