Reputation: 17
I am working with Amazon Redshift and I am encountering an intermittent error in my stored procedure. The error message is:
DETAIL: Serializable isolation violation on table - 101841, transactions forming the cycle are
The error occurs when performing an UPDATE statement on the table incremental_table inside the stored procedure. We are using Serializable isolation level for transaction handling.
I need to simulate this error in a controlled environment to troubleshoot and reproduce the issue. Could anyone guide me on how to simulate this "Serializable isolation violation" error in Amazon Redshift? Specifically, I would like to:
Understand the conditions under which Redshift throws this error.
Know if there is a way to manually trigger such a violation for testing.
Get any insight on best practices for handling such errors.
Thanks Sundar
Upvotes: 0
Views: 24
Reputation: 11082
Sure thing. As far as understanding this error the AWS Redshift pages do a good job - https://docs.aws.amazon.com/redshift/latest/dg/c_serial_isolation.html and https://aws.amazon.com/premiumsupport/knowledge-center/redshift-serializable-isolation/
If you are not familiar with MVCC coherency then a quick read of https://en.wikipedia.org/wiki/Multiversion_concurrency_control might help.
Let me try to simplify this down a bit. It is easy to miss the forest for the trees.
That's it. Redshift doesn't "know" that the changes that the other transaction is making is material to the results this transaction is making. Just that it COULD be material. Since it COULD be material then the serialization hazard exists and one transaction is aborted to prevent the possibility of indeterminant results.
The error occurs when this "A depends on B in one transaction while B depends on A in another" situation occurs AND the second transaction tries to COMMIT its results. Up until that point there is no conflict as the second transaction could ROLLBACK.
Hopefully this is clear, if not ask for clarification.
You can (or at least could some years back) create these circumstances using a workbench with 2 sessions (connections) open.
This should work but I think the Redshift team has been working on reducing the number of these errors so they may have made it more difficult. Let me know.
These conditions can be set up in a bench since we can leave a transaction open in one session while we do things in the other. In a real working database these transactions will open and close quickly and getting the timing to line up is difficult. You can use code to set this up but to reproduce reliably you will need to control the timing of events in 2 sessions.
As for addressing these errors in your ETL solution there are a few things you should do.
I'll just say it again - the best answer is to review your processes that change table contents and order these processes to remove the possibility of conflict. Just because you "resolve" your serialization errors doesn't mean that your database is in a self-consistent state.
Upvotes: 0