node32.html 4.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.1 Subtransactions</title>
<META NAME="description" CONTENT="4.1 Subtransactions">
<META NAME="keywords" CONTENT="zodb">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=">
<link rel="STYLESHEET" href="zodb.css">
<link rel="first" href="zodb.html">
<link rel="contents" href="contents.html" title="Contents">

<LINK REL="next" HREF="node33.html">
<LINK REL="previous" HREF="node31.html">
<LINK REL="up" HREF="node31.html">
<LINK REL="next" HREF="node33.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node31.html"><img src="/python/writing/icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A HREF="node31.html"><img src="/python/writing/icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A HREF="node33.html"><img src="/python/writing/icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">ZODB/ZEO Programming Guide</td>
<td><A href="contents.html"><img src="/python/writing/icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="/python/writing/icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="/python/writing/icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node31.html">4 Transactions and Versioning</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node31.html">4 Transactions and Versioning</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node33.html">4.2 Undoing Changes</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION000510000000000000000">
4.1 Subtransactions</A>
</H2>

<P>
Subtransactions can be created within a transaction.  Each
subtransaction can be individually committed and aborted, but the
changes within a subtransaction are not truly committed until the
containing transaction is committed.

<P>
The primary purpose of subtransactions is to decrease the memory usage
of transactions that touch a very large number of objects.  Consider a
transaction during which 200,000 objects are modified.  All the
objects that are modified in a single transaction have to remain in
memory until the transaction is committed, because the ZODB can't
discard them from the object cache.  This can potentially make the
memory usage quite large.  With subtransactions, a commit can be be
performed at intervals, say, every 10,000 objects.  Those 10,000
objects are then written to permanent storage and can be purged from
the cache to free more space.

<P>
To commit a subtransaction instead of a full transaction, 
pass a true value to the <tt class="method">commit()</tt>
or <tt class="method">abort()</tt> method of the <tt class="class">Transaction</tt> object.

<P>
<dl><dd><pre class="verbatim">
# Commit a subtransaction
get_transaction().commit(1)	

# Abort a subtransaction
get_transaction().abort(1)
</pre></dl>

<P>
A new subtransaction is automatically started on committing or
aborting the previous subtransaction.

<P>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node31.html"><img src="/python/writing/icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A HREF="node31.html"><img src="/python/writing/icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A HREF="node33.html"><img src="/python/writing/icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">ZODB/ZEO Programming Guide</td>
<td><A href="contents.html"><img src="/python/writing/icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="/python/writing/icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="/python/writing/icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node31.html">4 Transactions and Versioning</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node31.html">4 Transactions and Versioning</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node33.html">4.2 Undoing Changes</A>
<hr>
<span class="release-info">Release 0.03, documentation updated on February 8, 2002.</span>
</DIV>
<!--End of Navigation Panel-->

</BODY>
</HTML>