| 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>Defining application-specific log records</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.html" title="Chapter 14. Application Specific Logging and Recovery" /> |
| 12 | <link rel="next" href="apprec_auto.html" title="Automatically generated functions" /> |
| 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">Defining application-specific log records</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="apprec.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_auto.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_def"></a>Defining application-specific log records</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>By convention, log records are described in files named <code class="filename">XXX.src</code>, |
| 42 | where "XXX" is typically a descriptive name for a subsystem or other |
| 43 | logical group of logging functions. These files contain interface |
| 44 | definition language descriptions for each type of log record that is |
| 45 | used by the subsystem.</p> |
| 46 | <p>All blank lines and lines beginning with a hash ("#") character in |
| 47 | the XXX.src files are ignored.</p> |
| 48 | <p>The first non-comment line in the file should begin with the keyword |
| 49 | PREFIX, followed by a string that will be prepended to every generated |
| 50 | function name. Frequently, the PREFIX is either identical or similar |
| 51 | to the name of the <code class="filename">XXX.src</code> file. For example, the Berkeley DB |
| 52 | application-specific recovery example uses the file |
| 53 | <code class="filename">ex_apprec.src</code>, which begins with the following PREFIX line:</p> |
| 54 | <pre class="programlisting">PREFIX ex_apprec</pre> |
| 55 | <p>Following the PREFIX line are the include files required by the |
| 56 | automatically generated functions. The include files should be listed |
| 57 | in order, prefixed by the keyword INCLUDE. For example, the Berkeley DB |
| 58 | application-specific recovery example lists the following include |
| 59 | files:</p> |
| 60 | <pre class="programlisting">INCLUDE #include "ex_apprec.h"</pre> |
| 61 | <p>The rest of the XXX.src file consists of log record descriptions. Each |
| 62 | log record description begins with one of the following lines:</p> |
| 63 | <pre class="programlisting">BEGIN <span class="emphasis"><em>RECORD_NAME</em></span> <span class="emphasis"><em>DB_VERSION_NUMBER</em></span> <span class="emphasis"><em>RECORD_NUMBER</em></span></pre> |
| 64 | <pre class="programlisting">BEGIN_COMPAT <span class="emphasis"><em>RECORD_NAME</em></span> <span class="emphasis"><em>DB_VERSION_NUMBER</em></span> <span class="emphasis"><em>RECORD_NUMBER</em></span></pre> |
| 65 | <p>and ends with the line:</p> |
| 66 | <pre class="programlisting">END</pre> |
| 67 | <p>The <span class="emphasis"><em>BEGIN</em></span> line should be used for most record types.</p> |
| 68 | <p>The <span class="emphasis"><em>BEGIN_COMPAT</em></span> is used for log record compatibility to facilitate |
| 69 | online upgrades of replication groups. Records created with this keyword will |
| 70 | produce reading and printing routines, but no logging routines. The recovery |
| 71 | routines are retrieved from older releases, so no recovery templates will be |
| 72 | generated for these records.</p> |
| 73 | <p>The <span class="emphasis"><em>DB_VERSION_NUMBER</em></span> variable should be replaced with the |
| 74 | current major and minor version of Berkeley DB, with all punctuation removed. |
| 75 | For example, Berkeley DB version 4.2 should be 42, version 4.5 should be 45.</p> |
| 76 | <p>The <span class="emphasis"><em>RECORD_NAME</em></span> variable should be replaced with a record |
| 77 | name for this log record. The <span class="emphasis"><em>RECORD_NUMBER</em></span> variable should |
| 78 | be replaced with a record number.</p> |
| 79 | <p>The combination of PREFIX name and <span class="emphasis"><em>RECORD_NAME</em></span>, and the |
| 80 | <span class="emphasis"><em>RECORD_NUMBER</em></span> must be unique for the application, that is, |
| 81 | values for application-specific and Berkeley DB log records may not overlap. |
| 82 | Further, because record numbers are stored in log files, which are |
| 83 | usually portable across application and Berkeley DB releases, any change to |
| 84 | the record numbers or log record format or should be handled as |
| 85 | described in the section on log format changes in |
| 86 | the <a href="../upgrading/upgrade_process.html" class="olink">Upgrading Berkeley DB installations</a> chapter of the Berkeley DB Installation and Build Guide. The record number space |
| 87 | below 10,000 is reserved for Berkeley DB itself; applications should choose |
| 88 | record number values equal to or greater than 10,000.</p> |
| 89 | <p>Between the BEGIN and END keywords there should be one optional |
| 90 | <span class="emphasis"><em>DUPLICATE</em></span> line and one line for each |
| 91 | data item logged as part of this log record.</p> |
| 92 | <p>The <span class="emphasis"><em>DUPLICATE</em></span> line is of the form:</p> |
| 93 | <pre class="programlisting">DUPLICATE <span class="emphasis"><em>RECORD_NAME</em></span> <span class="emphasis"><em>DB_VERSION_NUMBER</em></span> <span class="emphasis"><em>RECORD_NUMBER</em></span></pre> |
| 94 | <p>The <span class="emphasis"><em>DUPLICATE</em></span> specifier should be used when creating a record |
| 95 | that requires its own record number but can use the argument structure, |
| 96 | reading and printing routines from another record. In this case, we will |
| 97 | create a new log record type, but use the enclosing log record type for |
| 98 | the argument structure and the log reading and printing routines.</p> |
| 99 | <p>The format of lines for each data item logged is as follows:</p> |
| 100 | <pre class="programlisting">ARG | DBT | POINTER <span class="emphasis"><em>variable_name</em></span> <span class="emphasis"><em>variable_type</em></span> <span class="emphasis"><em>printf_format</em></span></pre> |
| 101 | <p>The keyword ARG indicates that the argument is a simple parameter of |
| 102 | the type specified. For example, a file ID might be logged as:</p> |
| 103 | <pre class="programlisting">ARG fileID int d</pre> |
| 104 | <p>The keyword DBT indicates that the argument is a Berkeley DB DBT structure, |
| 105 | containing a length and pointer to a byte string. The keyword POINTER |
| 106 | indicates that the argument is a pointer to the data type specified (of |
| 107 | course the data type, not the pointer, is what is logged).</p> |
| 108 | <p>The <span class="emphasis"><em>variable_name</em></span> is the field name within the structure that |
| 109 | will be used to refer to this item. The <span class="emphasis"><em>variable_type</em></span> is |
| 110 | the C-language type of the variable, and the printf format is the |
| 111 | C-language format string, without the leading percent ("%") character, |
| 112 | that should be used to display the contents of the field (for example, |
| 113 | "s" for string, "d" for signed integral type, "u" for unsigned integral |
| 114 | type, "ld" for signed long integral type, "lu" for long unsigned |
| 115 | integral type, and so on).</p> |
| 116 | <p>For example, ex_apprec.src defines a single log record type, used to |
| 117 | log a directory name that has been stored in a DBT:</p> |
| 118 | <pre class="programlisting">BEGIN mkdir 10000 |
| 119 | DBT dirname DBT s |
| 120 | END</pre> |
| 121 | <p>As the name suggests, this example of an application-defined log record |
| 122 | will be used to log the creation of a directory. There are many more |
| 123 | examples of XXX.src files in the Berkeley DB distribution. For example, the |
| 124 | file btree/btree.src contains the definitions for the log records |
| 125 | supported by the Berkeley DB Btree access method.</p> |
| 126 | </div> |
| 127 | <div class="navfooter"> |
| 128 | <hr /> |
| 129 | <table width="100%" summary="Navigation footer"> |
| 130 | <tr> |
| 131 | <td width="40%" align="left"><a accesskey="p" href="apprec.html">Prev</a> </td> |
| 132 | <td width="20%" align="center"> |
| 133 | <a accesskey="u" href="apprec.html">Up</a> |
| 134 | </td> |
| 135 | <td width="40%" align="right"> <a accesskey="n" href="apprec_auto.html">Next</a></td> |
| 136 | </tr> |
| 137 | <tr> |
| 138 | <td width="40%" align="left" valign="top">Chapter 14. |
| 139 | Application Specific Logging and Recovery |
| 140 | </td> |
| 141 | <td width="20%" align="center"> |
| 142 | <a accesskey="h" href="index.html">Home</a> |
| 143 | </td> |
| 144 | <td width="40%" align="right" valign="top"> Automatically generated functions</td> |
| 145 | </tr> |
| 146 | </table> |
| 147 | </div> |
| 148 | </body> |
| 149 | </html> |