Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Informix Dynamic Server 11.50 Fundamentals Exam 555 certification preparation, Part 6: Data concurrency

Joo Guan Yap (yapjg@sg.ibm.com), Advanced Support Engineer, IBM
Joo Guan graduated from Nanyang University of Singapore with a Bachelor of Applied Science (Computer engineering) Degree in 1996 and was involved in various IT development projects. He joined IBM Informix support in 2001 and is now involved in Advanced Support work.

Summary:  This tutorial is the sixth in a series of nine tutorials designed to help you become familiar with all the different aspects of IBM® Informix® Dynamic Server (IDS) and help you get ready for the IDS Fundamentals Certification exam. In this part, which corresponds with Part 6 of the exam, gain an understanding of the data concurrency mechanisms in IDS.

View more content in this series

Date:  13 Aug 2009
Level:  Intermediate PDF:  A4 and Letter (65 KB | 25 pages)Get Adobe® Reader®

Activity:  12548 views
Comments:  

Deadlocks

A deadlock occurs when two sessions are holding onto the lock that each other needs. The result is that they will wait indefinitely for each other, but this situation is detected and prevented from happening by the database server. For example:

T1: Read row A and place a lock on it.
T2: Read row B and place a lock on it.
T1: Request a lock on row B.
T2: Request a lock on row A.

IDS maintains an internal lock table. To prevent a deadlock, it checks the internal lock table to see whether a deadlock can occur before a session can wait for a lock. This is what happens:

T1: Set lock mode to wait.
T2: Set lock mode to wait.
T1: Read row A and place a lock on it.
T2: Read row B and place a lock on it.
T1: Request a lock on row B; has to wait for T2 to release the lock on row B.
T2: Request a lock on row A, but is rejected because deadlock can occur if it has to wait for the lock.

From the internal lock table, IDS detects that:

  • T1 is holding to the lock on row A
  • T2 is holding to the lock on row B
  • T1 is waiting for the lock on row B that T2 is holding

A deadlock will occur if T2 is allowed to wait for a lock on row A that T1 is holding. Thus, the lock request is rejected with an error (-143 ISAM error: deadlock detected.)

Examine the onstat -p output for deadlocks:


Listing 10. onstat -p output for deadlocks


$ onstat -p

IBM Informix Dynamic Server Version 11.50.FC4     -- On-Line -- Up 2 days 22:34:37 
-- 157696 Kbytes

Profile
dskreads   pagreads   bufreads   %cached dskwrits   pagwrits   bufwrits   %cached
13851      44301      1894394    99.27   22604      41159      429311     94.73

isamtot    open       start      read    write   rewrite  delete  commit     rollbk
1178884    64495      88313      413795  46723   58450    5657    17833      16

gp_read    gp_write   gp_rewrt   gp_del     gp_alloc   gp_free    gp_curs
0          0          0          0          0          0          0

ovlock     ovuserthread ovbuff     usercpu  syscpu   numckpts   flushes
0          0            0          89.23    13.32    366        70849

bufwaits   lokwaits   lockreqs   deadlks    dltouts    ckpwaits   compress   seqscans
191        0          750183     5          0          6          4010       6770

ixda-RA    idx-RA     da-RA      RA-pgsused lchwaits
231        2          3080       3313       254


Looking at the "deadlks" field, you can see that five deadlock events have occurred since the database server came online. If deadlocks are happening frequently, examine the application and try to stagger the use of the frequently changed rows. By reducing the time to wait for a lock, the chances of deadlock can also be reduced.

For a distributed transaction, a session uses the DEADLOCK_TIMEOUT configuration parameter to wait for a response from the remote database server before it returns an error. The "dlouts" field in the onstat -p output shows the statistics for distributed deadlock timeouts.

Logging and non-logging database

In a logging database, the database server keeps a record of its transaction and locks held over the span of the transaction. Often, the locks held by the transaction can be identified unless the transaction is not committed or is rolled back. In a non-logging database, there are no transactions, but locks are still used. Though easily missed, locks are used by the server when executing the Data Manipulation Language and released very quickly after the statement is completed.

3 of 8 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=420556
TutorialTitle=Informix Dynamic Server 11.50 Fundamentals Exam 555 certification preparation, Part 6: Data concurrency
publish-date=08132009
author1-email=yapjg@sg.ibm.com
author1-email-cc=