hussein-awala opened a new pull request, #31987:
URL: https://github.com/apache/airflow/pull/31987

   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   Currently if the trigger yield multiple events, we load them all in a queue, 
and we pass through them multiple times but we use only the first one:
   In this block we pass through all the events to get the trigger ids, and we 
add them to a set, and since they have the same trigger id, we don't need them 
all in this block:
   
https://github.com/apache/airflow/blob/fc0e5a4d42ee882ca5bc20ea65be38b2c739644d/airflow/jobs/triggerer_job_runner.py#L658-L663
   
   Then we handle them using this method:
   
https://github.com/apache/airflow/blob/fc0e5a4d42ee882ca5bc20ea65be38b2c739644d/airflow/jobs/triggerer_job_runner.py#L378-L389
   
   But if we check the method `Trigger.submit_event`, we found that we filter 
on `TaskInstance.state` which we update to `scheduled` when we handle the first 
event, so the next sql queries are useless and will always return an empty list:
   
https://github.com/apache/airflow/blob/0f1cef27a5a19dd56e6b07ab0bf9868fb850421a/airflow/models/trigger.py#L142-L160
   
   And if we check the result of the tests I added in #31985, we found that 
it's possible to have a lot of generated events from the same trigger, so we 
can avoid increasing the memory size and reduce the SQL queries by just loading 
the first event.
   
   If there is a need to process all the generated events (which is not the 
case now), we need to change our handling method to wait the task termination 
and we need to provide all these events to the method `execute_complete` as a 
list which is a breaking change, but for now, the best solution is just loading 
the first event.
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)**
 for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party 
License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a 
newsfragment file, named `{pr_number}.significant.rst` or 
`{issue_number}.significant.rst`, in 
[newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to