OpenTP1 Version 7 Programming Guide

[Contents][Index][Back][Next]

4.2.7 TAM table access facility without table-based lock

TP1/FS/Table Access 05-00 or earlier locks the appropriate individual tables when it adds or deletes records. This facility is referred to as the TAM table access facility with table-based lock. For information about the locking of individual tables, see 4.2.6 Lock for TAM tables.

TP1/FS/Table Access 05-01 or later allows access to TAM table records while locking the appropriate records without locking entire tables. This facility is referred to as the TAM table access facility without table-based lock.

Organization of this subsection
(1) How to use the TAM table access facility without table-based lock
(2) Lock
(3) Notes
(4) Programming interface
(5) Definition interface

(1) How to use the TAM table access facility without table-based lock

To use the TAM table access facility without table-based lock, specify the update type that allows addition and deletion without locking tables in the TAM table access mode. The access mode must be specified in the tamtable command definition clause for the TAM service definition or the tamadd command. For information about the tamtable command definition clause, see the manual OpenTP1 System Definition. For information about the tamadd command, see the manual OpenTP1 Operation.

The same OpenTP1 system can include both TAM tables that are accessed using the TAM table access facility without table-based lock and TAM tables that are accessed using the TAM table access facility with table-based lock.

You do not need to recreate existing TAM files using the tamcre command before using the TAM table access facility without table-based lock.

(2) Lock

(a) Locking and unlocking resources

The dc_tam_open function and record access functions (dc_tam_read, dc_tam_write, and dc_tam_delete) lock resources. Similarly, UAPs written in COBOL and used to access records also lock resources.

Resources that have been locked are unlocked when the TAM table access transaction ends.

(b) The lock setting of the TAM service function used to activate the TAM table access facility without table-based lock versus the actual lock status

The table below indicates the actual lock status, as compared to the lock setting of the TAM service function used to activate the TAM table access facility without table-based lock.

Table 4-10 Actual lock status, as compared to the lock setting of the TAM service function used to activate the TAM table access facility without table-based lock

Value assigned to the TAM service function and flag Table-based lock Record-based lock
dc_tam_open Table-based lock Update lock#1 --
Record-based lock -- --
dc_tam_read Reference No lock -- --
Lock applied -- Reference lock
Updating -- Update lock
dc_tam_rewrite -- Update lock#2
dc_tam_write -- Update lock
dc_tam_delete -- Update lock

Legend:
--: No lock is applied.

#1
A dc_tam_open function in which table-based lock is specified waits to lock the appropriate table if the table is already locked by another transaction's dc_tam_open function in which table-based lock is specified. However it does not wait for the completion of any function that accesses records rather than tables. For further information, see (3) in 4.2.7 TAM table access facility without table-based lock.

#2
The dc_tam_rewrite function does not lock resources, but the resources involved in this function have already been locked by the dc_tam_read function that was issued in update mode.

(c) Lock application processing

The figure below shows processing that is used to lock resources when updating records using the TAM table access facility with table-based lock and the TAM table access facility without table-based lock.

Figure 4-8 Locking resources when updating records

[Figure]

  1. When dc_tam_write is issued, the TAM table access facility with table-based lock locks the table that is accessed for reference and locks the record to be updated. It then updates the record as shown in steps (1) to (3) in Figure 4-8.
  2. When dc_tam_write is issued, the TAM table access facility without table-based lock locks the record to be updated, and then updates the record as shown in steps (4) and (5) in Figure 4-8.

The figure below shows processing that is used to lock resources when adding records using the TAM table access facility with table-based lock and the TAM table access facility without table-based lock.

Figure 4-9 Locking resources when adding records

[Figure]

  1. When dc_tam_write is issued, the TAM table access facility with table-based lock locks the table that is accessed for updating, and then adds a record as shown in steps (1) and (2) in Figure 4-9.
  2. When dc_tam_write is issued, the TAM table access facility without table-based lock locks the record to be updated, and then adds the record as shown in steps (3) and (4) in Figure 4-9.

As explained above, the TAM table access facility with table-based lock and the TAM table access facility without table-based lock are different in the way they lock resources. For this reason, they are also different in the operation they will perform when two or more transactions compete for access to the same TAM table. If another transaction that is adding or deleting a record in the same table exists, the TAM table access facility with table-based lock cannot access the table to update, add, delete or reference the target record (if the table is locked by the function in the other transaction). The TAM table access facility without table-based lock can access the same TAM table if it does not compete with the facility in the other transaction for the record being accessed.

The figure below shows processing that is performed by the TAM table access facility with table-based lock when competition for access to the same record occurs.

Figure 4-10 Processing that is performed by the TAM table access facility with table-based lock when competition for access to the same record occurs

[Figure]

  1. UAP1 is going to add record 1. As shown in steps (1) and (2) in Figure 4-10, it locks the table to be updated, and then adds the record.
  2. UAP2 cannot update record 3 because it cannot lock the table to be referenced, as shown at step (3) in Figure 4-10.
  3. UAP3 cannot add record 5 because it cannot lock the table to be updated, as shown at step (4) in Figure 4-10.
  4. Therefore, UAP2 and UAP3 will wait until UAP1 ends the transaction and unlocks the resource or UAP2 and UAP3 will abort with a DCTAMER_LOCK error.

The figure below shows processing that is performed by the TAM table access facility without table-based lock when competition for access to the same record occurs.

Figure 4-11 Processing that is performed by the TAM table access facility without table-based lock when competition for access to the same record occurs

[Figure]

  1. UAP1 is going to add record 1. As shown in steps (1) and (2) in Figure 4-11, it locks record 1, and then adds the record.
  2. UAP2 locks record 3 to be updated and then updates the record as shown at step (3) in Figure 4-11.
  3. UAP3 locks record 5 to be added, and then adds the record as shown at step (4) in Figure 4-11.
  4. In this way, UAP2 and UAP3 can access the same TAM table before UAP1 begins the transaction because UAP1 does not lock the table.

(3) Notes

Note the following when using the TAM table access facility without table-based lock.

(a) Table-based lock applied by the dc_tam_open function

When the dc_tam_open function is issued with table-based lock specified (DCTAM_TBL_EXCLUSIVE flags is set to), it locks the table. However, it does not lock records that are included in the locked table and which may be accessed by record-access functions (dc_tam_read, dc_tam_write, and dc_tam_delete). This means that, once a dc_tam_open function that locks a table is issued, another dc_tam_open function that locks the same table must wait until the first function ends, but the record-access function does not need to wait.

The figure below shows how the dc_tam_open function locks resources.

Figure 4-12 How the dc_tam_open function locks resources

[Figure]

  1. UAP1 issues a dc_tam_open function in which flags is set to DCTAM_TBL_EXCLUSIVE, in order to lock the table to allow updating as shown at step (1) in Figure 4-12.
  2. UAP2 issues a dc_tam_open function in which table-based lock is specified. However, since it cannot lock the table to be updated as shown at step (2) in Figure 4-12, it will either wait until UAP1's transaction ends or abort with a DCTAMER_LOCK error.
  3. UAP3 issues a dc_tam_open function in which record-based lock is specified (flags is set to DCTAM_REC_EXCLUSIVE). Therefore, the dc_tam_open function will end normally. UAP3 locks record 3 to be updated, and then updates the record as shown at step (3) in Figure 4-12.
(b) Allocating empty records when adding records

When a record is deleted, the record will not become empty until the transaction that has deleted the record is committed. This means that until the transaction is committed, the area reserved for the deleted record will not be allocated to records being added. However, when a record with the same key value as that of the deleted record is to be added within the same transaction that has deleted the record, the area for the deleted record is allocated for the record to be added.

Suppose that, in attempt to add records (even though there is not an equal number of empty records) you delete records with different key values within the same transaction that will add records. When you attempt to add records, you will encounter a DCTAMER_NOAREA error return.

The figure below shows how an attempt to add records causes a DCTAMER_NOAREA error.

Figure 4-13 An example of a DCTAMER_NOAREA error caused by an attempt to add records

[Figure]

  1. Assume that records with key values 1, 2, and 3 are stored in a TAM table that can contain up to 3 records. UAP1 deletes key values 1, 2, and 3 and adds key value 4.
  2. As shown at step (1) in Figure 4-13, the deletion of key value 1 causes record 1 to be put into the deleted state, but does not cause it to become empty.
  3. As shown at step (2) in Figure 4-13, the deletion of key value 2 causes record 2 to be put into the deleted state, but does not cause it to become empty.
  4. As shown at step (3) in Figure 4-13, the deletion of key value 3 causes record 3 to be put into the deleted state, but does not cause it to become empty.
  5. As shown at step (4) in Figure 4-13, an attempt to add key value 4 causes a DCTAMER_NOAREA error return because no empty record exists.

To prevent an attempt to add records from causing a DCTAMER_NOAREA error, you need to obtain a number of empty records equal to the number of records you want to add or wait until the transaction that deletes records is committed, and then add records.

The figure below shows processing that is performed to obtain a number of empty records equal to the number of records to be added.

Figure 4-14 Processing that is performed to obtain a number of empty records equal to the number of records to be added

[Figure]

  1. Increase the maximum number of records that can be stored in the TAM table, to 4. Assume that the TAM table contains records with key values 1, 2, and 3. UAP1 deletes key values 1, 2, and 3 and adds key value 4.
  2. As shown at step (1) in Figure 4-14, the deletion of key value 1 causes record 1 to be put into the deleted state, but does not cause it to become empty.
  3. As shown at step (2) in Figure 4-14, the deletion of key value 2 causes record 2 to be put into the deleted state, but does not cause it to become empty.
  4. As shown at step (3) in Figure 4-14, the deletion of key value 3 causes record 3 to be put into the deleted state, but does not cause it to become empty.
  5. As shown at step (4) in Figure 4-14, the addition of key value 4 allows an empty record 4 to be added.

The figure below shows processing that is performed to add records after the record deletion transaction is committed.

Figure 4-15 Processing that is performed to add records after the record deletion transaction is committed

[Figure]

  1. Assume that records with key values 1, 2, and 3 are stored in a TAM table that can contain up to 3 records. UAP1 deletes key values 1, 2, and 3, commits the transaction, and then adds key value 4 during the next transaction.
  2. As shown at step (1) in Figure 4-15, the deletion of key value 1 causes record 1 to be put into the deleted state, but does not cause it to become empty.
  3. As shown at step (2) in Figure 4-15, the deletion of key value 2 causes record 2 to be put into the deleted state, but does not cause it to become empty.
  4. As shown at step (3) in Figure 4-15, the deletion of key value 3 causes record 3 to be put into the deleted state, but does not cause it to become empty.
  5. As shown at step (4) in Figure 4-15, the commitment of the transaction causes records 1, 2, and 3 being deleted to become empty.
  6. As shown at step (5) in Figure 4-15, the addition of key value 4 allows an empty record 4 to be added.
(c) Access mode change

You cannot use the tamadd command to change a TAM table that uses the TAM table access facility with table-based lock to a TAM table that uses the TAM table access facility without table-based lock or vice versa. If you attempt to use the tamadd command in order to make such a change, the tamadd command ends abnormally.

If you want to switch the TAM table access facility with or without table-based lock to the other facility, change the tamtable command definition clause in the TAM service definition, and then start the OpenTP1 system as usual. Alternatively, start the OpenTP1 system, with no additional definition registered in the TAM service definition, and then use the tamadd command to add a new definition in the TAM service definition.

(d) Deadlock

A deadlock can occur when a TAM table using the TAM table access facility with table-based lock is changed to a TAM table that uses the TAM table access facility without table-based lock. For further information, see (1) (b) in 4.2.11 Notes on adding and deleting TAM records.

(4) Programming interface

Except for the dc_tam_status function and CBLDCTAM('INFO'), TAM tables can be accessed via the same programming interface as for the TAM table access facility with table-based lock.

However, it may be necessary to recompile or relink UAPs. Table 4-11 lists conditions that require program recompilation. Table 4-12 lists conditions that require program relinkage.

Table 4-11 Conditions that require program recompilation

Condition Work required
dc_tam_status used Yes st_acs_type referenced Yes A new constant DCTAM_STS_RECLCK is returned as access mode information. Therefore, you need to modify and recompile your UAPs.
No You do not need to recompile your UAPs.
No You do not need to recompile your UAPs.

Table 4-12 Conditions that require program relinkage

Condition Work required
Libraries used by application programs Archive libraries You need to relink your UAPs
Shared libraries You do not need to relink your UAPs.

The dc_tam_status function returns access mode information to st_acs_type in the DC_TAMSTAT structure. Add DCTAM_STS_RECLCK as a value to be returned to st_acs_type. This value indicates an access mode in which records can be added or deleted without locking the table. A TAM table in this access mode uses the TAM table access facility without table-based lock.

For further information about the dc_tam_status function, its return values, and its usage, see the manual OpenTP1 Programming Reference C Language.

CBLDCTAM('INFO') returns access mode information to data name K. Add VALUE 'L' as a value to be returned to data name K. This value indicates an access mode in which records can be added or deleted without locking the table. A TAM table in this access mode uses the TAM table access facility without table-based lock. For further information about CBLDCTAM('INFO'), its return values, and its usage, see the manual OpenTP1 Programming Reference COBOL Language.

(5) Definition interface

In the tamtable command expression of the TAM service definition, the access type can be set using the -a option. When using the access facility for TAM tables without table-based locking, be sure to specify reclck as the -a option parameter. By setting this parameter to reclck, the "non-locking add/delete update type" access format is shown, which means that the TAM table is using the access facility for TAM tables without table-based locking.

For more detail on how to use other options of the tamtable command expression, see the manual OpenTP1 System Definition.