Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3983] Optimize MessageQueue #3984

Merged
merged 4 commits into from
Jun 7, 2023
Merged

Conversation

mxsm
Copy link
Member

@mxsm mxsm commented May 20, 2023

Fixes #3983

Motivation

Explain the content here.
Explain why you want to make the changes and what problem you're trying to solve.

Modifications

Optimize MessageQueue and add some comments

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@mxsm mxsm force-pushed the eventmesh-3983 branch from d9e57c0 to 5dee318 Compare May 22, 2023 15:58
}

/**
* Insert the message at the tail of this queue, waiting for space to become available if the queue is full
* Inserts the specified MessageEntity object into the queue.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original comment seems to be clear for making developer or user understand this method easier and faster. Maybe you can combine original comments and yours. CC @xwm1992

@@ -78,10 +82,10 @@ public void put(MessageEntity messageEntity) throws InterruptedException {
}

/**
* Get the first message at this queue, waiting for the message is available if the queue is empty, this method will not remove the message
* Retrieves and removes the head of the queue.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original comment seems to be more clear for making developer or user understand this method easier and faster. CC @xwm1992

@@ -143,24 +147,30 @@ public MessageEntity getTail() {
}

/**
* Get the message by offset, since the offset is increment, so we can get the first message in this queue and calculate the index of this offset
* Retrieves the MessageEntity object with the specified offset.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original comment seems to be more clear for making developer or user understand this class easier and faster. CC @xwm1992

return null;
}
int headIndex = takeIndex;
int tailIndex = putIndex - 1;
MessageEntity head = itemAt(headIndex);
if (head.getOffset() > offset) {
Copy link
Member

@pandaapo pandaapo May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int headIndex = takeIndex, this assignment seems to be unnecessary. CC @xwm1992

tailIndex += items.length;
}
MessageEntity tail = itemAt(tailIndex);
if (tail.getOffset() < offset) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of returning null when tail == null is lost in your modification. CC @xwm1992

@@ -55,21 +58,22 @@ public MessageQueue(int capacity) {
this.items = new MessageEntity[capacity];
this.lock = new ReentrantLock();
this.notEmpty = lock.newCondition();
this.notFull = lock.newCondition();
this.noteFull = lock.newCondition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 'notFull'.

/**
* This is a block queue, can get entity by offset. The queue is a FIFO data structure.
* This is a block queue, can get entity by offset. The queue is a FIFO data structure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems meaningless to remove the last period from the original comment and add a space before it. CC @xwm1992

@xwm1992
Copy link
Contributor

xwm1992 commented May 25, 2023

@mxsm please take a look for review suggestions, and fix the ci check error, thanks.

@mxsm
Copy link
Member Author

mxsm commented May 26, 2023

@mxsm please take a look for review suggestions, and fix the ci check error, thanks.

I will

@codecov
Copy link

codecov bot commented May 29, 2023

Codecov Report

Merging #3984 (322e2b5) into master (fb144bb) will decrease coverage by 0.01%.
The diff coverage is 57.14%.

❗ Current head 322e2b5 differs from pull request most recent head 09a944c. Consider uploading reports for the commit 09a944c to get more accurate results

@@             Coverage Diff              @@
##             master    #3984      +/-   ##
============================================
- Coverage     14.22%   14.21%   -0.01%     
  Complexity     1328     1328              
============================================
  Files           580      580              
  Lines         28856    28859       +3     
  Branches       2792     2793       +1     
============================================
- Hits           4105     4103       -2     
- Misses        24361    24368       +7     
+ Partials        390      388       -2     
Impacted Files Coverage Δ
...ntmesh/storage/standalone/broker/MessageQueue.java 61.44% <57.14%> (-7.31%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

xwm1992
xwm1992 previously approved these changes May 29, 2023
lrhkobe
lrhkobe previously approved these changes May 30, 2023
@xwm1992
Copy link
Contributor

xwm1992 commented May 31, 2023

@mxsm please fix the conflicts.

@mxsm mxsm dismissed stale reviews from lrhkobe and xwm1992 via 09a944c June 4, 2023 14:05
@mxsm mxsm force-pushed the eventmesh-3983 branch from 79a06db to 09a944c Compare June 4, 2023 14:05
@mxsm mxsm requested review from xwm1992 and lrhkobe June 4, 2023 14:05
@mxsm
Copy link
Member Author

mxsm commented Jun 4, 2023

@mxsm please fix the conflicts.

@xwm1992 Done

@xwm1992 xwm1992 merged commit c5bbd67 into apache:master Jun 7, 2023
@mxsm mxsm deleted the eventmesh-3983 branch June 7, 2023 04:26
kyooosukedn pushed a commit to kyooosukedn/eventmesh that referenced this pull request Jun 18, 2023
* [ISSUE apache#3983] Optimize MessageQueue

* modify public of attribute items  to private

* optimize code readability

* optimize code logic
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.

[Enhancement] Optimize MessageQueue
4 participants