Handling of Deadlocks | Transaction Processing | Teradata Vantage - Deadlock - Analytics Database - Teradata Vantage

SQL Request and Transaction Processing

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-05-02
dita:mapPath
zfm1628111633230.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
evd1472255317510
lifecycle
latest
Product Category
Teradata Vantage™

One problem that can occur with two-phase locking (see Two-Phased Locking Defined) is that two requests lock a different database resource that the other request needs to continue processing its transaction. For example, the first transaction may lock table row B and the second transaction may lock table row A. If the first transaction now needs to lock table row A to continue, and the second transaction needs to lock table row B to continue, the transactions have created a deadlock. Each transaction waits for the other transaction to release a locked resource before continuing.

This situation is different from the case where individual requests are waiting for a lock to be released. Database lock requests do not time out, so a request waits in the lock queue until being granted the necessary lock, unless you specify the NO WAIT option in a LOCKING clause that modifies the request. If you do that, the request ends immediately and rolls back any updates made by the containing transaction.

For example, a local deadlock occurs when two transactions that concurrently hold READ locks for the same data on the same AMP attempt to enter an update request.

Also, because requests are processing in parallel on multiple AMPs, a global deadlock can occur.

For example, suppose transaction_a places a WRITE lock on object_x (for example the rows sharing the same hash value of a table) on AMP1, and transaction_b places a WRITE lock on object_y on AMP2. Both of these lock requests are granted.

Now, if transaction_b attempts to place a write lock on object_x on AMP1, transaction_b is blocked. Similarly, if transaction_a places a WRITE lock on object_y on AMP2, transaction_a is also blocked. Neither transaction can complete.

If the DBQL Lock Logger is enabled, deadlocks are logged in the XML lock log table, DBQLXMLLockTbl, and main log table, DBQLogTbl. You can use the Viewpoint DBQL Lock Logger portlet to report deadlocks. See Teradata® Viewpoint User Guide, B035-2206.

Deadlocks

Each request in a transaction places its own locks while running and continues to hold the locks until the transaction either commits or rolls back.

This can result in deadlocks when multiple concurrent accesses against the same database objects occur. The application-level solution to this potential problem is to apply all the explicit database- and table-level locks you need in a single request at the beginning of a transaction.

Deadlock Detection

Vantage supports deadlock detection and handling at the following levels:

Level Description
Local Contention between threads within an AMP, localized within one vproc.

The AMP-local deadlock detection software checks for deadlocks at a fixed 30-second interval.

Global Contention between threads over two or more different AMPs.

Global deadlock detection runs at a user-defined period set by the DBS Control utility using the DeadLockTimeOut parameter. The global deadlock detection software runs by default with a period of four minutes, but you may want to specify a shorter interval.

Use the Viewpoint Lock Logger portlet to detect blocked transactions and global deadlocks. For information about how to use this utility portlet, see Teradata® Viewpoint User Guide, B035-2206.

You can also use the XMLPLAN output from DBQL logging to investigate deadlock situations. For more information, see Teradata Vantage™ - Database Administration, B035-1093.

When the system detects a deadlock, it ends the transaction and rolls back the most recently initiated of the two transactions.

Detecting and Handling Deadlock for Client Utility Locks

Because most client utilities use database locking, the global deadlock detector knows when client utilities become trapped in a deadlock. (The global deadlock detector does not detect HUT deadlocks.) To resolve the deadlock, the Lock Manager aborts the deadlocked transaction, rolls back its updates, and returns a retryable 2631 error to the requesting application or utility.

The following table summarizes what happens to a transaction submitted from a client utility or application when a retryable 2631 error occurs, and then provides a basic solution for the problem.

Client Utility Or Application Solution
BTEQ with .SET RETRY active Even though the entire transaction has been rolled back, BTEQ retries only the failed request and any subsequent requests in the transaction, not the entire transaction.

If this occurs, the updates made by requests in the transaction prior to the failed request are lost, as is the contextual information indicating that a transaction is in progress.

Other Code the application to do the following:
  1. Check for error code 2631.
  2. If error code 2631 is detected, resubmit the entire ended transaction.

For more information about retryable error 2631, see Teradata Vantage™ - Database Messages, B035-1096.