Previous Topic: Sharing Run Units Between ProgramsNext Topic: Area Locks


Record Locks

In general, record locks prevent concurrent retrieval and update by separate run units operating under the same central version. This statement does not apply when:

Exclusive Lock

An exclusive lock indicates that no other run unit can access the designated record occurrence in any way. Only one run unit at a time can place an exclusive lock on a record occurrence. A run unit can place an exclusive lock on a record occurrence only if that occurrence has not been assigned any locks (shared or exclusive) by another run unit. A run unit that tries to place an exclusive lock on an occurrence that already has been locked must wait until all other locks on the occurrence are released.

Shared Lock

A shared lock indicates that other run units can retrieve the designated record occurrence but cannot update it. Any number of run units can place a shared lock on a record occurrence. A run unit that tries to place a shared lock on an occurrence for which an exclusive lock is already held must wait until the exclusive lock is released.

Notify Lock

A notify lock is used in the online environment to monitor database access to a specified record occurrence.

For more information on notify locks, see Maintaining Data Integrity in the Online Environment.

Implicit and Explicit Locks

Record locks can be set implicitly by the central version or you can set them explicitly by coding the DML KEEP function in the program.

Implicit Locks

Implicit locks are maintained automatically by the central version for every run unit accessing the database in shared update usage mode. The DBA can also specify that implicit locks be maintained for run units accessing the database in shared retrieval or protected update usage mode.

For further details about usage modes, see Area Usage Modes.

Types of Implicit Lock

Implicit locks can be shared or exclusive, as follows:

For more information on the implicit locks acquired by the DBMS, see Implicit Record Locks.

Explicit Locks

Explicit locks, which you set in your program, maintain record locks that would otherwise be released after a change in currency. The KEEP statement and the KEEP clause of the FIND/OBTAIN statement are used to set explicit shared and exclusive locks.

For more information about setting explicit locks, see Locking Records.

Managing Record Locks

Accumulating a large number of implicit or explicit record locks during a database transaction hinders system performance. You can maintain efficient database transactions by regularly issuing the DML COMMIT statement (described later in this chapter).

Additionally, certain conditions that result from the use of record locks ca CAuse abnormal termination of run units executing under the central version:

Deadlock Example

The following sequence of figures shows a typical deadlock situation:

┌────────────────────────┬────────────────────────┐
│                        │                        │
│       Locks held       │       Wait state       │
├────────────────────────┼────────────────────────┤
│                                                 │
│                        │                        │
│   A - Bower                                     │
│   B - Bank             │                        │
│                                                 │
│                        │                        │
│                                                 │
│                        │                        │
│                                                 │
├────────────────────────┴────────────────────────┤
│                                                 │
│  ┌──────────────────┐     ┌──────────────────┐  │
│  │     Run unit     │     │    Run unit      │  │
│  │        A         │     │       B          │  │
│  │                  │     │                  │  │
│  │  ┌─────────────┐ │     │  ┌────────────┐  │  │
│  │  │  Executing  │ │     │  │  Executing │  │  │
│  │  └─────────────┘ │     │  └────────────┘  │  │
│  └──────────────────┘     └──────────────────┘  │
│                                                 │
└─────────────────────────────────────────────────┘
┌────────────────────────┬────────────────────────┐
│                        │                        │
│       Locks held       │       Wait state       │
├────────────────────────┼────────────────────────┤
│                                                 │
│                        │                        │
│   A - Bower                A - Bank             │
│   B - Bank             │                        │
│                                                 │
│                        │                        │
│                                                 │
│                        │                        │
│                                                 │
├────────────────────────┴────────────────────────┤
│                                                 │
│  ┌──────────────────┐     ┌──────────────────┐  │
│  │     Run Unit     │     │    Run Unit      │  │
│  │        A         │     │       B          │  │
│  │                  │     │                  │  │
│  │  ┌─────────────┐ │     │  ┌────────────┐  │  │
│  │  │  Waiting    │ │     │  │  Executing │  │  │
│  │  └─────────────┘ │     │  └────────────┘  │  │
│  └──────────────────┘     └──────────────────┘  │
│                                                 │
└─────────────────────────────────────────────────┘
┌────────────────────────┬────────────────────────┐
│                        │                        │
│       Locks held       │       Wait state       │
├────────────────────────┼────────────────────────┤
│                                                 │
│                        │                        │
│   A - Bower                   A - Bank          │
│   B - Bank             │      B - Bower         │
│                                                 │
│                        │                        │
│                                                 │
│                        │                        │
│                                                 │
├────────────────────────┴────────────────────────┤
│                                                 │
│                                                 │
│  ┌──────────────────┐     ┌──────────────────┐  │
│  │     Run Unit     │     │    Run Unit      │  │
│  │        A         │     │       B          │  │
│  │                  │     │                  │  │
│  │  ┌─────────────┐ │     │  ┌─────────────┐ │  │
│  │  │   Waiting   │ │     │  │   Waiting   │ │  │
│  │  └─────────────┘ │     │  └─────────────┘ │  │
│  │                  │     │                  │  │
│  └──────────────────┘     └──────────────────┘  │
└─────────────────────────────────────────────────┘

For more information about deadlock detection and processing, see the CA IDMS Database Administration Guide.