gtpa2m1x | Application Programming |
TPFCS provides three levels of concurrency control:
The first type of concurrency uses a nonlocking cursor to read elements in a collection without creating any type of interlock on the target collection. For this reason, it is considered a dirty-read cursor. A subsequent request to access the collection by a locking cursor will be successful and an exclusive lock will be placed on the collection by the new cursor. However, the nonlocking cursor will still be able to read elements in the collection.
To provide additional database integrity for those collections that allow element updating, an update sequence counter is stored in each element in a given collection and optimistic concurrency is enforced on the element during update processing. Optimistic concurrency allows you to read a collection and update it without exclusive access to the collection. When an element is to be updated, it must first be read from the collection with the returned sequence counter saved. The functions used to update elements in a collection require that the application provide the expected value for this counter. TPFCS increments the counter whenever a collection element is updated. If the collection is updated by some other user, your current update request will fail because the value passed by the application as input to the function does not match the update sequence counter embedded in the element. The collection must be retrieved again for a successful update to take place.
Pessimistic concurrency uses a locking cursor to create an exclusive lock on the collection. No other locking cursor in the same ECB is able to create a lock on the collection and the attempt is rejected with an error return code. If another ECB attempts to access the collection using a locking cursor, the ECB is forced to wait until the first ECB either deletes its cursor or exits. This is called a dirty-read cursor because there is no guarantee that two back-to-back reads can read the same element. However, the nonlocking cursors are still able to read the collection.
TPFCS provides dirty-reader protection by using the FILNC macro to file records in a sequence to make sure that an updated or new record is on the DASD surface before filing the record that points to the updated record. This is done to ensure that another user who is attempting to read the collection using a nonlocking cursor will be able to follow a whole chain. If the updates were filed in the wrong order, it might be possible for the reader to follow a chain with holes in it or the chain could point to records that were not even part of the collection; for example:
Record A contains a pointer to record B and now TPFCS has to insert record C between record A and B. If TPFCS filed record A with the new pointer to record C before filing record C, it would then be possible for a reader to read record A and then attempt to read record C before it had been filed. To prevent this, TPFCS dirty-reader protection will make sure that record C is filed first by using the FILNC macro, and then record A will be filed.
For more information about the FILNC macro, see TPF General Macros.