Fix message IDs settlement order #11560
Merged
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.
What?
This commit fixes issues that were present only on
main
branch and were introduced by #9022.rabbit_queue_consumers:subtract_acks/3
) expect message IDs to be (n)acked in the order as they were delivered to the channel / session proc. Hence, thelists:usort(MsgIds0)
inrabbit_classic_queue:settle/5
was wrong causing not all messages to be acked adding a regression to also AMQP 0.9.1.rabbitmq-server/deps/rabbit/src/rabbit_fifo.erl
Lines 226 to 234 in 34d3f94
How?
The session proc will settle (internal) message IDs to queues in ascending (AMQP) delivery ID order, i.e. in the order messages were sent to the client and in the order messages were settled by the client.
This commit chooses to keep the session's outgoing_unsettled_map map data structure.
An alternative would have been to use a queue or lqueue for the outgoing_unsettled_map as done in
rabbitmq-server/deps/rabbit/src/rabbit_channel.erl
Line 135 in 34d3f94
rabbitmq-server/deps/rabbit/src/rabbit_queue_consumers.erl
Line 43 in 34d3f94
Whether a queue (as done by
rabbit_channel
) or a map (as done byrabbit_amqp_session
) performs better depends on the pattern how clients ack messages.A queue will likely perform good enough because usually the oldest delivered messages will be acked first.
However, given that there can be many different consumers on an AQMP 0.9.1 channel or AMQP 1.0 session, this commit favours a map because it will likely generate less garbage and is very efficient when for example a single new message (or few new messages) gets acked while many (older) messages are still checked out by the session (but by possibly different AMQP 1.0 receivers).