Repository navigation
Acknowledge MQ message only after a TriggerInstance is stored in DB - #2643
Conversation
* 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
|
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? |
Yes, will get more info out. |
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): |
There was a problem hiding this comment.
This ideally should be in its own file but whatevs.
|
Looking forward to CLI and API changes. |
* 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.
| """ | ||
| 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 |
There was a problem hiding this comment.
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.
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
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.processing- TI is picked up for processing and figures out the applicable rules etc.processed- RulesEngine has determined the executions to create and those are now scheduled.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 correspondingRuleEnforcementor in the worst case logs(ugh!)If RulesEngine crashes after firing off executions but not before moving a TriggerInstance from
processing->processedthen there will be a mis-calculated step. Still there will be no TI loss.A future improvement could be for
st2to track such processing failures and go automatically re-process the executions.Todo