In a high-volume test environment, we are getting sporadic instances of this error: The current transaction failed to commit due to a serializable validation failure.I understand WHAT causes this to occur, but I can't see HOW it's happening given the actual DDL involved. The procedure that is throwing this error inserts a single row to a memory-optimized table using the passed parameters as values. I don't see how a phantom row is being inserted in the range when there is no range being read. I'm posting below the heavily redacted-and-reduced DDL for the table and procedure. I have removed most of the columns and all of the non-clustered indexes (I'm not sure if they could possibly be involved, but please correct me if non-clustered indexes can cause this issue). There are no foreign keys and no constraints besides the primary key.I cannot reproduce this issue outside of a high-volume environment. There are other procedures that insert/update/select this table, is that relevant? This procedure, however, is the one that is failing. It's called by itself and is the only thing in its own transaction.I would appreciate any clarifications or troubleshooting hints. I'm not sure what to look for.[code="sql"]CREATE TABLE [dbo].[test_table]( [first_key] [varchar](4) COLLATE Latin1_General_100_BIN2 NOT NULL, [second_key] [varchar](30) COLLATE Latin1_General_100_BIN2 NOT NULL, [numerous_other_fields] [varchar](15) COLLATE Latin1_General_100_BIN2 NULL,CONSTRAINT [test_table_pk] PRIMARY KEY NONCLUSTERED ( [first_key] ASC, [second_key] ASC))WITH ( MEMORY_OPTIMIZED = ON , DURABILITY = SCHEMA_AND_DATA )GOCREATE PROCEDURE [dbo].[the_problem_procedure]( @first_key CHAR(4) , @second_key VARCHAR(30) , @numerous_other_fields VARCHAR(15) ,@return_code INT OUTPUT ,@error_message NVARCHAR(4000) OUTPUT)WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNERAS BEGIN ATOMIC WITH(TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english', DELAYED_DURABILITY = ON) DECLARE @process_name VARCHAR(35) DECLARE @err_nbr INT DECLARE @err_msg NVARCHAR(4000) SET @return_code = 0 SET @error_message = 'SUCCESS' BEGIN TRYINSERT INTO [dbo].[test_table] ( [first_key] ,[second_key] ,[numerous_other_fields] ) VALUES ( @first_key ,@second_key ,@numerous_other_fields ); END TRY BEGIN CATCH SELECT @err_nbr = ERROR_NUMBER(), @err_msg = ERROR_MESSAGE() SET @error_message = 'FAILED Error Code: '+CONVERT(VARCHAR,@err_nbr) +', Error Message: '+ @err_msg SET @return_code = -1; THROW; END CATCH END[/code]
↧