1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2001-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: fop_rec.c,v 1.1.1.1 2003/11/20 22:13:30 toshok Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <string.h>
#endif
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/fop.h"
#include "dbinc/db_am.h"
#include "dbinc/txn.h"
/*
* __fop_create_recover --
* Recovery function for create.
*
* PUBLIC: int __fop_create_recover
* PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__fop_create_recover(dbenv, dbtp, lsnp, op, info)
DB_ENV *dbenv;
DBT *dbtp;
DB_LSN *lsnp;
db_recops op;
void *info;
{
DB_FH fh;
__fop_create_args *argp;
char *real_name;
int ret;
real_name = NULL;
COMPQUIET(info, NULL);
REC_PRINT(__fop_create_print);
REC_NOOP_INTRO(__fop_create_read);
if ((ret = __db_appname(dbenv, (APPNAME)argp->appname,
(const char *)argp->name.data, 0, NULL, &real_name)) != 0)
goto out;
if (DB_UNDO(op))
(void)__os_unlink(dbenv, real_name);
else if (DB_REDO(op))
if ((ret = __os_open(dbenv, real_name,
DB_OSO_CREATE | DB_OSO_EXCL, argp->mode, &fh)) == 0)
__os_closehandle(dbenv, &fh);
*lsnp = argp->prev_lsn;
out: if (real_name != NULL)
__os_free(dbenv, real_name);
REC_NOOP_CLOSE;
}
/*
* __fop_remove_recover --
* Recovery function for remove.
*
* PUBLIC: int __fop_remove_recover
* PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__fop_remove_recover(dbenv, dbtp, lsnp, op, info)
DB_ENV *dbenv;
DBT *dbtp;
DB_LSN *lsnp;
db_recops op;
void *info;
{
__fop_remove_args *argp;
char *real_name;
int ret;
real_name = NULL;
COMPQUIET(info, NULL);
REC_PRINT(__fop_remove_print);
REC_NOOP_INTRO(__fop_remove_read);
if ((ret = __db_appname(dbenv, (APPNAME)argp->appname,
(const char *)argp->name.data, 0, NULL, &real_name)) != 0)
goto out;
if (DB_REDO(op) && (ret = dbenv->memp_nameop(dbenv,
(u_int8_t *)argp->fid.data, NULL, real_name, NULL)) != 0)
goto out;
*lsnp = argp->prev_lsn;
out: if (real_name != NULL)
__os_free(dbenv, real_name);
REC_NOOP_CLOSE;
}
/*
* __fop_write_recover --
* Recovery function for writechunk.
*
* PUBLIC: int __fop_write_recover
* PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__fop_write_recover(dbenv, dbtp, lsnp, op, info)
DB_ENV *dbenv;
DBT *dbtp;
DB_LSN *lsnp;
db_recops op;
void *info;
{
__fop_write_args *argp;
int ret;
COMPQUIET(info, NULL);
REC_PRINT(__fop_write_print);
REC_NOOP_INTRO(__fop_write_read);
if (DB_UNDO(op))
DB_ASSERT(argp->flag != 0);
else if (DB_REDO(op))
ret = __fop_write(dbenv,
argp->txnid, argp->name.data, argp->appname, NULL,
argp->offset, argp->page.data, argp->page.size, argp->flag);
*lsnp = argp->prev_lsn;
REC_NOOP_CLOSE;
}
/*
* __fop_rename_recover --
* Recovery function for rename.
*
* PUBLIC: int __fop_rename_recover
* PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__fop_rename_recover(dbenv, dbtp, lsnp, op, info)
DB_ENV *dbenv;
DBT *dbtp;
DB_LSN *lsnp;
db_recops op;
void *info;
{
__fop_rename_args *argp;
DBMETA *meta;
char *real_new, *real_old, *src;
int ret;
u_int8_t *fileid, mbuf[DBMETASIZE];
real_new = NULL;
real_old = NULL;
ret = 0;
meta = (DBMETA *)&mbuf[0];
COMPQUIET(info, NULL);
REC_PRINT(__fop_rename_print);
REC_NOOP_INTRO(__fop_rename_read);
fileid = argp->fileid.data;
if ((ret = __db_appname(dbenv, (APPNAME)argp->appname,
(const char *)argp->newname.data, 0, NULL, &real_new)) != 0)
goto out;
if ((ret = __db_appname(dbenv, (APPNAME)argp->appname,
(const char *)argp->oldname.data, 0, NULL, &real_old)) != 0)
goto out;
/*
* Verify that we are manipulating the correct file. We should always
* be OK on an ABORT or an APPLY, but during recovery, we have to
* check.
*/
if (op != DB_TXN_ABORT && op != DB_TXN_APPLY) {
src = DB_UNDO(op) ? real_new : real_old;
/*
* Interpret any error as meaning that the file either doesn't
* exist, doesn't have a meta-data page, or is in some other
* way, shape or form, incorrect, so that we should not restore
* it.
*/
if (__fop_read_meta(
dbenv, src, mbuf, DBMETASIZE, NULL, 1, NULL, 0) != 0)
goto done;
if (__db_chk_meta(dbenv, NULL, meta, 1) != 0)
goto done;
if (memcmp(argp->fileid.data, meta->uid, DB_FILE_ID_LEN) != 0)
goto done;
}
if (DB_UNDO(op))
(void)dbenv->memp_nameop(dbenv, fileid,
(const char *)argp->oldname.data, real_new, real_old);
if (DB_REDO(op))
(void)dbenv->memp_nameop(dbenv, fileid,
(const char *)argp->newname.data, real_old, real_new);
done: *lsnp = argp->prev_lsn;
out: if (real_new != NULL)
__os_free(dbenv, real_new);
if (real_old != NULL)
__os_free(dbenv, real_old);
REC_NOOP_CLOSE;
}
/*
* __fop_file_remove_recover --
* Recovery function for file_remove. On the REDO pass, we need to
* make sure no one recreated the file while we weren't looking. On an
* undo pass must check if the file we are interested in is the one that
* exists and then set the status of the child transaction depending on
* what we find out.
*
* PUBLIC: int __fop_file_remove_recover
* PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__fop_file_remove_recover(dbenv, dbtp, lsnp, op, info)
DB_ENV *dbenv;
DBT *dbtp;
DB_LSN *lsnp;
db_recops op;
void *info;
{
__fop_file_remove_args *argp;
DBMETA *meta;
char *real_name;
int is_real, is_tmp, ret;
size_t len;
u_int8_t mbuf[DBMETASIZE];
u_int32_t cstat;
real_name = NULL;
is_real = is_tmp = 0;
meta = (DBMETA *)&mbuf[0];
REC_PRINT(__fop_file_remove_print);
REC_NOOP_INTRO(__fop_file_remove_read);
/*
* This record is only interesting on the backward, forward, and
* apply phases.
*/
if (op != DB_TXN_BACKWARD_ROLL &&
op != DB_TXN_FORWARD_ROLL && op != DB_TXN_APPLY)
goto done;
if ((ret = __db_appname(dbenv,
(APPNAME)argp->appname, argp->name.data, 0, NULL, &real_name)) != 0)
goto out;
/* Verify that we are manipulating the correct file. */
if ((ret = __fop_read_meta(dbenv,
real_name, mbuf, DBMETASIZE, NULL, 1, &len, 0)) != 0) {
/*
* If len is non-zero, then the file exists and has something
* in it, but that something isn't a full meta-data page, so
* this is very bad. Bail out!
*/
if (len != 0)
goto out;
/* File does not exist. */
cstat = TXN_EXPECTED;
} else {
/*
* We can ignore errors here since we'll simply fail the
* checks below and assume this is the wrong file.
*/
(void)__db_chk_meta(dbenv, NULL, meta, 1);
is_real =
memcmp(argp->real_fid.data, meta->uid, DB_FILE_ID_LEN) == 0;
is_tmp =
memcmp(argp->tmp_fid.data, meta->uid, DB_FILE_ID_LEN) == 0;
if (!is_real && !is_tmp)
/* File exists, but isn't what we were removing. */
cstat = TXN_IGNORE;
else
/* File exists and is the one that we were removing. */
cstat = TXN_COMMIT;
}
if (DB_UNDO(op)) {
/* On the backward pass, we leave a note for the child txn. */
if ((ret = __db_txnlist_update(dbenv,
info, argp->child, cstat, NULL)) == DB_NOTFOUND)
ret = __db_txnlist_add(dbenv,
info, argp->child, cstat, NULL);
} else if (DB_REDO(op)) {
/*
* On the forward pass, check if someone recreated the
* file while we weren't looking.
*/
if (cstat == TXN_COMMIT)
(void)dbenv->memp_nameop(dbenv,
is_real ? argp->real_fid.data : argp->tmp_fid.data,
NULL, real_name, NULL);
}
done: *lsnp = argp->prev_lsn;
ret = 0;
out: if (real_name != NULL)
__os_free(dbenv, real_name);
REC_NOOP_CLOSE;
}
|