Repository navigation
Let MessageGroupQueue producers in whenever there is room - #11736
Open
LindseyZ1205 wants to merge 1 commit into
Open
LindseyZ1205 wants to merge 1 commit into
LindseyZ1205 wants to merge 1 commit into
Conversation
The `drainTo()` signals the "not full" condition only once, however many messages it removes. When several producers wait in the `put()` or the `offer(message, timeout, unit)` of a full bounded queue, e.g. senders to a `QueueChannel` from the `MessageChannels.queue(messageStore, groupId)` with a `capacity()`, a `QueueChannel.clear()` wakes up only one of them. The others keep waiting (or time out and fail the send), although the queue has room for them. The `offer(message, timeout, unit)` also rejects the message when there is no time left to wait, even if the queue has room for it: with a zero timeout, it does not add the message even to an empty queue, unlike the `BlockingQueue` contract. * Signal all the waiting producers in the `drainTo()`; each of them checks the size of the queue again * Add the message in the `offer(message, timeout, unit)` whenever there is room, regardless of the time left Signed-off-by: Yingzi Zhang <yingzizhang1205@gmail.com>
cppwfs
requested changes
Nov 16, 2026
| @Test | ||
| void timedOfferWithoutTimeToWaitAddsMessageIfThereIsRoom() throws InterruptedException { | ||
| MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), "FOO", 1); | ||
| assertThat(queue.offer(new GenericMessage<>("foo"), 0, TimeUnit.MILLISECONDS)).isTrue(); |
Contributor
There was a problem hiding this comment.
Coding standards require that test code does not use terms like foo and bar. Please replace with meaningful names.
| assertThat(queue.offer(new GenericMessage<>("bar"), 0, TimeUnit.MILLISECONDS)).isFalse(); | ||
| assertThat(queue.size()).isEqualTo(1); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Add a test for unbounded queue. i.e An unbounded queue rejecting a message because there was no time to wait. It would create a MessageGroupQueue without a capacity, call offer() with a zero timeout, and assert that it returns true and that the queue size is 1.
artembilan
requested changes
Nov 16, 2026
artembilan
left a comment
Member
There was a problem hiding this comment.
I treat this as a bug, so for next patch version plus back-ports.
Thanks
| if (timeoutInNanos > 0) { | ||
| offered = this.doOffer(message); | ||
| } | ||
| offered = this.doOffer(message); |
Member
There was a problem hiding this comment.
No this. on method calls, please.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When several producers wait for room in a full bounded
MessageGroupQueue, adrainTo()wakes up only one of them: it signals the "not full" condition once, however many messages it removes. TheQueueChannel.clear()calls it, so with aQueueChannelfromMessageChannels.queue(messageStore, groupId).capacity(2), two senders waiting insend()and aclear(), one sender gets in and the other one keeps waiting, although the queue has room for it. With a send timeout, that sender fails the send when the timeout expires.The
offer(message, timeout, unit)also rejects the message when there is no time left to wait, even if the queue has room for it:offer(message, 0, TimeUnit.MILLISECONDS)returnsfalseeven for an empty queue, while theBlockingQueuecontract (and the JDK queues) add the message when there is room.This signals all the waiting producers in the
drainTo()(each of them checks the size of the queue again), and adds the message in the timedoffer()whenever there is room.I ran the
MessageGroupQueueTests(the two new tests fail without the change), theQueueChannelTests, thePriorityChannelTestsand theMessageGroupQueueTestsof the JDBC module (withRUN_LONG_INTEGRATION_TESTS=true), and Checkstyle on the two files. As the snapshot dependencies ofmainaren't in my cache, I compiled this branch'sMessageGroupQueueand the tests against the core module ofee9c722; the core classes they use are the same there as onmain, apart from theMessageGroupQueueitself.