Update.
[glibc.git] / db2 / hash / hash.src
blob8cbcee73f7153a85eeeea6d6e081b5e889a7b2ea
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996, 1997
5  *      Sleepycat Software.  All rights reserved.
6  */
7 /*
8  * Copyright (c) 1995, 1996
9  *      Margo Seltzer.  All rights reserved.
10  */
12  * Copyright (c) 1995, 1996
13  *      The President and Fellows of Harvard University.  All rights reserved.
14  *
15  * This code is derived from software contributed to Berkeley by
16  * Margo Seltzer.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  *    notice, this list of conditions and the following disclaimer in the
25  *    documentation and/or other materials provided with the distribution.
26  * 3. All advertising materials mentioning features or use of this software
27  *    must display the following acknowledgement:
28  *      This product includes software developed by the University of
29  *      California, Berkeley and its contributors.
30  * 4. Neither the name of the University nor the names of its contributors
31  *    may be used to endorse or promote products derived from this software
32  *    without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  *
46  *      @(#)hash.src    10.2 (Sleepycat) 11/2/97
47  */
49 #include "config.h"
52  * This is the source file used to create the logging functions for the
53  * hash package.  Each access method (or set of routines wishing to register
54  * record types with the transaction system) should have a file like this.
55  * Each type of log record and its parameters is defined.  The basic
56  * format of a record definition is:
57  *
58  * BEGIN        <RECORD_TYPE>
59  * ARG|STRING|POINTER   <variable name> <variable type> <printf format>
60  * ...
61  * END
62  * ARG the argument is a simple parameter of the type * specified.
63  * DBT the argument is a DBT (db.h) containing a length and pointer.
64  * PTR the argument is a pointer to the data type specified; the entire
65  *     type should be logged.
66  *
67  * There are a set of shell scripts of the form xxx.sh that generate c
68  * code and or h files to process these.  (This is probably better done
69  * in a single PERL script, but for now, this works.)
70  *
71  * The DB recovery system requires the following three fields appear in
72  * every record, and will assign them to the per-record-type structures
73  * as well as making them the first parameters to the appropriate logging
74  * call.
75  * rectype:     record-type, identifies the structure and log/read call
76  * txnid:       transaction id, a DBT in this implementation
77  * prev:        the last LSN for this transaction
78  */
81  * Use the argument of PREFIX as the prefix for all record types,
82  * routines, id numbers, etc.
83  */
84 PREFIX  ham
87  * HASH-insdel: used for hash to insert/delete a pair of entries onto a master
88  * page. The pair might be regular key/data pairs or they might be the
89  * structures that refer to off page items, duplicates or offpage duplicates.
90  *  opcode - PUTPAIR/DELPAIR + big masks
91  *  fileid - identifies the file referenced
92  *  pgno - page within file
93  *  ndx - index on the page of the item being added (item index)
94  *  pagelsn - lsn on the page before the update
95  *  key - the key being inserted
96  *  data - the data being inserted
97  */
98 BEGIN insdel
99 ARG     opcode          u_int32_t       lu
100 ARG     fileid          u_int32_t       lu
101 ARG     pgno            db_pgno_t       lu
102 ARG     ndx             u_int32_t       lu
103 POINTER pagelsn         DB_LSN *        lu
104 DBT     key             DBT             s
105 DBT     data            DBT             s
109  * Used to add and remove overflow pages.
110  * prev_pgno is the previous page that is going to get modified to
111  *      point to this one.  If this is the first page in a chain
112  *      then prev_pgno should be PGNO_INVALID.
113  * new_pgno is the page being allocated.
114  * next_pgno is the page that follows this one.  On allocation,
115  *      this should be PGNO_INVALID.  For deletes, it may exist.
116  * pagelsn is the old lsn on the page.
117  */
118 BEGIN newpage
119 ARG     opcode          u_int32_t       lu
120 ARG     fileid          u_int32_t       lu
121 ARG     prev_pgno       db_pgno_t       lu
122 POINTER prevlsn         DB_LSN *        lu
123 ARG     new_pgno        db_pgno_t       lu
124 POINTER pagelsn         DB_LSN *        lu
125 ARG     next_pgno       db_pgno_t       lu
126 POINTER nextlsn         DB_LSN *        lu
130  * Splitting requires two types of log messages.  The first
131  * logs the meta-data of the split.  The second logs the
132  * data on the original page.  To redo the split, we have
133  * to visit the new page (pages) and add the items back
134  * on the page if they are not yet there.
135  * For the meta-data split
136  *      bucket: max_bucket in table before split
137  *      ovflpoint: overflow point before split.
138  *      spares: spares[ovflpoint] before split.
139  */
140 BEGIN splitmeta
141 ARG     fileid          u_int32_t       lu
142 ARG     bucket          u_int32_t       lu
143 ARG     ovflpoint       u_int32_t       lu
144 ARG     spares          u_int32_t       lu
145 POINTER metalsn         DB_LSN *        lu
148 BEGIN splitdata
149 ARG     fileid          u_int32_t       lu
150 ARG     opcode          u_int32_t       lu
151 ARG     pgno            db_pgno_t       lu
152 DBT     pageimage       DBT             s
153 POINTER pagelsn         DB_LSN *        lu
157  * HASH-replace: is used for hash to handle partial puts that only
158  * affect a single master page.
159  *  fileid - identifies the file referenced
160  *  pgno - page within file
161  *  ndx - index on the page of the item being modified (item index)
162  *  pagelsn - lsn on the page before the update
163  *  off - offset in the old item where the new item is going.
164  *  olditem - DBT that describes the part of the item being replaced.
165  *  newitem - DBT of the new item.
166  *  makedup - this was a replacement that made an item a duplicate.
167  */
168 BEGIN replace
169 ARG     fileid          u_int32_t       lu
170 ARG     pgno            db_pgno_t       lu
171 ARG     ndx             u_int32_t       lu
172 POINTER pagelsn         DB_LSN *        lu
173 ARG     off             int32_t         ld
174 DBT     olditem         DBT             s
175 DBT     newitem         DBT             s
176 ARG     makedup         u_int32_t       lu
180  * HASH-newpgno: is used to record getting/deleting a new page number.
181  * This doesn't require much data modification, just modifying the
182  * meta-data.
183  * pgno is the page being allocated/freed.
184  * free_pgno is the next_pgno on the free list.
185  * old_type was the type of a page being deallocated.
186  * old_pgno was the next page number before the deallocation.  We use it
187  *      to indicate whether we incremented the spares count or not
188  *      during this allocation.
189  */
190 BEGIN newpgno
191 ARG     opcode          u_int32_t       lu
192 ARG     fileid          u_int32_t       lu
193 ARG     pgno            db_pgno_t       lu
194 ARG     free_pgno       db_pgno_t       lu
195 ARG     old_type        u_int32_t       lu
196 ARG     old_pgno        db_pgno_t       lu
197 ARG     new_type        u_int32_t       lu
198 POINTER pagelsn         DB_LSN *        lu
199 POINTER metalsn         DB_LSN *        lu
203  * ovfl: initialize a set of overflow pages.
204  */
205 BEGIN ovfl
206 ARG     fileid          u_int32_t       lu
207 ARG     start_pgno      db_pgno_t       lu
208 ARG     npages          u_int32_t       lu
209 ARG     free_pgno       db_pgno_t       lu
210 ARG     ovflpoint       u_int32_t       lu
211 POINTER metalsn         DB_LSN *        lu
215  * Used when we empty the first page in a bucket and there are pages
216  * after it.  The page after it gets copied into the bucket page (since
217  * bucket pages have to be in fixed locations).
218  * pgno: the bucket page
219  * pagelsn: the old LSN on the bucket page
220  * next_pgno: the page number of the next page
221  * nnext_pgno: page after next_pgno (may need to change its prev)
222  * nnextlsn: the LSN of nnext_pgno.
223  */
224 BEGIN copypage
225 ARG     fileid          u_int32_t       lu
226 ARG     pgno            db_pgno_t       lu
227 POINTER pagelsn         DB_LSN *        lu
228 ARG     next_pgno       db_pgno_t       lu
229 POINTER nextlsn         DB_LSN *        lu
230 ARG     nnext_pgno      db_pgno_t       lu
231 POINTER nnextlsn        DB_LSN *        lu
232 DBT     page            DBT             s