TakawaAkirayo opened a new pull request, #41429:
URL: https://github.com/apache/airflow/pull/41429
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
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/
-->
The scheduler job raise exception on database dead lock and exist.
```
Traceback (most recent call last):
File
"/usr/local/lib/python3.8/dist-packages/airflow/jobs/scheduler_job_runner.py",
line 845, in _execute
self._run_scheduler_loop()
File
"/usr/local/lib/python3.8/dist-packages/airflow/jobs/scheduler_job_runner.py",
line 991, in _run_scheduler_loop
next_event = timers.run(blocking=False)
File "/usr/lib/python3.8/sched.py", line 151, in run
action(*argument, **kwargs)
File
"/usr/local/lib/python3.8/dist-packages/airflow/utils/event_scheduler.py", line
37, in repeat
action(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/airflow/utils/session.py",
line 77, in wrapper
return func(*args, session=session, **kwargs)
File
"/usr/local/lib/python3.8/dist-packages/airflow/jobs/scheduler_job_runner.py",
line 1680, in check_trigger_timeouts
num_timed_out_tasks = session.execute(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/session.py",
line 1717, in execute
result = conn._execute_20(statement, params or {}, execution_options)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py",
line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/sql/elements.py",
line 334, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py",
line 1577, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py",
line 1953, in _execute_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py",
line 2134, in _handle_dbapi_exception
util.raise_(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/default.py", line
736, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line
179, in execute
res = self._query(mogrified_query)
File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line
330, in _query
db.query(q)
File "/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py", line
255, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1213, 'Deadlock
found when trying to get lock; try restarting transaction')
[SQL: UPDATE task_instance SET state=%s, updated_at=%s, trigger_id=%s,
next_method=%s, next_kwargs=%s WHERE task_instance.state = %s AND
task_instance.trigger_timeout < %s]
[parameters: (<TaskInstanceState.SCHEDULED: 'scheduled'>,
datetime.datetime(2024, 8, 2, 13, 14, 22, 215659), None, '__fail__', '{"__var":
{"error": "Trigger/execution timeout"}, "__type": "dict"}',
<TaskInstanceState.DEFERRED: 'deferred'>, datetime.datetime(2024, 8, 2, 13, 14,
22, 202306, tzinfo=Timezone('UTC')))]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
[[34m2024-08-02T06:14:22.258-0700[0m]
{[34mkubernetes_executor.py:[0m706} INFO[0m - Shutting down Kubernetes
executor[0m
```
This should occur when the scheduler and trigger compete for a row lock,
based on MySQL database query log analysis. Since the trigger already includes
a retry mechanism on update(Trigger.clean_unused), we should add a retry
mechanism here as well.
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.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]