1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Application Requirements</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" /> 10 <link rel="up" href="introduction.html" title="Chapter��1.��Introduction" /> 11 <link rel="prev" href="sysfailure.html" title="A Note on System Failure" /> 12 <link rel="next" href="multithread-intro.html" title="Multi-threaded and Multi-process Applications" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Application Requirements</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="sysfailure.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��1.��Introduction</th> 23 <td width="20%" align="right">��<a accesskey="n" href="multithread-intro.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="apireq"></a>Application Requirements</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 In order to use transactions, your application has certain 38 requirements beyond what is required of non-transactional protected 39 applications. They are: 40 </p> 41 <div class="itemizedlist"> 42 <ul type="disc"> 43 <li> 44 <p> 45 Environments. 46 </p> 47 <p> 48 Environments are optional for non-transactional 49 applications, but they are required for transactional 50 applications. 51 </p> 52 <p> 53 Environment usage is described in detail in 54 <a class="xref" href="usingtxns.html" title="Chapter��3.��Transaction Basics">Transaction Basics</a>. 55 </p> 56 </li> 57 <li> 58 <p> 59 Transaction subsystem. 60 </p> 61 <p> 62 In order to use transactions, you must explicitly 63 enable the transactional subsystem for your 64 application, and this must be done at the time that 65 your environment is first created. 66 </p> 67 </li> 68 <li> 69 <p> 70 Logging subsystem. 71 </p> 72 <p> 73 The logging subsystem is required for recovery purposes, but 74 its usage also means your application may require a 75 little more administrative effort than it does when logging 76 is not in use. See <a class="xref" href="filemanagement.html" title="Chapter��5.��Managing DB Files">Managing DB Files</a> for more information. 77 </p> 78 </li> 79 <li> 80 <p> 81 <span>DB_TXN</span> 82 83 84 85 handles. 86 </p> 87 <p> 88 In order to obtain the atomicity guarantee offered by 89 the transactional subsystem (that is, combine multiple 90 operations in a single unit of work), your application must use 91 transaction handles. These handles are obtained from your 92 <span>DB_ENV</span> 93 94 95 96 objects. They should normally be short-lived, and their usage is 97 reasonably simple. To complete a transaction and save 98 the work it performed, you 99 call its <code class="methodname">commit()</code> method. To 100 complete a transaction and discard its work, you call its 101 <code class="methodname">abort()</code> method. 102 </p> 103 <p> 104 In addition, it is possible to use auto commit if you want 105 to transactional protect a single write operation. Auto 106 commit allows a transaction to be used without 107 obtaining an explicit transaction handle. See 108 <a class="xref" href="autocommit.html" title="Auto Commit">Auto Commit</a> 109 for information on how to use auto commit. 110 </p> 111 </li> 112 <li> 113 <p> 114 Database open requirements. 115 </p> 116 <p> 117 118 <span>In addition to using 119 environments and initializing the 120 correct subsystems, your</span> 121 122 123 application must transaction protect the database 124 125 opens<span>, 126 and any secondary index associations,</span> 127 128 if subsequent operations on the databases are to be transaction 129 protected. The database open and secondary index 130 association are commonly transaction protected using 131 auto commit. 132 </p> 133 </li> 134 <li> 135 <p> 136 Deadlock detection. 137 </p> 138 <p> 139 Typically transactional applications use multiple 140 threads of control when accessing the database. 141 Any time multiple threads are used on a single resource, 142 the potential for lock contention arises. In turn, lock 143 contention can lead to deadlocks. See 144 <a class="xref" href="blocking_deadlocks.html" title="Locks, Blocks, and Deadlocks">Locks, Blocks, and Deadlocks</a> 145 for more information. 146 </p> 147 <p> 148 Therefore, transactional applications must frequently 149 include code for detecting and responding to deadlocks. 150 Note that this requirement is not 151 <span class="emphasis"><em>specific</em></span> to transactions 152 ��� you can certainly write concurrent 153 non-transactional DB applications. Further, not 154 every transactional application uses concurrency and 155 so not every transactional application must 156 manage deadlocks. Still, deadlock management is so 157 frequently a characteristic of transactional 158 applications that we discuss it in this 159 book. See <a class="xref" href="txnconcurrency.html" title="Chapter��4.��Concurrency">Concurrency</a> 160 for more information. 161 </p> 162 </li> 163 </ul> 164 </div> 165 </div> 166 <div class="navfooter"> 167 <hr /> 168 <table width="100%" summary="Navigation footer"> 169 <tr> 170 <td width="40%" align="left"><a accesskey="p" href="sysfailure.html">Prev</a>��</td> 171 <td width="20%" align="center"> 172 <a accesskey="u" href="introduction.html">Up</a> 173 </td> 174 <td width="40%" align="right">��<a accesskey="n" href="multithread-intro.html">Next</a></td> 175 </tr> 176 <tr> 177 <td width="40%" align="left" valign="top">A Note on System Failure��</td> 178 <td width="20%" align="center"> 179 <a accesskey="h" href="index.html">Home</a> 180 </td> 181 <td width="40%" align="right" valign="top">��Multi-threaded 182 <span>and Multi-process</span> 183 Applications</td> 184 </tr> 185 </table> 186 </div> 187 </body> 188</html> 189