1<!--$Id: notxn.so,v 10.15 2001/05/22 19:39:31 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Locking without transactions</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<a name="2"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></b></td> 14<td align=right><a href="/lock/page.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/lock/twopl.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Locking without transactions</b></p> 17<p>If an application runs with locking specified, but not transactions (for 18example, <a href="/api_c/env_open.html">DB_ENV->open</a> is called with <a href="/api_c/env_open.html#DB_INIT_LOCK">DB_INIT_LOCK</a> or 19<a href="/api_c/env_open.html#DB_INIT_CDB">DB_INIT_CDB</a> specified, but not <a href="/api_c/env_open.html#DB_INIT_TXN">DB_INIT_TXN</a>), locks are 20normally acquired during each Berkeley DB operation and released before the 21operation returns to the caller. The only exception is in the case of 22cursor operations. Cursors identify a particular position in a file. 23For this reason, cursors must retain read locks across cursor calls to 24make sure that the position is uniquely identifiable during a subsequent 25cursor call, and so that an operation using <a href="/api_c/dbc_get.html#DB_CURRENT">DB_CURRENT</a> will 26always refer to the same record as a previous cursor call. These cursor 27locks cannot be released until the cursor is either repositioned and a 28new cursor lock established (for example, using the <a href="/api_c/dbc_get.html#DB_NEXT">DB_NEXT</a> 29or <a href="/api_c/dbc_get.html#DB_SET">DB_SET</a> flags), or the cursor is closed. As a result, 30application writers are encouraged to close cursors as soon as 31possible.</p> 32<p>It is important to realize that concurrent applications that use locking 33must ensure that two concurrent threads do not block each other. 34However, because Btree and Hash access method page splits can occur at 35any time, there is virtually no way to guarantee that an application 36that writes the database cannot deadlock. Applications running without 37the protection of transactions may deadlock, and can leave the database 38in an inconsistent state when they do so. Applications that need 39concurrent access, but not transactions, are more safely implemented 40using the Berkeley DB Concurrent Data Store Product.</p> 41<table width="100%"><tr><td><br></td><td align=right><a href="/lock/page.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/lock/twopl.html"><img src="/images/next.gif" alt="Next"></a> 42</td></tr></table> 43<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 44</body> 45</html> 46