Debian Codegraph @

docs/programmer_reference/apprec_auto.html

raw symbols SCIP
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>Automatically generated functions</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="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="apprec.html" title="Chapter 14.  Application Specific Logging and Recovery" />
11 <link rel="prev" href="apprec_def.html" title="Defining application-specific log records" />
12 <link rel="next" href="apprec_config.html" title="Application configuration" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Automatically generated functions</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="apprec_def.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 14. 
26 Application Specific Logging and Recovery
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="apprec_config.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="apprec_auto"></a>Automatically generated functions</h2>
38 </div>
39 </div>
40 </div>
41 <p>The XXX.src file is processed using the gen_rec.awk script included in
42 the dist directory of the Berkeley DB distribution. This is an awk script
43 that is executed from with the following command line:</p>
44 <pre class="programlisting">awk -f gen_rec.awk \
45 -v source_file=<span class="emphasis"><em>C_FILE</em></span> \
46 -v header_file=<span class="emphasis"><em>H_FILE</em></span> \
47 -v print_file=<span class="emphasis"><em>P_FILE</em></span> \
48 -v template_file=<span class="emphasis"><em>TMP_FILE</em></span> &lt; XXX.src</pre>
49 <p>where <span class="emphasis"><em>C_FILE</em></span> is the name of the file into which to place the
50 automatically generated C code, <span class="emphasis"><em>H_FILE</em></span> is the name of the
51 file into which to place the automatically generated data structures
52 and declarations, <span class="emphasis"><em>P_FILE</em></span> is the name of the file into which to
53 place the automatically generated C code that prints log records,
54 and <span class="emphasis"><em>TMP_FILE</em></span> is the name of the file into
55 which to place a template for the recovery routines.</p>
56 <p>Because the gen_rec.awk script uses sources files located relative to
57 the Berkeley DB dist directory, it must be run from the dist directory. For
58 example, in building the Berkeley DB logging and recovery routines for
59 ex_apprec, the following script is used to rebuild the automatically
60 generated files:</p>
61 <pre class="programlisting">E=../examples_c/ex_apprec
62 <p></p>
63 cd ../../dist
64 awk -f gen_rec.awk \
65 -v source_file=$E/ex_apprec_auto.c \
66 -v header_file=$E/ex_apprec_auto.h \
67 -v print_file=$E/ex_apprec_autop.c \
68 -v template_file=$E/ex_apprec_template &lt; $E/ex_apprec.src</pre>
69 <p>For each log record description found in the XXX.src file, the following
70 structure declarations and #defines will be created in the file
71 <span class="emphasis"><em>header_file</em></span>:</p>
72 <pre class="programlisting">#define DB_PREFIX_RECORD_TYPE /* Integer ID number */
73
74 typedef struct _PREFIX_RECORD_TYPE_args {
75 /*
76 * These three fields are generated for every record.
77 */
78 u_int32_t type; /* Record type used for dispatch. */
79
80 /*
81 * Transaction handle that identifies the transaction on whose
82 * behalf the record is being logged.
83 */
84 DB_TXN *txnid;
85
86 /*
87 * The log sequence number returned by the previous call to log_put
88 * for this transaction.
89 */
90 DB_LSN *prev_lsn;
91
92 /*
93 * The rest of the structure contains one field for each of
94 * the entries in the record statement.
95 */
96 };</pre>
97 <p>Thus, the auto-generated ex_apprec_mkdir_args structure looks as follows:</p>
98 <pre class="programlisting">typedef struct _ex_apprec_mkdir_args {
99 u_int32_t type;
100 DB_TXN *txnid;
101 DB_LSN prev_lsn;
102 DBT dirname;
103 } ex_apprec_mkdir_args;</pre>
104 <p>The template_file will contain a template for a recovery function. The
105 recovery function is called on each record read from the log during
106 system recovery, transaction abort, or the application of log records
107 on a replication client, and is expected to redo or undo the operations
108 described by that record. The details of the recovery function will be
109 specific to the record being logged and need to be written manually, but
110 the template provides a good starting point. (See ex_apprec_template
111 and ex_apprec_rec.c for an example of both the template produced and the
112 resulting recovery function.)</p>
113 <p>The template file should be copied to a source file in the application
114 (but not the automatically generated source_file, as that will get
115 overwritten each time gen_rec.awk is run) and fully developed there.
116 The recovery function takes the following parameters:</p>
117 <div class="blockquote">
118 <blockquote class="blockquote">
119 <div class="variablelist">
120 <dl>
121 <dt>
122 <span class="term">dbenv</span>
123 </dt>
124 <dd>The environment in which recovery is running.</dd>
125 <dt>
126 <span class="term">rec</span>
127 </dt>
128 <dd>The record being recovered.</dd>
129 <dt>
130 <span class="term">lsn</span>
131 </dt>
132 <dd>The log sequence number of the record being recovered. The
133 prev_lsn field, automatically included in every auto-generated log
134 record, should be returned through this argument. The prev_lsn field
135 is used to chain log records together to allow transaction aborts;
136 because the recovery function is the only place that a log record gets
137 parsed, the responsibility for returning this value lies with the
138 recovery function writer.</dd>
139 <dt>
140 <span class="term">op</span>
141 </dt>
142 <dd>A parameter of type db_recops, which indicates what operation is being
143 run (<a href="../api_reference/C/envset_app_dispatch.html#set_app_dispatch_DB_TXN_ABORT" class="olink">DB_TXN_ABORT</a>, <a href="../api_reference/C/envset_app_dispatch.html#set_app_dispatch_DB_TXN_APPLY" class="olink">DB_TXN_APPLY</a>, <a href="../api_reference/C/envset_app_dispatch.html#set_app_dispatch_DB_TXN_BACKWARD_ROLL" class="olink">DB_TXN_BACKWARD_ROLL</a>,
144 <a href="../api_reference/C/envset_app_dispatch.html#set_app_dispatch_DB_TXN_FORWARD_ROLL" class="olink">DB_TXN_FORWARD_ROLL</a> or <a href="../api_reference/C/envset_app_dispatch.html#set_app_dispatch_DB_TXN_PRINT" class="olink">DB_TXN_PRINT</a>).
145 </dd>
146 </dl>
147 </div>
148 </blockquote>
149 </div>
150 <p>In addition to the header_file and template_file, a source_file is
151 created, containing a log, read, recovery, and print function for each
152 record type.</p>
153 <p>The log function marshalls the parameters into a buffer, and calls
154 <a href="../api_reference/C/logput.html" class="olink">DB_ENV-&gt;log_put()</a> on that buffer returning 0 on success and non-zero on
155 failure. The log function takes the following parameters:</p>
156 <div class="blockquote">
157 <blockquote class="blockquote">
158 <div class="variablelist">
159 <dl>
160 <dt>
161 <span class="term">dbenv</span>
162 </dt>
163 <dd>The environment in which recovery is running.</dd>
164 <dt>
165 <span class="term">txnid</span>
166 </dt>
167 <dd>The transaction identifier for the transaction handle returned by
168 <a href="../api_reference/C/txnbegin.html" class="olink">DB_ENV-&gt;txn_begin()</a>.</dd>
169 <dt>
170 <span class="term">lsnp</span>
171 </dt>
172 <dd>A pointer to storage for a log sequence number into which the log
173 sequence number of the new log record will be returned.</dd>
174 <dt>
175 <span class="term">syncflag</span>
176 </dt>
177 <dd>A flag indicating whether the record must be written synchronously.
178 Valid values are 0 and <a href="../api_reference/C/logput.html#put_DB_FLUSH" class="olink">DB_FLUSH</a>.</dd>
179 <dt>
180 <span class="term">args</span>
181 </dt>
182 <dd>The remaining parameters to the log message are the fields described
183 in the XXX.src file, in order.</dd>
184 </dl>
185 </div>
186 </blockquote>
187 </div>
188 <p>The read function takes a buffer and unmarshalls its contents into a
189 structure of the appropriate type. It returns 0 on success and non-zero
190 on error. After the fields of the structure have been used, the pointer
191 returned from the read function should be freed. The read function
192 takes the following parameters:</p>
193 <div class="blockquote">
194 <blockquote class="blockquote">
195 <div class="variablelist">
196 <dl>
197 <dt>
198 <span class="term">dbenv</span>
199 </dt>
200 <dd>The environment in which recovery is running.</dd>
201 <dt>
202 <span class="term">recbuf</span>
203 </dt>
204 <dd>A buffer.</dd>
205 <dt>
206 <span class="term">argp</span>
207 </dt>
208 <dd>A pointer to a structure of the appropriate type.</dd>
209 </dl>
210 </div>
211 </blockquote>
212 </div>
213 <p>The print function displays the contents of the record. The print
214 function takes the same parameters as the recovery function described
215 previously. Although some of the parameters are unused by the print
216 function, taking the same parameters allows a single dispatch loop to
217 dispatch to a variety of functions. The print function takes the
218 following parameters:</p>
219 <div class="blockquote">
220 <blockquote class="blockquote">
221 <div class="variablelist">
222 <dl>
223 <dt>
224 <span class="term">dbenv</span>
225 </dt>
226 <dd>The environment in which recovery is running.</dd>
227 <dt>
228 <span class="term">rec</span>
229 </dt>
230 <dd>The record being recovered.</dd>
231 <dt>
232 <span class="term">lsn</span>
233 </dt>
234 <dd>The log sequence number of the record being recovered.</dd>
235 <dt>
236 <span class="term">op</span>
237 </dt>
238 <dd>Unused.</dd>
239 </dl>
240 </div>
241 </blockquote>
242 </div>
243 <p>Finally, the source file will contain a function (named XXX_init_print,
244 where XXX is replaced by the prefix) which should be added to the
245 initialization part of the standalone <a href="../api_reference/C/db_printlog.html" class="olink">db_printlog</a> utility code
246 so that utility can be used to display application-specific log records.</p>
247 </div>
248 <div class="navfooter">
249 <hr />
250 <table width="100%" summary="Navigation footer">
251 <tr>
252 <td width="40%" align="left"><a accesskey="p" href="apprec_def.html">Prev</a> </td>
253 <td width="20%" align="center">
254 <a accesskey="u" href="apprec.html">Up</a>
255 </td>
256 <td width="40%" align="right"> <a accesskey="n" href="apprec_config.html">Next</a></td>
257 </tr>
258 <tr>
259 <td width="40%" align="left" valign="top">Defining application-specific log records </td>
260 <td width="20%" align="center">
261 <a accesskey="h" href="index.html">Home</a>
262 </td>
263 <td width="40%" align="right" valign="top"> Application configuration</td>
264 </tr>
265 </table>
266 </div>
267 </body>
268 </html>