2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
10
* Copyright (c) 1995, 1996
11
* Margo Seltzer. All rights reserved.
14
* Copyright (c) 1995, 1996
15
* The President and Fellows of Harvard University. All rights reserved.
17
* This code is derived from software contributed to Berkeley by
20
* Redistribution and use in source and binary forms, with or without
21
* modification, are permitted provided that the following conditions
23
* 1. Redistributions of source code must retain the above copyright
24
* notice, this list of conditions and the following disclaimer.
25
* 2. Redistributions in binary form must reproduce the above copyright
26
* notice, this list of conditions and the following disclaimer in the
27
* documentation and/or other materials provided with the distribution.
28
* 3. Neither the name of the University nor the names of its contributors
29
* may be used to endorse or promote products derived from this software
30
* without specific prior written permission.
32
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
INCLUDE #include "db_config.h"
50
INCLUDE #ifndef NO_SYSTEM_INCLUDES
51
INCLUDE #include <sys/types.h>
53
INCLUDE #include <ctype.h>
54
INCLUDE #include <string.h>
57
INCLUDE #include "db_int.h"
58
INCLUDE #include "dbinc/crypto.h"
59
INCLUDE #include "dbinc/db_page.h"
60
INCLUDE #include "dbinc/db_dispatch.h"
61
INCLUDE #include "dbinc/db_am.h"
62
INCLUDE #include "dbinc/hash.h"
63
INCLUDE #include "dbinc/rep.h"
64
INCLUDE #include "dbinc/log.h"
65
INCLUDE #include "dbinc/txn.h"
69
* HASH-insdel: used for hash to insert/delete a pair of entries onto a master
70
* page. The pair might be regular key/data pairs or they might be the
71
* structures that refer to off page items, duplicates or offpage duplicates.
72
* opcode - PUTPAIR/DELPAIR + big masks
73
* fileid - identifies the file referenced
74
* pgno - page within file
75
* ndx - index on the page of the item being added (item index)
76
* pagelsn - lsn on the page before the update
77
* key - the key being inserted
78
* data - the data being inserted
81
ARG opcode u_int32_t lu
83
WRLOCK pgno db_pgno_t lu
85
POINTER pagelsn DB_LSN * lu
91
* Used to add and remove overflow pages.
92
* prev_pgno is the previous page that is going to get modified to
93
* point to this one. If this is the first page in a chain
94
* then prev_pgno should be PGNO_INVALID.
95
* new_pgno is the page being allocated.
96
* next_pgno is the page that follows this one. On allocation,
97
* this should be PGNO_INVALID. For deletes, it may exist.
98
* pagelsn is the old lsn on the page.
101
ARG opcode u_int32_t lu
103
WRLOCKNZ prev_pgno db_pgno_t lu
104
POINTER prevlsn DB_LSN * lu
105
WRLOCKNZ new_pgno db_pgno_t lu
106
POINTER pagelsn DB_LSN * lu
107
WRLOCKNZ next_pgno db_pgno_t lu
108
POINTER nextlsn DB_LSN * lu
112
* Splitting requires two types of log messages. The second logs the
113
* data on the original page. To redo the split, we have to visit the
114
* new page (pages) and add the items back on the page if they are not
119
ARG opcode u_int32_t lu
120
WRLOCK pgno db_pgno_t lu
121
PGDBT pageimage DBT s
122
POINTER pagelsn DB_LSN * lu
126
* HASH-replace: is used for hash to handle partial puts that only
127
* affect a single master page.
128
* fileid - identifies the file referenced
129
* pgno - page within file
130
* ndx - index on the page of the item being modified (item index)
131
* pagelsn - lsn on the page before the update
132
* off - offset in the old item where the new item is going.
133
* olditem - DBT that describes the part of the item being replaced.
134
* newitem - DBT of the new item.
135
* makedup - this was a replacement that made an item a duplicate.
139
WRLOCK pgno db_pgno_t lu
141
POINTER pagelsn DB_LSN * lu
145
ARG makedup u_int32_t lu
149
* Used when we empty the first page in a bucket and there are pages after
150
* it. The page after it gets copied into the bucket page (since bucket
151
* pages have to be in fixed locations).
152
* pgno: the bucket page
153
* pagelsn: the old LSN on the bucket page
154
* next_pgno: the page number of the next page
155
* nnext_pgno: page after next_pgno (may need to change its prev)
156
* nnextlsn: the LSN of nnext_pgno.
160
WRLOCK pgno db_pgno_t lu
161
POINTER pagelsn DB_LSN * lu
162
WRLOCK next_pgno db_pgno_t lu
163
POINTER nextlsn DB_LSN * lu
164
WRLOCKNZ nnext_pgno db_pgno_t lu
165
POINTER nnextlsn DB_LSN * lu
170
* This record logs the meta-data aspects of a split operation. It has enough
171
* information so that we can record both an individual page allocation as well
172
* as a group allocation which we do because in sub databases, the pages in
173
* a hash doubling, must be contiguous. If we do a group allocation, the
174
* number of pages allocated is bucket + 1, pgno is the page number of the
175
* first newly allocated bucket.
177
* bucket: Old maximum bucket number.
178
* mmpgno: Master meta-data page number (0 if same as mpgno).
179
* mmetalsn: Lsn of the master meta-data page.
180
* mpgno: Meta-data page number.
181
* metalsn: Lsn of the meta-data page.
182
* pgno: Page allocated to bucket + 1 (first newly allocated page)
183
* pagelsn: Lsn of either the first page allocated (if newalloc == 0) or
184
* the last page allocated (if newalloc == 1).
185
* newalloc: 1 indicates that this record did the actual allocation;
186
* 0 indicates that the pages were already allocated from a
187
* previous (failed) allocation.
191
ARG bucket u_int32_t lu
192
WRLOCK mmpgno db_pgno_t lu
193
POINTER mmetalsn DB_LSN * lu
194
WRLOCKNZ mpgno db_pgno_t lu
195
POINTER metalsn DB_LSN * lu
196
WRLOCK pgno db_pgno_t lu
197
POINTER pagelsn DB_LSN * lu
198
ARG newalloc u_int32_t lu
204
* This is used in conjunction with MPOOL_NEW_GROUP when we are creating
205
* a new database to make sure that we recreate or reclaim free pages
206
* when we allocate a chunk of contiguous ones during database creation.
208
* pgno: meta-data page number
209
* metalsn: meta-data lsn
210
* start_pgno: starting page number
211
* num: number of allocated pages
215
POINTER meta_lsn DB_LSN * lu
216
WRLOCK start_pgno db_pgno_t lu
218
ARG free db_pgno_t lu
222
* Records for backing out cursor adjustment.
223
* curadj - added or deleted a record or a dup
225
* pgno - page that was effected
226
* indx - indx of recrod effected.
227
* len - if a dup its length.
228
* dup_off - if a dup its offset
229
* add - 1 if add 0 if delete
230
* is_dup - 1 if dup 0 otherwise.
231
* order - order assigned to this deleted record or dup.
233
* chgpg - rmoved a page, move the records to a new page
234
* mode - CHGPG page was deleted or records move to new page.
235
* - SPLIT we split a bucket
236
* - DUP we convered to off page duplicates.
237
* old_pgno, new_pgno - old and new page numbers.
238
* old_index, new_index - old and new index numbers, NDX_INVALID if
239
* it effects all records on the page.
240
* For three opcodes new in 3.3 (DB_HAM_DELFIRSTPG, DELMIDPG,
241
* and DELLASTPG), we overload old_indx and new_indx to avoid
242
* needing a new log record type: old_indx stores the only
243
* indx of interest to these records, and new_indx stores the
244
* order that's assigned to the lowest deleted record we're
249
ARG pgno db_pgno_t lu
250
ARG indx u_int32_t lu
252
ARG dup_off u_int32_t lu
255
ARG order u_int32_t lu
260
ARG mode db_ham_mode ld
261
ARG old_pgno db_pgno_t lu
262
ARG new_pgno db_pgno_t lu
263
ARG old_indx u_int32_t lu
264
ARG new_indx u_int32_t lu