Tuesday, January 22, 2008

Dynamics Axapta and OCC (Optimistic Concurreny Control)

Definition

Optimistic Concurrency Control (OCC) helps increase database performance. Pessimistic Concurrency Control locks records as soon as they are fetched from the database for an update. However, Optimistic Concurrency only locks records from the time when the actual update is performed.

Pessimistic concurrency was the only option available in Microsoft Axapta 3.0 (now a part of Microsoft Dynamics). You can now choose which concurrency model to use—optimistic or pessimistic.

Advantages

  • Fewer resources are used to hold the locks during the update process.
  • Records are locked for a shorter length of time.
  • Records remain available for other processes to update if they have been selected from the database but haven't yet been updated.

Disadvantages

The disadvantage of using OCC is that 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.

How to catch Update Conflicts

Update Conflicts can be handled by catching the UpdateConflict and UpdateConflictNotRecovered events.

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.

e.g. AOT\Classes\PurchTableType\delete

Update Conflicts and recversion field

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. The default value of recVersion is 1. This is changed to a random value when a record is updated.

Links
http://msdn2.microsoft.com/en-us/library/ms378709.aspx
http://msdn2.microsoft.com/en-us/library/bb190073.aspx

No comments:

Post a Comment