Sep 24, 2014

RecVersion(System Field in Table) - On Updation


RecVersion is used for optimistic concurrency control (OCC) and is used by the AOS.    
      
First let us know about Concurrency Controls,
-  Optimistic Concurrency Control (OCC)   
-  Pessimistic Concurrency Control (PCC)
 
        Optimistic Concurrency Control (OCC) helps in increase of database performance at the time of record updation. Pessimistic Concurrency Control locks records as soon as they are fetched from the database for an update, where OC only locks records from the time when the actual update is performed.
 
OCC - Advantages and Disadvantages 
  • Records are locked for a shorter length of time.
  • Records will remain available for other processes to update if they have been selected from the database
  • The update can fail if another process updates the same record. If the update fails, it must be retried. This can  lead to a reduction in database performance.
  Update Conflicts can be handled by catching the UpdateConflict and UpdateConflictNotRecoveredevents.

This pattern is used across AX API's for retrying the update conflicts and if it exceeds the maximum retry count then UpdateConflictNotRecovered exception is thrown.
 
RecVersion use on updation :- 

      Update conflicts are detected by the kernel. It checks the value of the recVersion system field on the table at the time the record is selected for update. This value is matched to the value of the field when the record is subsequently updated.

" When the update is executed, the system checks if the recVersion of the record in the database is equal to the recVersion on the moment the records was selected. If that was the case. The update succeed "
Note : The default value of recVersion is 1. This will changed to a random value(Int32) when a record is updated.