How can I force a Snapshot Isolation failure of 3960

Go To StackoverFlow.com

3

Story

I have a SPROC using Snapshot Isolation to perform several inserts via MERGE. This SPROC is called with very high load and often in parallel so it occasionally throws an Error 3960- which indicates the snapshot rolled back because of change conflicts. This is expected because of the high concurrency.

Problem

I've implemented a "retry" queue to perform this work again later on, but I am having difficulty reproducing the error to verify my checks are accurate.

Question

How can I reproduce a snapshot failure (3960, specifically) to verify my retry logic is working?

Already Tried

  • RAISEERROR doesn't work because it doesn't allow me to raise existing errors, only user defined ones
  • I've tried re-inserted the same record, but this doesn't throw the same failure since it's not two different transactions "racing" another
2012-04-04 19:47
by Jordan
just go with your code if you have tested the various parts independently of the actual error catch. if your new code fails and misses the error, it won't be any worse then it is when it is failing now - KM. 2012-04-10 17:26


1

Open two connections, start a snapshot transaction on both, on connection 1 update a record, on the connection 2 update the same record (in background because it will block), then on connection 1 commit

Or treat a user error as a 3960 ...

2012-07-14 09:21
by Jack


0

Why not just do this:

RAISERROR(3960, {sev}, {state})

Replacing {sev} and {state} with the actual values that you see when the error occurs in production?

(Nope, as Martin pointed out, that doesn't work.)


If not that then I would suggest trying to run your test query multiple times simultaneously. I have done this myself to simulate other concurrency errors. It should be doable as long as the test query is not too fast (a couple of seconds at least).

2012-04-10 17:01
by RBarryYoung
RAISERROR can't be used to raise system error numbers - Martin Smith 2012-04-10 19:18
Huh, right you are. Guess I never tried it before... Anyway, the other method should work (if the test query is not too fast). That I have done before - RBarryYoung 2012-04-10 19:21
Thanks for the responses! I did spend time trying to re-create the race condition without any luck. Eventually the team decided the code was supported with enough logging so it was approved to deploy live - Jordan 2012-04-11 20:01
Ads