]>
git.ipfire.org Git - thirdparty/glibc.git/blob - db2/log/log_rec.c
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
8 * Copyright (c) 1995, 1996
9 * The President and Fellows of Harvard University. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 static const char sccsid
[] = "@(#)log_rec.c 10.16 (Sleepycat) 1/17/98";
46 #ifndef NO_SYSTEM_INCLUDES
47 #include <sys/types.h>
59 #include "db_dispatch.h"
60 #include "common_ext.h"
62 static int __log_open_file
__P((DB_LOG
*,
63 u_int8_t
*, char *, DBTYPE
, u_int32_t
));
66 * PUBLIC: int __log_register_recover
67 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
70 __log_register_recover(logp
, dbtp
, lsnp
, redo
, info
)
77 __log_register_args
*argp
;
81 __log_register_print(logp
, dbtp
, lsnp
, redo
, info
);
83 COMPQUIET(info
, NULL
);
84 COMPQUIET(lsnp
, NULL
);
86 F_SET(logp
, DB_AM_RECOVER
);
88 if ((ret
= __log_register_read(dbtp
->data
, &argp
)) != 0)
91 if ((argp
->opcode
== LOG_CHECKPOINT
&& redo
== TXN_OPENFILES
) ||
92 (argp
->opcode
== LOG_OPEN
&&
93 (redo
== TXN_REDO
|| redo
== TXN_OPENFILES
||
94 redo
== TXN_FORWARD_ROLL
)) ||
95 (argp
->opcode
== LOG_CLOSE
&&
96 (redo
== TXN_UNDO
|| redo
== TXN_BACKWARD_ROLL
))) {
98 * If we are redoing an open or undoing a close, then we need
101 ret
= __log_open_file(logp
,
102 argp
->uid
.data
, argp
->name
.data
, argp
->ftype
, argp
->id
);
104 if (redo
== TXN_OPENFILES
)
105 __db_err(logp
->dbenv
,
106 "warning: file %s not found",
110 } else if (argp
->opcode
!= LOG_CHECKPOINT
) {
112 * If we are redoing a close or undoing an open, then we need
115 * If the file is deleted, then we can just ignore this close.
116 * Otherwise, we'd better have a valid dbp that we should either
117 * close or whose reference count should be decremented.
119 LOCK_LOGTHREAD(logp
);
120 if (logp
->dbentry
[argp
->id
].dbp
== NULL
) {
121 if (!logp
->dbentry
[argp
->id
].deleted
)
123 } else if (--logp
->dbentry
[argp
->id
].refcount
== 0) {
124 ret
= logp
->dbentry
[argp
->id
].dbp
->close(
125 logp
->dbentry
[argp
->id
].dbp
, 0);
126 logp
->dbentry
[argp
->id
].dbp
= NULL
;
128 UNLOCK_LOGTHREAD(logp
);
131 out
: F_CLR(logp
, DB_AM_RECOVER
);
137 /* Hand coded routines. */
140 * Called during log_register recovery. Make sure that we have an
141 * entry in the dbentry table for this ndx.
142 * Returns 0 on success, non-zero on error.
145 __log_open_file(lp
, uid
, name
, ftype
, ndx
)
156 if (ndx
< lp
->dbentry_cnt
&&
157 (lp
->dbentry
[ndx
].deleted
== 1 || lp
->dbentry
[ndx
].dbp
!= NULL
)) {
158 lp
->dbentry
[ndx
].refcount
++;
160 UNLOCK_LOGTHREAD(lp
);
163 UNLOCK_LOGTHREAD(lp
);
165 /* Need to open file. */
167 if ((ret
= db_open(name
, ftype
, 0, 0, lp
->dbenv
, NULL
, &dbp
)) == 0) {
169 * Verify that we are opening the same file that we were
170 * referring to when we wrote this log record.
172 if (memcmp(uid
, dbp
->lock
.fileid
, DB_FILE_ID_LEN
) != 0) {
173 (void)dbp
->close(dbp
, 0);
179 if (ret
== 0 || ret
== ENOENT
)
180 (void)__log_add_logid(lp
, dbp
, ndx
);
186 * This function returns:
187 * 0 SUCCESS (the entry was not previously set and is now set or the
188 * entry was previously set and we just inced the ref count.
189 * >0 on system error (returns errno value).
190 * PUBLIC: int __log_add_logid __P((DB_LOG *, DB *, u_int32_t));
193 __log_add_logid(logp
, dbp
, ndx
)
198 DB_ENTRY
*temp_entryp
;
204 LOCK_LOGTHREAD(logp
);
206 * Check if we need to grow the table.
208 if (logp
->dbentry_cnt
<= ndx
) {
209 if (logp
->dbentry_cnt
== 0) {
210 logp
->dbentry
= (DB_ENTRY
*)
211 __db_malloc(DB_GROW_SIZE
* sizeof(DB_ENTRY
));
212 if (logp
->dbentry
== NULL
) {
217 temp_entryp
= (DB_ENTRY
*)__db_realloc(logp
->dbentry
,
218 (DB_GROW_SIZE
+ logp
->dbentry_cnt
) *
220 if (temp_entryp
== NULL
) {
224 logp
->dbentry
= temp_entryp
;
227 /* Initialize the new entries. */
228 for (i
= logp
->dbentry_cnt
;
229 i
< logp
->dbentry_cnt
+ DB_GROW_SIZE
; i
++) {
230 logp
->dbentry
[i
].dbp
= NULL
;
231 logp
->dbentry
[i
].deleted
= 0;
234 logp
->dbentry_cnt
+= DB_GROW_SIZE
;
237 if (logp
->dbentry
[ndx
].deleted
== 0 && logp
->dbentry
[ndx
].dbp
== NULL
) {
238 logp
->dbentry
[ndx
].dbp
= dbp
;
239 logp
->dbentry
[ndx
].refcount
= 1;
240 logp
->dbentry
[ndx
].deleted
= dbp
== NULL
;
242 logp
->dbentry
[ndx
].refcount
++;
244 err
: UNLOCK_LOGTHREAD(logp
);
250 * __db_fileid_to_db --
251 * Return the DB corresponding to the specified fileid.
253 * PUBLIC: int __db_fileid_to_db __P((DB_LOG *, DB **, u_int32_t));
256 __db_fileid_to_db(logp
, dbpp
, ndx
)
264 LOCK_LOGTHREAD(logp
);
267 * Return DB_DELETED if the file has been deleted
268 * (it's not an error).
270 if (logp
->dbentry
[ndx
].deleted
) {
276 * Otherwise return 0, but if we don't have a corresponding DB,
279 if ((*dbpp
= logp
->dbentry
[ndx
].dbp
) == NULL
)
282 err
: UNLOCK_LOGTHREAD(logp
);
287 * Close files that were opened by the recovery daemon.
289 * PUBLIC: void __log_close_files __P((DB_LOG *));
292 __log_close_files(logp
)
297 LOCK_LOGTHREAD(logp
);
298 for (i
= 0; i
< logp
->dbentry_cnt
; i
++)
299 if (logp
->dbentry
[i
].dbp
)
300 logp
->dbentry
[i
].dbp
->close(logp
->dbentry
[i
].dbp
, 0);
301 UNLOCK_LOGTHREAD(logp
);
305 * PUBLIC: void __log_rem_logid __P((DB_LOG *, u_int32_t));
308 __log_rem_logid(logp
, ndx
)
312 LOCK_LOGTHREAD(logp
);
313 if (--logp
->dbentry
[ndx
].refcount
== 0) {
314 logp
->dbentry
[ndx
].dbp
= NULL
;
315 logp
->dbentry
[ndx
].deleted
= 0;
317 UNLOCK_LOGTHREAD(logp
);