[ 
https://issues.apache.org/jira/browse/AIRFLOW-3136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16636546#comment-16636546
 ] 

ASF GitHub Bot commented on AIRFLOW-3136:
-----------------------------------------

vardancse opened a new pull request #3994: [AIRFLOW-3136] Add retry_number to 
TaskInstance Key property to avoid race condition
URL: https://github.com/apache/incubator-airflow/pull/3994
 
 
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following 
[AIRFLOW-3136](https://issues.apache.org/jira/browse/AIRFLOW-3136) issues and 
references them in the PR title. 
   
   ### Description
   
   - [ ] Here are some details about my PR.
   We were seeing an intermittent issue where executor reports task instance 
finished while task says it's in queue state, it was due to a race condition 
between scheduler which was clearing event_buffer in _process_executor_events 
method in jobs.py executor was about to put next_retry task's status as running 
which was failed in previous try. So, we thought to add retry_number as the 
member of TaskInstance key property.
   
   ### Tests
   
   - [ ] My PR adds the following unit tests __OR__ does not need testing for 
this extremely good reason:
   
   ### Commits
   
   - [ ] My commits all reference Jira issues in their subject lines, and I 
have squashed multiple commits if they address the same issue. In addition, my 
commits follow the guidelines from "[How to write a good git commit 
message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes 
how to use it.
     - When adding new operators/hooks/sensors, the autoclass documentation 
generation needs to be added.
   
   ### Code Quality
   
   - [ ] Passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Scheduler Failing the Task retries run while processing Executor Events
> -----------------------------------------------------------------------
>
>                 Key: AIRFLOW-3136
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-3136
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: scheduler
>    Affects Versions: 1.9.0
>            Reporter: raman
>            Priority: Major
>
> Following behaviour is observed with Airflow 1.9 with LocalExecutor mode
>  
> Airflow scheduler processes the executor events in 
> "_process_executor_events(self, simple_dag_bag, session=None)" function of 
> jobs.py.
> The events are identified by key which is composed of dag id, task id, 
> execution date. So all retries of a task have the same key.
> If task retry interval is very small like 30 seconds than scheduler might 
> schedule the next retry run while the previous task run result is still in 
> the executor event queue.
> Current task run might be in queued state while scheduler is processing the 
> executor's previous events Which might make scheduler to fail the current run 
> because of following code in the jobs.py file
> def _process_executor_events(self, simple_dag_bag, session=None):
>  """
>  Respond to executor events.
>  """
>  # TODO: this shares quite a lot of code with _manage_executor_state
> TI = models.TaskInstance
>  *for key, state in 
> list(self.executor.get_event_buffer(simple_dag_bag.dag_ids)*
>  *.items()):*
>  dag_id, task_id, execution_date = key
>  self.log.info(
>  "Executor reports %s.%s execution_date=%s as %s",
>  dag_id, task_id, execution_date, state
>  )
>  if state == State.FAILED or state == State.SUCCESS:
>  qry = session.query(TI).filter(TI.dag_id == dag_id,
>  TI.task_id == task_id,
>  TI.execution_date == execution_date)
>  ti = qry.first()
>  if not ti:
>  self.log.warning("TaskInstance %s went missing from the database", ti)
>  continue
> TODO: should we fail RUNNING as well, as we do in Backfills?
>  *if ti.state == State.QUEUED:*
>  msg = ("Executor reports task instance %s finished (%s) "
>  "although the task says its %s. Was the task "
>  "killed externally?".format(ti, state, ti.state))
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to