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

Transaction rollbacks #954

Open
SvdSinner opened this issue Jan 31, 2023 · 2 comments
Open

Transaction rollbacks #954

SvdSinner opened this issue Jan 31, 2023 · 2 comments

Comments

@SvdSinner
Copy link
Contributor

There are two issues with how transactions rollback currently in Sql Server (might be relevant to other databases, don't know):

  1. The rollback command uses the same timeout as normal commands. However, for a large synchronization, the transaction might include dozens, hundreds or thousands of sql commands. Rolling a large transaction back takes significantly more time to complete that any of the individual sql commands it is rolling back. This means that rolling back large transactions will almost always result in a connection timeout error. Rollback commands should always be executed with a CommandTimeout of 0 (no limit).
  2. When the connection timeouts occur, all knowledge of the original error/exception that triggered the roll back is lost, and nothing meaningful is able to be logged. Any SqlExceptions thrown while rolling back (timeout or otherwise) need to include information on why the rollback that failed was occurring. This could be done as inner exceptions or by a custom exception that includes the additional information. Without this, long syncs fail with no indication of what went wrong, just that some unknown thing triggered rollback and that the rollback caused a timeout error.
@Mimetis
Copy link
Owner

Mimetis commented Jan 31, 2023

Did you tried and look at the last version? (v0.9.8) that has been merged yesterday in main?

Timeout & Deadlocks are defined as transient errors.
That means that the transaction will be run again each time a transient error is happenning.

If you want to reduce the size of transactions, you can opt in for options.TransactionMode = TransactionMode.PerBatch; that will reduce the size of the transactions.

Regarding the errors, I think with the last version published, the error is raised correctly, but not sure honestly.
Do you have an example ?

@SvdSinner
Copy link
Contributor Author

I'll sync my fork with the newest and re-test. The way to replicate is to sync a table with a foreign key reference to a table that isn't synced and thereby causing "The MERGE statement conflicted with the FOREIGN KEY constraint "FK_BlahBlahBlah". The conflict occurred in database "someDb", table "dbo.thisTable", column 'thisColumn'."

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

No branches or pull requests

2 participants