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

Add acking mechamism for shared dispatch #1872

Merged
merged 9 commits into from
Nov 21, 2018

Conversation

spring2maz
Copy link
Collaborator

@spring2maz spring2maz commented Sep 27, 2018

For QoS0 messages, no acking
For QoS1/2 messages, 'ACK' if any:

  • ACK when QoS is downgraded to 0
  • Message is sent to connection process

'NACK' if any:

  • There is no alive connection process for the receiving session
  • Message queue is full and the receiving session starts to drop old messages
  • The receiving session crash

Upon 'NACK', messages are dispatched to the 'next' subscriber in the group,
depending on the shared subscription dispatch strategy.

@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch from 0047c28 to be02999 Compare September 27, 2018 22:46
@emqplus emqplus self-assigned this Sep 28, 2018
@emqplus emqplus added this to the 3.0-beta.4 milestone Sep 28, 2018
include/emqx.hrl Outdated Show resolved Hide resolved
src/emqx_shared_sub.erl Outdated Show resolved Hide resolved
@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch from be02999 to d93d875 Compare October 6, 2018 17:08
@spring2maz spring2maz changed the base branch from shared-subscriber-should-key-by-group-id to emqx30 October 6, 2018 17:08
@coveralls
Copy link
Collaborator

coveralls commented Oct 6, 2018

Pull Request Test Coverage Report for Build 3832

  • 66 of 80 (82.5%) changed or added relevant lines in 3 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.4%) to 61.324%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/emqx_session.erl 18 23 78.26%
src/emqx_shared_sub.erl 47 56 83.93%
Files with Coverage Reduction New Missed Lines %
src/emqx_shared_sub.erl 1 80.0%
src/emqx_session.erl 1 73.24%
Totals Coverage Status
Change from base Build 3818: 0.4%
Covered Lines: 2770
Relevant Lines: 4517

💛 - Coveralls

@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch 2 times, most recently from 02d9651 to 2de01a2 Compare October 6, 2018 21:17
@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch from c6010a7 to 5f1b2d8 Compare November 3, 2018 09:37
@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch from 10101e5 to 58d69d5 Compare November 19, 2018 18:25
For QoS0 messages, no acking
For QoS1/2 messages, 'ACK' at any of events below:
 - ACK when QoS is downgraded to 0
 - Message is sent to connection process
'NACK' at any of events below:
 - Message queue is full and the receiving session starts to drop old messages
 - The receiving session crash
Upon 'NACK', messages are dispatched to the 'next' subscriber in the group,
depending on the shared subscription dispatch strategy.
Prior to this commit, QoS-2 messages a published through the session process
which can at the same time being a receiving process for messages
published by other sessions. This works fine until we introduce
synced-dispatch for shared subscription, because then there is a risk
of deadlock of two (or more) processes sending to messages and waiting
for acknowledges around the same moment.

In this commit, the 'publish' call for QoS-2 messages have been replaced
with 'register_publish_packet_id' and return immediately after the
packet ID (and timestamp) is registered in the session process, the
the publish work is done by caller (connection) process like the way
QoS-0/1 messages are handled
Also nack if a message is dropped due to message queue being full
@spring2maz spring2maz force-pushed the reliable-delivery-of-qos1-2-in-shared-sub branch from 58d69d5 to af9dc10 Compare November 19, 2018 18:30
@turtleDeng turtleDeng merged commit a2c658b into emqx30 Nov 21, 2018
@turtleDeng turtleDeng deleted the reliable-delivery-of-qos1-2-in-shared-sub branch November 21, 2018 14:49
tigercl pushed a commit that referenced this pull request Nov 24, 2018
* Add acking mechamism for shared dispatch

For QoS0 messages, no acking
For QoS1/2 messages, 'ACK' at any of events below:
 - ACK when QoS is downgraded to 0
 - Message is sent to connection process
'NACK' at any of events below:
 - Message queue is full and the receiving session starts to drop old messages
 - The receiving session crash
Upon 'NACK', messages are dispatched to the 'next' subscriber in the group,
depending on the shared subscription dispatch strategy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants