Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround occasional deadlocks with MSSQL #19856

Merged

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Nov 27, 2021

We already have a mechanism to retry operations that could result
in temporary deadlocks - this have been helpful with handling MySQL
deadlocks - however similar problems occur occasionally in MSSQL and
there we get a DBAPIError rather than OperationalError:

`sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('40001', '[40001]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction
(Process ID 55) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
(1205) (SQLExecDirectW)');

This PR adds DBAPIError to the list of errors that are handled
by run_with_db_retries to mitigate such occasional deadlocks.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

We already have a mechanism to retry operations that could result
in temporary deadlocks - this have been helpful with handling MySQL
deadlocks - however similar problems occur occasionally in MSSQL and
there we get a DBAPIError rather than OperationalError:

`sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('40001', '[40001]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction
(Process ID 55) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
(1205) (SQLExecDirectW)');

This PR adds DBAPIError to the list of errors that are handled
by `run_with_db_retries` to mitigate such occasional deadlocks.
@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Nov 27, 2021
@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@potiuk potiuk merged commit e87856d into apache:main Nov 27, 2021
@potiuk potiuk deleted the workaround-occasional-deadlocks-with-mssql branch November 27, 2021 16:51
dillonjohnson pushed a commit to dillonjohnson/airflow that referenced this pull request Dec 1, 2021
We already have a mechanism to retry operations that could result
in temporary deadlocks - this have been helpful with handling MySQL
deadlocks - however similar problems occur occasionally in MSSQL and
there we get a DBAPIError rather than OperationalError:

`sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('40001', '[40001]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction
(Process ID 55) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
(1205) (SQLExecDirectW)');

This PR adds DBAPIError to the list of errors that are handled
by `run_with_db_retries` to mitigate such occasional deadlocks.
@jedcunningham jedcunningham added this to the Airflow 2.2.3 milestone Dec 7, 2021
jedcunningham pushed a commit that referenced this pull request Dec 7, 2021
We already have a mechanism to retry operations that could result
in temporary deadlocks - this have been helpful with handling MySQL
deadlocks - however similar problems occur occasionally in MSSQL and
there we get a DBAPIError rather than OperationalError:

`sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('40001', '[40001]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction
(Process ID 55) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
(1205) (SQLExecDirectW)');

This PR adds DBAPIError to the list of errors that are handled
by `run_with_db_retries` to mitigate such occasional deadlocks.

(cherry picked from commit e87856d)
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Dec 8, 2021
@potiuk potiuk restored the workaround-occasional-deadlocks-with-mssql branch April 26, 2022 20:54
@potiuk potiuk deleted the workaround-occasional-deadlocks-with-mssql branch July 29, 2022 20:08
jmaicher added a commit to jmaicher/airflow that referenced this pull request Jul 19, 2024
In apache#19856, we added `DBAPIError` besides `OperationalError` to the retry exception types, but did not change the `retry_db_transaction` decorator to rollback transaction after failures and before a retry.

In certain cases (see apache#40882), this is needed as otherwise all retries will fail when the current session/transaction was "poisened" by the initial error.
potiuk pushed a commit that referenced this pull request Jul 19, 2024
In #19856, we added `DBAPIError` besides `OperationalError` to the retry exception types, but did not change the `retry_db_transaction` decorator to rollback transaction after failures and before a retry.

In certain cases (see #40882), this is needed as otherwise all retries will fail when the current session/transaction was "poisened" by the initial error.
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
In apache#19856, we added `DBAPIError` besides `OperationalError` to the retry exception types, but did not change the `retry_db_transaction` decorator to rollback transaction after failures and before a retry.

In certain cases (see apache#40882), this is needed as otherwise all retries will fail when the current session/transaction was "poisened" by the initial error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants