How to handle Concurrency issue?

165 views Asked by At

How to handle Concurrency issue?

I am sending two files.1 file from frontend UI and 1 file from backend.

Suppose File A content is

Hello
I am XYZ

Suppose File B content is

Hello
I am ABC

When i am sending the files at the same time then the both files are getting merged into one like below:

Hello
I am XYZ
Hello
I am ABC

Is there any Solution to handle this Concurrency issue? I have used transaction.

I have the following Script:

BEGIN TRY
BEGIN TRANSACTION 
  SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

  EXEC PROC_FILE_IDENTIFIER @FILE_IDENTIFIER OUT
  
   IF @IS_FL_GN=1
   BEGIN
          EXEC PROC_FLOW_GEN_CREATE_FILE @REGID,@DATAFLOW,....... ------ File Creation from UI
    END
    else
    BEGIN
          EXEC PROC_CREATE_FILE @REGID,@DATAFLOW,.........  ------File Creation from backend
    END
    
    -- Move the created file into IN folder
    
    SET @RESULTTEXT=@T_HEADER + @T_GROUP + @T_FOOTER  
       
  DECLARE @PATH       VARCHAR(2000)  
  DECLARE @TXT        VARCHAR(2000)   
  SET @PATH = 'D:\Symbio_Data_Testing\IN\' + @FILE_IDENTIFIER + '.USR'
  
   COMMIT TRANSACTION 
   END TRY
   
   BEGIN CATCH
      Select ERROR_MESSAGE()
       Select ERROR_LINE()
        IF @@TRANCOUNT > 0
          ROLLBACK TRANSACTION
            Exec PROC_CHECK_LAST_FILE_GENERATED 
   END CATCH

The SP PROC_FILE_IDENTIFIER gives the Filename. This SP contains table: File_number_mst_t which contains file_number which gets updated everytime.

Suppose there is file number 1.
   when user create file,it will take the filename as 1(f1) and update the filenumber to 2.
   Next time when the user will send file,it will take the filename as 2(f2) and update the file to 3.




 Transaction1              
   1
   2              Transaction2   
                      2
                      3
                  

How can i handle the Concurrency isssue when file Comes at the same time.(Conflict occured). Any Suggestions or ideas will be highly appreciated.

0

There are 0 answers