Skip to content

Acknowledge MQ message only after a TriggerInstance is stored in DB - #2643

Merged
manasdk merged 16 commits into
masterfrom
ti_msg_ack
Apr 28, 2016
Merged

manasdk merged 16 commits into
masterfrom
ti_msg_ack

Conversation

@manasdk

@manasdk manasdk commented Apr 22, 2016 •

Copy link
Copy Markdown
Contributor

With this PR we make sure that only after a TriggerInstance is saved in the DB will the message be ack-ed to RMQ. This way if the rulesengine process goes down while the event is being processed at least the event will not be lost.

There are various stages in the handling of a TriggerInstance from the perspective of the RulesEngine

  1. pending -. RulesEngine picks up the TI from the MQ and records in the DB. At this point it is safe to ACK back to RMQ.
  2. processing - TI is picked up for processing and figures out the applicable rules etc.
  3. processed - RulesEngine has determined the executions to create and those are now scheduled.
  4. processing_failed - TI is picked up but for one or another reason there is a failure to process. There should be more information about this in a corresponding RuleEnforcement or in the worst case logs(ugh!)

If RulesEngine crashes after firing off executions but not before moving a TriggerInstance from processing -> processed then there will be a mis-calculated step. Still there will be no TI loss.

A future improvement could be for st2 to track such processing failures and go automatically re-process the executions.

$ st2 trigger-instance list --status processing
+----+---------+-----------------+--------+
| id | trigger | occurrence_time | status |
+----+---------+-----------------+--------+
+----+---------+-----------------+--------+

Todo

  • Decouple Trace creation from message acknowledgement.
  • Some doc around StagedMessageHandler

manasdk added 3 commits April 21, 2016 16:57
* Ack-ing a message pre creation in DB means that if the RulesEngine crashes
  it could mean st2 would loose that TriggerInstance. By delaying the ACK to
  RMQ there is atleast some opportunity to recover the message.
* Wrote up some new MessageHandler and QueueConsumer interfaces.
* Also remove unnecessary RMQ connections from test
@manasdk manasdk added the WIP label Apr 22, 2016
@Kami

Kami commented Apr 23, 2016

Copy link
Copy Markdown
Member

Some background / context on this change would be good.

I assume we don't want a message to be ACKed if the TriggerInstance (or underlying Trace) creation fails, right?

Also, afaik, Trace creation should be / is best-effort anyway and we proceed even if it fails, right?

@manasdk

manasdk commented Apr 25, 2016

Copy link
Copy Markdown
Contributor Author

Some background / context on this change would be good.

Yes, will get more info out.

@manasdk manasdk changed the title Ti msg ack [WIP] Ti msg ack Apr 25, 2016
@manasdk

manasdk commented Apr 25, 2016

Copy link
Copy Markdown
Contributor Author

Also, afaik, Trace creation should be / is best-effort anyway and we proceed even if it fails, right?

Yes. There are some quirks in how I handled async creation etc which makes is a bit tricky to not depend on trace create but I will fix that part. It is not something I am focusing on at this point.



@six.add_metaclass(abc.ABCMeta)
class StagedMessageHandler(MessageHandler):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This ideally should be in its own file but whatevs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

E_TOO_MUCH_EFFORT

@lakshmi-kannan

Copy link
Copy Markdown
Contributor

Looking forward to CLI and API changes.

@manasdk manasdk changed the title [WIP] Ti msg ack Acknowledge MQ message only after a TriggerInstance is stored in DB Apr 27, 2016
manasdk added 2 commits April 27, 2016 17:17
* this way ack only requires a TriggerInstance to be created
* while at it added some docs on the new interfaces which are a bit quirky.
@manasdk
manasdk merged commit db12af5 into master Apr 28, 2016
@manasdk
manasdk deleted the ti_msg_ack branch April 28, 2016 22:42
"""
MessageHandler to deal with messages in 2 steps.
1. pre_ack_process : This is called on the handler before ack-ing the message.
2. process: Called after ack-in the messages

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Honestly, for consistency and to make it more obvious, I would prefer process to be called post_ack_process (or similar), but I imagine you just kept it as process, because it was called that before.

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.

3 participants