Skip to content

Comments

[ISSUE#2740]optimize some methods#2742

Closed
sunxi92 wants to merge 1 commit intoapache:developfrom
sunxi92:optimize
Closed

[ISSUE#2740]optimize some methods#2742
sunxi92 wants to merge 1 commit intoapache:developfrom
sunxi92:optimize

Conversation

@sunxi92
Copy link
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

Coverage Status

Coverage decreased (-0.1%) to 51.805% when pulling 1f9925c on sunxi92:optimize into 3ae2517 on apache:master.

@codecov-io
Copy link

Codecov Report

Merging #2742 (1f9925c) into master (3ae2517) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2742      +/-   ##
============================================
+ Coverage     45.94%   46.00%   +0.06%     
+ Complexity     4317     4316       -1     
============================================
  Files           547      547              
  Lines         36236    36231       -5     
  Branches       4808     4807       -1     
============================================
+ Hits          16648    16669      +21     
+ Misses        17503    17473      -30     
- Partials       2085     2089       +4     
Impacted Files Coverage Δ Complexity Δ
...pache/rocketmq/store/dledger/DLedgerCommitLog.java 73.64% <100.00%> (-0.06%) 70.00 <0.00> (-2.00)
...ain/java/org/apache/rocketmq/test/util/MQWait.java 43.24% <0.00%> (-5.41%) 3.00% <0.00%> (ø%)
...mq/client/impl/consumer/RebalanceLitePullImpl.java 49.15% <0.00%> (-5.09%) 10.00% <0.00%> (-1.00%)
...ketmq/client/impl/consumer/PullMessageService.java 75.55% <0.00%> (-4.45%) 9.00% <0.00%> (-1.00%)
...ketmq/common/protocol/body/ConsumerConnection.java 95.83% <0.00%> (-4.17%) 13.00% <0.00%> (-1.00%)
...client/consumer/store/RemoteBrokerOffsetStore.java 67.56% <0.00%> (-1.81%) 20.00% <0.00%> (-2.00%)
...etmq/client/latency/LatencyFaultToleranceImpl.java 50.00% <0.00%> (ø) 8.00% <0.00%> (ø%)
...he/rocketmq/client/trace/AsyncTraceDispatcher.java 74.11% <0.00%> (+0.50%) 17.00% <0.00%> (ø%)
...rocketmq/client/impl/factory/MQClientInstance.java 50.14% <0.00%> (+0.58%) 90.00% <0.00%> (ø%)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ae2517...1f9925c. Read the comment docs.

@sunxi92 sunxi92 changed the title [#2740]optimize some methods [ISSUE#2740]optimize some methods Apr 20, 2021
@yuz10 yuz10 changed the base branch from master to develop March 9, 2022 03:54
@github-actions
Copy link

This PR is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this PR.

@github-actions github-actions bot added the stale label Jul 20, 2023
@github-actions
Copy link

This PR was closed because it has been inactive for 3 days since being marked as stale.

@github-actions github-actions bot closed this Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants