多个进程正在调用getNextOID存储过程。我们已经对阴阳进行了压力测试,但从未陷入僵局。但是,在生产环境中,我们每天都会看到一些。谁能解释这个简单的代码如何产生死锁?
CREATE Procedure [dbo].[GetNextOID]
@OID int Output as
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
Begin TRAN T1
SELECT @OID = identifier from identifiertable where type = 'ObjectID'
update identifiertable set updatetime = Current_TimeStamp, identifier = identifier + 1 where type = 'ObjectID'
If @@ERROR <> 0 goto OnError
Commit Tran T1
IF @@RowCount > 0
RETURN 0
ELSE
RETURN -1
OnError:
Rollback Tran T1
Return -1