Previous Topic: DC/UCF System DeadlocksNext Topic: Limits on Task Resource Usage


Database Resource Deadlocks

Lock Entities

The system uses three distinct entities to track contention for database resources:

How the System Detects a Deadlock

The mechanism used to detect a deadlocked task is the same for both DC/UCF system resources and database resources.

Deadlock detection is carried out in these major phases:

  1. Identifying stalled tasks—To identify tasks that are stalled, all DCEs in the system are examined. Any DCE found stalled while waiting on a resource is entered into the deadlock detection matrix (DDM). All subsequent processing begins with the DCE address stored in the DDM table. This eliminates scanning all DCEs in the system.
  2. Identifying task dependencies—Next, the dependencies between the stalled tasks are identified. The deadlock detection matrix is updated to reflect these relationships. For each task, a bit in the deadlock detection matrix is enabled for the tasks it is waiting on.
  3. Identifying deadlocks—To determine the tasks involved in a deadlock, each pair of deadlocked tasks is examined. From this examination, one of the tasks is identified as the victim.
  4. Selecting a victim—The task running for the shortest period of time is chosen as the victim of the two tasks as long as:

    The task running for the shortest period of time is chosen as the victim because most likely is has consumed fewer resources than a longer running task. As a result, less duplication of work should be required when the victim is restarted, with these exceptions:

Victim Selection User Exit

The algorithm used to select a victim in a deadlock situation may not be optimal for your installation or applications. A user exit is provided to allow victims to be selected based upon your requirements. The exit is passed the TCE addresses of each pair of deadlocked tasks and may take one of two actions:

Note: For more information about the Victim Selection user exit, see the CA IDMS System Operations Guide.

Detecting Deadlocks

The following figure illustrates how the deadlock detection mechanism detects deadlocks.

Task A is using resource 1.        ┌─────────┐                ┌─────────┐
                                   │         │                │         │
Task B is using resource 2.        │  Task A │                │  Task B │
                                   └────▲────┘                └────▲────┘
A lock is created for                   │                          │
resource 1 and resource 2.              │                          │
                                   ┌────┴────┐                ┌────┴────┐
                                   │   Lock  │                │   Lock  │
Every lock is connected to         │   A-1   │                │   B-2   │
the task that owns                 └────▲────┘                └────▲────┘
the resource.                           │                          │
                                        │                          │
                                   ┌────┴────┐                ┌────┴────┐
                                   │ Resource│                │ Resource│
                                   │    1    │                │    2    │
                                   └─────────┘                └─────────┘
--------------------------------------------------------------------------------

Task A requests resource 2.        ┌─────────┐                ┌─────────┐
                                   │         │                │         │
A lock wait is created to          │  Task A │                │  Task B │
indicate that task A is            └─▲─────┬─┘                └────▲────┘
waiting on resource 2.               │     │                       │
                                     │     │                       │
Task A points to the        ┌────────┴┐  ┌─▼───────┐          ┌────┴────┐
lock wait for resource 2.   │   Lock  │  │Lock wait│          │   Lock  │
The lock wait points to     │   A-1   │  │   A-2   │          │   B-2   │
resource 2 to indicate      └────▲────┘  └────┬────┘          └────▲────┘
the resource it is               │            │                    │
waiting on.                      │            └─────────────────┐  │
                            ┌────┴────┐                       ┌─▼──┴────┐
Task A waits on resource 2. │ Resource│                       │ Resource│
                            │    1    │                       │    2    │
                            └─────────┘                       └─────────┘
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Task B requests resource 1.         ┌─────────┐                ┌─────────┐
                                    │         │                │         │
A lock wait is created to           │  Task A │                │  Task B │
indicate that task B                └─▲─────┬─┘                └─▲─────┬─┘
is waiting on resource 1.             │     │                    │     │
                                      │     │                    │     │
Task B waits.                ┌────────┴┐  ┌─▼───────┐    ┌───────┴─┐ ┌─▼───────┐
                             │   Lock  │  │Lock wait│    │   Lock  │ │Lock wait│
When the deadlock detector   │   A-1   │  │   A-2   │    │   B-2   │ │  B-1    │
is activated, it finds       └────▲────┘  └────┬────┘    └────▲────┘ └────┬────┘
both task A and task B            │            │              │           │
waiting on resource 2             │            │              │           │
and may then check for       ┌────┴────┐  ┌────▼────┐         │           │
deadlocks.                   │ Resource│  │ Resource│         │           │
                             │    1    │  │    2    ├─────────┘           │
The lock wait-to-resource    └────▲────┘  └─────────┘                     │
chain shows the resource          │                                       │
that the task is waiting on.      └───────────────────────────────────────┘
The resource-to-lock-to task
chain shows which tasks own a given
resource.  Using this information,
the deadlock detector can determine
tasks that are deadlocked.
--------------------------------------------------------------------------------

Deadlock Detection Interval

You can control the frequency with which the deadlock detection mechanism searches for deadlocked tasks using the DEADLOCK DETECTION parameter of the SYSTEM statement.

The DEADLOCK DETECTION parameter allows you to specify the amount of time that elapses before the deadlock detection mechanism searches for deadlocked tasks.

You can use the DCMT VARY DEADLOCK command at runtime to override the system generation specification.

More Information: