Berkeley DB set_lk_detect vs. lock_detect

Berkeley DB set_lk_detect vs. lock_detect

Post by To » Sun, 01 Sep 2002 08:12:11



Hi there,

When doing deadlock detection in Berkeley DB, what are the difference
with these two approaches?
1) calling set_lk_detect(..., DB_LOCK_DEFAULT) before creating the db
env and then checking for deadlocks after each db call with the error
code DB_LOCK_DEADLOCK.
2) running a thread that periodically calls lock_detect

I'm assuming 1) has more overhead and could in theory slow down
throughput of the system. And 2) would be used to increase throughput
while checking for deadlocks periodically. If this assumption is
incorrect, why wouldn't you always set set_lk_detect?

Thanks for the help in advance.

Cheers,
~AC

 
 
 

Berkeley DB set_lk_detect vs. lock_detect

Post by Keith Bost » Sun, 01 Sep 2002 23:30:02


g.google.com>...

Quote:> Hi there,

> When doing deadlock detection in Berkeley DB, what are the difference
> with these two approaches?
> 1) calling set_lk_detect(..., DB_LOCK_DEFAULT) before creating the db
> env and then checking for deadlocks after each db call with the error
> code DB_LOCK_DEADLOCK.
> 2) running a thread that periodically calls lock_detect

> I'm assuming 1) has more overhead and could in theory slow down
> throughput of the system. And 2) would be used to increase throughput
> while checking for deadlocks periodically. If this assumption is
> incorrect, why wouldn't you always set set_lk_detect?

Regardless of the deadlocks are checked for, the application must  
to check for a DB_LOCK_DEADLOCK return and abort the enclosing
transaction; the difference between calling DB_ENV->set_lk_detect  
and DB_ENV->lock_detect is the way deadlock detection is done, not
in how the deadlock is handled by the application.

The tradeoffs between the DB_ENV->lock_detect and DB_ENV->set_lk_detect
methods is that automatic deadlock detection will resolve deadlocks more
quickly (because as the deadlock detector runs as soon as the lock  
request blocks), however, automatic deadlock detection often runs the
deadlock detector when there is no need for it, and in systems where
many operations block temporarily on locks but are soon able to proceed,
automatic detection can decrease performance.

Finally, in current releases of Berkeley DB, lock and transaction
timeouts may be used in place of, or in addition to, regular deadlock
detection. If lock timeouts are set, lock requests will return
DB_LOCK_DEADLOCK from a lock call when it is detected that the locks
timeouts has expired, that is, the lock request has blocked, waiting,
longer than the specified timeout. If transaction timeouts are set, lock
requests will return DB_LOCK_DEADLOCK from a lock call when it has been
detected that the transaction has been active longer than the specified
timeout.

Regards,
--keith

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic

118 Tower Rd.                   +1-781-259-3139
Lincoln, MA 01773               http://www.sleepycat.com