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

Change query retry handling #308

Merged
merged 1 commit into from Nov 7, 2021
Merged

Conversation

nponiros
Copy link
Contributor

@nponiros nponiros commented Nov 6, 2021

Move transaction retry handling to the transaction and nestedTransaction
methods and change it so that the handler function is called again
instead of just replaying the queries that are part of the transaction.
Fixes #163.

Add a second parameter to the transaction method to allow users to
define a retry limit per transaction. If a retry limit is given for a
transaction then the global defined retry limit for transactions is
ignored.

Change executeQuery so that it retries individual queries that failed
with a transaction rollback error. Only queries that are not part of a
transaction are retried. The number of times a query is retried is
specified by the global queryRetryLimit configuration. Fixes #176.

The above change also fixes #196 since the transactionQueries array no
longer exists.

Move transaction retry handling to the transaction and nestedTransaction
methods and change it so that the handler function is called again
instead of just replaying the queries that are part of the transaction.
Fixes gajus#163.

Add a second parameter to the transaction method to allow users to
define a retry limit per transaction. If a retry limit is given for a
transaction then the global defined retry limit for transactions is
ignored.

Change executeQuery so that it retries individual queries that failed
with a transaction rollback error. Only queries that are not part of a
transaction are retried. The number of times a query is retried is
specified by the global queryRetryLimit configuration. Fixes gajus#176.

The above change also fixes gajus#196 since the transactionQueries array no
longer exists.
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 87.903% when pulling 93d0d19 on nponiros:fix_transaction_retry into 95db15d on gajus:master.

@nponiros
Copy link
Contributor Author

nponiros commented Nov 6, 2021

A few things to note:

The blocking/unblocking behaviour for transactions is now different than before. Now we unblock before retrying a transaction. Before the unblock took place after the retry. I don't fully understand the reason for the blocking/unblocking so I'm not sure if this causes any issues.

With the way I implemented the retry mechanism for a single query and transaction the user will see the transaction rollback error if the query/transaction fails despite the retries. Before the user would get an UnexpectedState error. I assumed that this was a bug. Also before the queries were retried until the limit was reached and the result of the last retry was return. I also assumed that this was a bug and now the retry function returns as soon as a query succeeds.

The way I implemented the transaction retry a nested transaction is retried until it reaches its limit and in case the transaction rollback error persist the parent transaction is retried until its limit. I don't know if this is such a good idea. Perhaps it would be better to not retry nested transactions and let the parent transaction do the retry.

@gajus gajus merged commit f973ced into gajus:master Nov 7, 2021
@gajus
Copy link
Owner

gajus commented Nov 7, 2021

@nponiros This is really awesome contribution. Thank you for taking time to put it together. I am releasing it as a breaking change.

@gajus
Copy link
Owner

gajus commented Nov 7, 2021

🎉 This PR is included in version 25.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants