Locks and the Locking Systems

A number of sets of locks are used by the system, or are available to users, to protect the database against corruption.

Read/update Locks (Group Locks)

These are set for very short periods by system software when an item is being updated. They are set on a group within a file and their purpose is to prevent corruption of data within the group due to attempted concurrent update of its contents.

Item Locks

These can be set by DataBasic programs, Procs and the editors when an item may be updated and should therefore not be accessed by another updating process.

Reality's item locks are advisory; this means that locking an item does not prevent other processes writing to it, but rather indicates that the item is in use. If you decide to use locks, they must be used by all programs that update the items concerned.

Do not take a lock unnecessarily; other processes may require access to the item.

See the DataBasic, Proc, EDITOR and Screen Editor sections for more details of the use of item locks.

Item Deadlock Detection

An Item Deadlock, also known as a Deadly Embrace, occurs when two processes are competing for items locked by the other. For example, suppose Process A asserts a lock on Item B and then attempts to assert a lock on Item A. Simultaneously, Process B asserts a lock on Item A and then attempts to assert a lock on Item B. Process A and Process B each are asserting an item lock on an item the other process also requires. The result is a stalemate in which neither process is able to gain access to all the items it requires.

Reality provides the facility to detect an item deadlock. After detecting a deadlock it waits for a configurable length of time, then sends a warning message to both the terminal screen and the daemon log informing the user that a deadlock is in progress and giving the names of the account and file involved. The daemon log output is of the form:

Feb 12 15:56:35#27043 port402 WARNING: Item deadlock:
ACC1:, AFILE (DATA) 'ITEMA' held by 401
Feb 12 15:56:35 #27042 port401 WARNING: Item deadlock:
ACC1:, AFILE (DATA) 'ITEMB' held by 402

Item deadlock detection is configured by the database configuration parameter ItemLockTimeOut.

Execution Locks

These are shared by DataBasic and Proc to allow temporary exclusion of other processes that try to set the same lock. This set of 256 numbered locks is available as an alternative to item-locks.

See the DataBasic and Proc sections for more details of the use of execution locks.

Monitoring and Maintaining Locks

The following TCL commands are provided to monitor and maintain these locks:

CLEAR-BASIC-LOCKS
Clears the execution lock table.

CLEAR-ITEM-LOCKS
Clears one or more item locks, depending on the options specified.

LIST-EXECUTION-LOCKS
Lists execution locks currently set.

LIST-GROUP-LOCKS
Lists read/update locks currently set.

LIST-ITEM-LOCKSLists item locks currently set.

LIST-LOCKSLists read/update, item and execution locks currently set.

MAKE-SPECIAL ILOCKS
Creates a special view of the item lock table, showing locks that are in contention

SHOW-ITEM-LOCKS
Lists item locks and processes waiting to set them.

Note

Retrieval and update lock codes set on files are a security feature, and are not related to the above, which are temporary locks set to prevent data corruption.