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>DB->sync()</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> 10 <link rel="up" href="db.html" title="Chapter��2.�� The DB Handle" /> 11 <link rel="prev" href="dbstat_print.html" title="DB->stat_print()" /> 12 <link rel="next" href="dbtruncate.html" title="DB->truncate()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB->sync()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbstat_print.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.�� 23 The DB Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="dbtruncate.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="dbsync"></a>DB->sync()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB->sync(DB *db, u_int32_t flags); </pre> 42 <p> 43 The <code class="methodname">DB->sync()</code> method flushes any cached information to disk. 44 </p> 45 <p> 46 If the database is in memory only, the <code class="methodname">DB->sync()</code> method has no 47 effect and will always succeed. 48 </p> 49 <p> 50 <span class="bold"><strong>It is important to understand that flushing 51 cached information to disk only minimizes the window of opportunity 52 for corrupted data.</strong></span> Although unlikely, it is possible for 53 database corruption to happen if a system or application crash occurs 54 while writing data to the database. To ensure that database 55 corruption never occurs, applications must either: use transactions 56 and logging with automatic recovery; use logging and 57 application-specific recovery; or edit a copy of the database, and 58 once all applications using the database have successfully called 59 <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a>, atomically 60 replace the original database with the updated copy. 61 </p> 62 <p> 63 The <code class="methodname">DB->sync()</code> <span> 64 <span> 65 method returns a non-zero error value on failure and 0 on success. 66 </span> 67 68 </span> 69 </p> 70 <div class="sect2" lang="en" xml:lang="en"> 71 <div class="titlepage"> 72 <div> 73 <div> 74 <h3 class="title"><a id="id1651993"></a>Parameters</h3> 75 </div> 76 </div> 77 </div> 78 <div class="sect3" lang="en" xml:lang="en"> 79 <div class="titlepage"> 80 <div> 81 <div> 82 <h4 class="title"><a id="id1651971"></a>flags</h4> 83 </div> 84 </div> 85 </div> 86 <p> 87 The <span class="bold"><strong>flags</strong></span> parameter is currently 88 unused, and must be set to 0. 89 </p> 90 </div> 91 </div> 92 <div class="sect2" lang="en" xml:lang="en"> 93 <div class="titlepage"> 94 <div> 95 <div> 96 <h3 class="title"><a id="id1652141"></a>Errors</h3> 97 </div> 98 </div> 99 </div> 100 <p> 101 The <code class="methodname">DB->sync()</code> <span> 102 <span> 103 method may fail and return one of the following non-zero errors: 104 </span> 105 106 </span> 107 </p> 108 <div class="sect3" lang="en" xml:lang="en"> 109 <div class="titlepage"> 110 <div> 111 <div> 112 <h4 class="title"><a id="id1652133"></a> DB_REP_HANDLE_DEAD</h4> 113 </div> 114 </div> 115 </div> 116 <p> 117 When a client synchronizes with the master, it is possible for committed 118 transactions to be rolled back. This invalidates all the database and cursor 119 handles opened in the replication environment. Once this occurs, an attempt to use 120 such a handle will 121 122 return <code class="literal">DB_REP_HANDLE_DEAD</code>. 123 The application will need to discard the handle and open a new one in order to 124 continue processing. 125 </p> 126 </div> 127 <div class="sect3" lang="en" xml:lang="en"> 128 <div class="titlepage"> 129 <div> 130 <div> 131 <h4 class="title"><a id="id1651970"></a>DB_REP_LOCKOUT</h4> 132 </div> 133 </div> 134 </div> 135 <p> 136 The operation was blocked by client/master synchronization. 137 </p> 138 </div> 139 <div class="sect3" lang="en" xml:lang="en"> 140 <div class="titlepage"> 141 <div> 142 <div> 143 <h4 class="title"><a id="id1651997"></a>EINVAL</h4> 144 </div> 145 </div> 146 </div> 147 <p> 148 An invalid flag value or parameter was specified. 149 </p> 150 </div> 151 </div> 152 <div class="sect2" lang="en" xml:lang="en"> 153 <div class="titlepage"> 154 <div> 155 <div> 156 <h3 class="title"><a id="id1651965"></a>Class</h3> 157 </div> 158 </div> 159 </div> 160 <p> 161 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> 162 </p> 163 </div> 164 <div class="sect2" lang="en" xml:lang="en"> 165 <div class="titlepage"> 166 <div> 167 <div> 168 <h3 class="title"><a id="id1651554"></a>See Also</h3> 169 </div> 170 </div> 171 </div> 172 <p> 173 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 174 </p> 175 </div> 176 </div> 177 <div class="navfooter"> 178 <hr /> 179 <table width="100%" summary="Navigation footer"> 180 <tr> 181 <td width="40%" align="left"><a accesskey="p" href="dbstat_print.html">Prev</a>��</td> 182 <td width="20%" align="center"> 183 <a accesskey="u" href="db.html">Up</a> 184 </td> 185 <td width="40%" align="right">��<a accesskey="n" href="dbtruncate.html">Next</a></td> 186 </tr> 187 <tr> 188 <td width="40%" align="left" valign="top">DB->stat_print()��</td> 189 <td width="20%" align="center"> 190 <a accesskey="h" href="index.html">Home</a> 191 </td> 192 <td width="40%" align="right" valign="top">��DB->truncate()</td> 193 </tr> 194 </table> 195 </div> 196 </body> 197</html> 198