diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2007-07-30 11:58:31 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2007-07-30 11:58:31 +0300 |
commit | cab228435bde1b5496522c03a4ce9840f2ef3701 (patch) | |
tree | 2c37b65d176e2de097603333f4de071c31eeff3d /db/fileops | |
parent | 2d07882d45e9e575c00f8f402d4c7271bb65cfe9 (diff) | |
download | rpm-cab228435bde1b5496522c03a4ce9840f2ef3701.tar.gz rpm-cab228435bde1b5496522c03a4ce9840f2ef3701.tar.bz2 rpm-cab228435bde1b5496522c03a4ce9840f2ef3701.zip |
Update internal BDB to version 4.6.18.
Diffstat (limited to 'db/fileops')
-rw-r--r-- | db/fileops/fileops.src | 14 | ||||
-rw-r--r-- | db/fileops/fileops_auto.c | 88 | ||||
-rw-r--r-- | db/fileops/fileops_autop.c | 3 | ||||
-rw-r--r-- | db/fileops/fop_basic.c | 55 | ||||
-rw-r--r-- | db/fileops/fop_rec.c | 56 | ||||
-rw-r--r-- | db/fileops/fop_util.c | 217 |
6 files changed, 288 insertions, 145 deletions
diff --git a/db/fileops/fileops.src b/db/fileops/fileops.src index ce81e1513..4518dcf0e 100644 --- a/db/fileops/fileops.src +++ b/db/fileops/fileops.src @@ -1,10 +1,9 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2001-2006 - * Oracle Corporation. All rights reserved. + * Copyright (c) 2001,2007 Oracle. All rights reserved. * - * $Id: fileops.src,v 12.6 2006/08/24 14:46:03 bostic Exp $ + * $Id: fileops.src,v 12.10 2007/05/17 18:17:19 bostic Exp $ */ PREFIX __fop @@ -73,14 +72,23 @@ END * be interpreted via calls to __db_appname. The fileid is the 20-byte * DB fileid of the file being renamed. We need to check it on recovery * so that we don't inadvertently overwrite good files. + * + * There are two variants of this log record: one that must be both done + * and undone and one that is not undone (used for renaming tmp files, see + * SR #15119) + * + * These two record types use the same structure, read, and print functions, + * but have different recovery functions. */ BEGIN rename 42 146 +DUPLICATE rename_noundo 46 150 DBT oldname DBT s DBT newname DBT s DBT fileid DBT s ARG appname u_int32_t lu END + /* * File removal record. This is a DB-level log record that indicates * we've just completed some form of file removal. The purpose of this diff --git a/db/fileops/fileops_auto.c b/db/fileops/fileops_auto.c index 0da353b2b..5d903649e 100644 --- a/db/fileops/fileops_auto.c +++ b/db/fileops/fileops_auto.c @@ -140,6 +140,7 @@ __fop_create_log(dbenv, txnp, ret_lsnp, flags, *ret_lsnp = *rlsnp; } } else { + ret = 0; #ifdef DIAGNOSTIC /* * Set the debug bit if we are going to log non-durable @@ -149,10 +150,9 @@ __fop_create_log(dbenv, txnp, ret_lsnp, flags, rectype |= DB_debug_FLAG; memcpy(logrec.data, &rectype, sizeof(rectype)); - ret = __log_put(dbenv, - rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); -#else - ret = 0; + if (!IS_REP_CLIENT(dbenv)) + ret = __log_put(dbenv, + rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); #endif STAILQ_INSERT_HEAD(&txnp->logs, lr, links); F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); @@ -359,6 +359,7 @@ __fop_remove_log(dbenv, txnp, ret_lsnp, flags, *ret_lsnp = *rlsnp; } } else { + ret = 0; #ifdef DIAGNOSTIC /* * Set the debug bit if we are going to log non-durable @@ -368,10 +369,9 @@ __fop_remove_log(dbenv, txnp, ret_lsnp, flags, rectype |= DB_debug_FLAG; memcpy(logrec.data, &rectype, sizeof(rectype)); - ret = __log_put(dbenv, - rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); -#else - ret = 0; + if (!IS_REP_CLIENT(dbenv)) + ret = __log_put(dbenv, + rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); #endif STAILQ_INSERT_HEAD(&txnp->logs, lr, links); F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); @@ -606,6 +606,7 @@ __fop_write_log(dbenv, txnp, ret_lsnp, flags, *ret_lsnp = *rlsnp; } } else { + ret = 0; #ifdef DIAGNOSTIC /* * Set the debug bit if we are going to log non-durable @@ -615,10 +616,9 @@ __fop_write_log(dbenv, txnp, ret_lsnp, flags, rectype |= DB_debug_FLAG; memcpy(logrec.data, &rectype, sizeof(rectype)); - ret = __log_put(dbenv, - rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); -#else - ret = 0; + if (!IS_REP_CLIENT(dbenv)) + ret = __log_put(dbenv, + rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); #endif STAILQ_INSERT_HEAD(&txnp->logs, lr, links); F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); @@ -710,6 +710,16 @@ __fop_write_read(dbenv, recbuf, argpp) * PUBLIC: int __fop_rename_log __P((DB_ENV *, DB_TXN *, DB_LSN *, * PUBLIC: u_int32_t, const DBT *, const DBT *, const DBT *, u_int32_t)); */ +/* + * PUBLIC: int __fop_rename_noundo_log __P((DB_ENV *, DB_TXN *, + * PUBLIC: DB_LSN *, u_int32_t, const DBT *, const DBT *, const DBT *, + * PUBLIC: u_int32_t)); + */ +/* + * PUBLIC: int __fop_rename_int_log __P((DB_ENV *, DB_TXN *, + * PUBLIC: DB_LSN *, u_int32_t, const DBT *, const DBT *, const DBT *, + * PUBLIC: u_int32_t, u_int32_t)); + */ int __fop_rename_log(dbenv, txnp, ret_lsnp, flags, oldname, newname, fileid, appname) @@ -721,6 +731,39 @@ __fop_rename_log(dbenv, txnp, ret_lsnp, flags, const DBT *newname; const DBT *fileid; u_int32_t appname; + +{ + return (__fop_rename_int_log(dbenv, txnp, ret_lsnp, flags, + oldname, newname, fileid, appname, DB___fop_rename)); +} +int +__fop_rename_noundo_log(dbenv, txnp, ret_lsnp, flags, + oldname, newname, fileid, appname) + DB_ENV *dbenv; + DB_TXN *txnp; + DB_LSN *ret_lsnp; + u_int32_t flags; + const DBT *oldname; + const DBT *newname; + const DBT *fileid; + u_int32_t appname; + +{ + return (__fop_rename_int_log(dbenv, txnp, ret_lsnp, flags, + oldname, newname, fileid, appname, DB___fop_rename_noundo)); +} +int +__fop_rename_int_log(dbenv, txnp, ret_lsnp, flags, + oldname, newname, fileid, appname, type) + DB_ENV *dbenv; + DB_TXN *txnp; + DB_LSN *ret_lsnp; + u_int32_t flags; + const DBT *oldname; + const DBT *newname; + const DBT *fileid; + u_int32_t appname; + u_int32_t type; { DBT logrec; DB_TXNLOGREC *lr; @@ -732,7 +775,7 @@ __fop_rename_log(dbenv, txnp, ret_lsnp, flags, COMPQUIET(lr, NULL); - rectype = DB___fop_rename; + rectype = type; npad = 0; rlsnp = ret_lsnp; @@ -856,6 +899,7 @@ __fop_rename_log(dbenv, txnp, ret_lsnp, flags, *ret_lsnp = *rlsnp; } } else { + ret = 0; #ifdef DIAGNOSTIC /* * Set the debug bit if we are going to log non-durable @@ -865,10 +909,9 @@ __fop_rename_log(dbenv, txnp, ret_lsnp, flags, rectype |= DB_debug_FLAG; memcpy(logrec.data, &rectype, sizeof(rectype)); - ret = __log_put(dbenv, - rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); -#else - ret = 0; + if (!IS_REP_CLIENT(dbenv)) + ret = __log_put(dbenv, + rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); #endif STAILQ_INSERT_HEAD(&txnp->logs, lr, links); F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); @@ -1103,6 +1146,7 @@ __fop_file_remove_log(dbenv, txnp, ret_lsnp, flags, *ret_lsnp = *rlsnp; } } else { + ret = 0; #ifdef DIAGNOSTIC /* * Set the debug bit if we are going to log non-durable @@ -1112,10 +1156,9 @@ __fop_file_remove_log(dbenv, txnp, ret_lsnp, flags, rectype |= DB_debug_FLAG; memcpy(logrec.data, &rectype, sizeof(rectype)); - ret = __log_put(dbenv, - rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); -#else - ret = 0; + if (!IS_REP_CLIENT(dbenv)) + ret = __log_put(dbenv, + rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); #endif STAILQ_INSERT_HEAD(&txnp->logs, lr, links); F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); @@ -1223,6 +1266,9 @@ __fop_init_recover(dbenv, dtabp, dtabsizep) __fop_rename_recover, DB___fop_rename)) != 0) return (ret); if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, + __fop_rename_noundo_recover, DB___fop_rename_noundo)) != 0) + return (ret); + if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, __fop_file_remove_recover, DB___fop_file_remove)) != 0) return (ret); return (0); diff --git a/db/fileops/fileops_autop.c b/db/fileops/fileops_autop.c index e19167691..abf3ee535 100644 --- a/db/fileops/fileops_autop.c +++ b/db/fileops/fileops_autop.c @@ -282,6 +282,9 @@ __fop_init_print(dbenv, dtabp, dtabsizep) __fop_rename_print, DB___fop_rename)) != 0) return (ret); if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, + __fop_rename_print, DB___fop_rename_noundo)) != 0) + return (ret); + if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, __fop_file_remove_print, DB___fop_file_remove)) != 0) return (ret); return (0); diff --git a/db/fileops/fop_basic.c b/db/fileops/fop_basic.c index 9563ddbc1..7b3597ad2 100644 --- a/db/fileops/fop_basic.c +++ b/db/fileops/fop_basic.c @@ -1,10 +1,9 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2001-2006 - * Oracle Corporation. All rights reserved. + * Copyright (c) 2001,2007 Oracle. All rights reserved. * - * $Id: fop_basic.c,v 12.19 2006/09/19 15:06:59 bostic Exp $ + * $Id: fop_basic.c,v 12.25 2007/05/17 15:15:37 bostic Exp $ */ #include "db_config.h" @@ -82,7 +81,11 @@ __fop_create(dbenv, txn, fhpp, name, appname, mode, flags) if (mode == 0) mode = __db_omode(OWNER_RW); - if (DBENV_LOGGING(dbenv)) { + if (DBENV_LOGGING(dbenv) +#if !defined(DEBUG_WOP) + && txn != NULL +#endif + ) { DB_INIT_DBT(data, name, strlen(name) + 1); if ((ret = __fop_create_log(dbenv, txn, &lsn, flags | DB_FLUSH, @@ -95,7 +98,7 @@ __fop_create(dbenv, txn, fhpp, name, appname, mode, flags) if (fhpp == NULL) fhpp = &fhp; ret = __os_open( - dbenv, real_name, DB_OSO_CREATE | DB_OSO_EXCL, mode, fhpp); + dbenv, real_name, 0, DB_OSO_CREATE | DB_OSO_EXCL, mode, fhpp); err: DB_TEST_RECOVERY_LABEL @@ -138,7 +141,11 @@ __fop_remove(dbenv, txn, fileid, name, appname, flags) dbenv, fileid, NULL, real_name, NULL, 0)) != 0) goto err; } else { - if (DBENV_LOGGING(dbenv)) { + if (DBENV_LOGGING(dbenv) +#if !defined(DEBUG_WOP) + && txn != NULL +#endif + ) { memset(&fdbt, 0, sizeof(ndbt)); fdbt.data = fileid; fdbt.size = fileid == NULL ? 0 : DB_FILE_ID_LEN; @@ -170,7 +177,7 @@ err: if (real_name != NULL) * * PUBLIC: int __fop_write __P((DB_ENV *, * PUBLIC: DB_TXN *, const char *, APPNAME, DB_FH *, u_int32_t, db_pgno_t, - * PUBLIC: u_int32_t, u_int8_t *, u_int32_t, u_int32_t, u_int32_t)); + * PUBLIC: u_int32_t, void *, u_int32_t, u_int32_t, u_int32_t)); */ int __fop_write(dbenv, @@ -183,7 +190,7 @@ __fop_write(dbenv, u_int32_t pgsize; db_pgno_t pageno; u_int32_t off; - u_int8_t *buf; + void *buf; u_int32_t size, istmp, flags; { DB_LSN lsn; @@ -201,7 +208,11 @@ __fop_write(dbenv, __db_appname(dbenv, appname, name, 0, NULL, &real_name)) != 0) return (ret); - if (DBENV_LOGGING(dbenv)) { + if (DBENV_LOGGING(dbenv) +#if !defined(DEBUG_WOP) + && txn != NULL +#endif + ) { memset(&data, 0, sizeof(data)); data.data = buf; data.size = size; @@ -214,7 +225,7 @@ __fop_write(dbenv, if (fhp == NULL) { /* File isn't open; we need to reopen it. */ - if ((ret = __os_open(dbenv, real_name, 0, 0, &fhp)) != 0) + if ((ret = __os_open(dbenv, real_name, 0, 0, 0, &fhp)) != 0) goto err; local_open = 1; } @@ -240,17 +251,18 @@ err: if (local_open && * __fop_rename -- * Change a file's name. * - * PUBLIC: int __fop_rename __P((DB_ENV *, DB_TXN *, - * PUBLIC: const char *, const char *, u_int8_t *, APPNAME, u_int32_t)); + * PUBLIC: int __fop_rename __P((DB_ENV *, DB_TXN *, const char *, + * PUBLIC: const char *, u_int8_t *, APPNAME, int, u_int32_t)); */ int -__fop_rename(dbenv, txn, oldname, newname, fid, appname, flags) +__fop_rename(dbenv, txn, oldname, newname, fid, appname, with_undo, flags) DB_ENV *dbenv; DB_TXN *txn; const char *oldname; const char *newname; u_int8_t *fid; APPNAME appname; + int with_undo; u_int32_t flags; { DB_LSN lsn; @@ -264,14 +276,25 @@ __fop_rename(dbenv, txn, oldname, newname, fid, appname, flags) if ((ret = __db_appname(dbenv, appname, newname, 0, NULL, &n)) != 0) goto err; - if (DBENV_LOGGING(dbenv)) { + if (DBENV_LOGGING(dbenv) +#if !defined(DEBUG_WOP) + && txn != NULL +#endif + ) { DB_INIT_DBT(old, oldname, strlen(oldname) + 1); DB_INIT_DBT(new, newname, strlen(newname) + 1); memset(&fiddbt, 0, sizeof(fiddbt)); fiddbt.data = fid; fiddbt.size = DB_FILE_ID_LEN; - if ((ret = __fop_rename_log(dbenv, txn, &lsn, flags | DB_FLUSH, - &old, &new, &fiddbt, (u_int32_t)appname)) != 0) + if (with_undo) + ret = __fop_rename_log(dbenv, + txn, &lsn, flags | DB_FLUSH, + &old, &new, &fiddbt, (u_int32_t)appname); + else + ret = __fop_rename_noundo_log(dbenv, + txn, &lsn, flags | DB_FLUSH, + &old, &new, &fiddbt, (u_int32_t)appname); + if (ret != 0) goto err; } diff --git a/db/fileops/fop_rec.c b/db/fileops/fop_rec.c index eced8fd39..3de3c70ce 100644 --- a/db/fileops/fop_rec.c +++ b/db/fileops/fop_rec.c @@ -1,10 +1,9 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2001-2006 - * Oracle Corporation. All rights reserved. + * Copyright (c) 2001,2007 Oracle. All rights reserved. * - * $Id: fop_rec.c,v 12.12 2006/08/24 14:46:03 bostic Exp $ + * $Id: fop_rec.c,v 12.18 2007/05/17 15:15:37 bostic Exp $ */ #include "db_config.h" @@ -16,6 +15,9 @@ #include "dbinc/mp.h" #include "dbinc/txn.h" +static int __fop_rename_recover_int + __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *, int)); + /* * The transactional guarantees Berkeley DB provides for file * system level operations (database physical file create, delete, @@ -66,8 +68,8 @@ __fop_create_recover(dbenv, dbtp, lsnp, op, info) char *real_name; int ret; - real_name = NULL; COMPQUIET(info, NULL); + real_name = NULL; REC_PRINT(__fop_create_print); REC_NOOP_INTRO(__fop_create_read); @@ -78,8 +80,8 @@ __fop_create_recover(dbenv, dbtp, lsnp, op, info) 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, (int)argp->mode, &fhp)) == 0) + if ((ret = __os_open(dbenv, real_name, 0, + DB_OSO_CREATE, (int)argp->mode, &fhp)) == 0) (void)__os_closehandle(dbenv, fhp); else goto out; @@ -112,8 +114,8 @@ __fop_remove_recover(dbenv, dbtp, lsnp, op, info) char *real_name; int ret; - real_name = NULL; COMPQUIET(info, NULL); + real_name = NULL; REC_PRINT(__fop_remove_print); REC_NOOP_INTRO(__fop_remove_read); @@ -170,10 +172,17 @@ __fop_write_recover(dbenv, dbtp, lsnp, op, info) /* * __fop_rename_recover -- - * Recovery function for rename. + * Recovery functions for rename. There are two variants that + * both use the same utility function. Had we known about this on day + * one, we would have simply added a parameter. However, since we need + * to retain old records for backward compatibility (online-upgrade) + * wrapping the two seems like the right solution. * * PUBLIC: int __fop_rename_recover * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); + * + * PUBLIC: int __fop_rename_noundo_recover + * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); */ int __fop_rename_recover(dbenv, dbtp, lsnp, op, info) @@ -183,6 +192,29 @@ __fop_rename_recover(dbenv, dbtp, lsnp, op, info) db_recops op; void *info; { + return (__fop_rename_recover_int(dbenv, dbtp, lsnp, op, info, 1)); +} + +int +__fop_rename_noundo_recover(dbenv, dbtp, lsnp, op, info) + DB_ENV *dbenv; + DBT *dbtp; + DB_LSN *lsnp; + db_recops op; + void *info; +{ + return (__fop_rename_recover_int(dbenv, dbtp, lsnp, op, info, 0)); +} + +int +__fop_rename_recover_int(dbenv, dbtp, lsnp, op, info, undo) + DB_ENV *dbenv; + DBT *dbtp; + DB_LSN *lsnp; + db_recops op; + void *info; + int undo; +{ __fop_rename_args *argp; DB_FH *fhp; DBMETA *meta; @@ -221,7 +253,7 @@ __fop_rename_recover(dbenv, dbtp, lsnp, op, info) * way, shape or form, incorrect, so that we should not restore * it. */ - if (__os_open(dbenv, src, 0, 0, &fhp) != 0) + if (__os_open(dbenv, src, 0, 0, 0, &fhp) != 0) goto done; if (__fop_read_meta(dbenv, src, mbuf, DBMETASIZE, fhp, 1, NULL) != 0) @@ -240,7 +272,7 @@ __fop_rename_recover(dbenv, dbtp, lsnp, op, info) * file since the state of the world is beyond this * point. */ - if (__os_open(dbenv, real_new, 0, 0, &fhp) == 0 && + if (__os_open(dbenv, real_new, 0, 0, 0, &fhp) == 0 && __fop_read_meta(dbenv, src, mbuf, DBMETASIZE, fhp, 1, NULL) == 0 && __db_chk_meta(dbenv, NULL, meta, 1) == 0 && @@ -253,7 +285,7 @@ __fop_rename_recover(dbenv, dbtp, lsnp, op, info) } } - if (DB_UNDO(op)) + if (undo && DB_UNDO(op)) (void)__memp_nameop(dbenv, fileid, (const char *)argp->oldname.data, real_new, real_old, 0); if (DB_REDO(op)) @@ -320,7 +352,7 @@ __fop_file_remove_recover(dbenv, dbtp, lsnp, op, info) /* Verify that we are manipulating the correct file. */ len = 0; - if (__os_open(dbenv, real_name, 0, 0, &fhp) != 0 || + if (__os_open(dbenv, real_name, 0, 0, 0, &fhp) != 0 || (ret = __fop_read_meta(dbenv, real_name, mbuf, DBMETASIZE, fhp, 1, &len)) != 0) { /* diff --git a/db/fileops/fop_util.c b/db/fileops/fop_util.c index 9da9d4a43..6d45f4843 100644 --- a/db/fileops/fop_util.c +++ b/db/fileops/fop_util.c @@ -1,10 +1,9 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2001-2006 - * Oracle Corporation. All rights reserved. + * Copyright (c) 2001,2007 Oracle. All rights reserved. * - * $Id: fop_util.c,v 12.36 2006/09/19 15:06:59 bostic Exp $ + * $Id: fop_util.c,v 12.55 2007/07/17 07:29:05 mjc Exp $ */ #include "db_config.h" @@ -24,11 +23,11 @@ static int __fop_inmem_create __P((DB *, const char *, DB_TXN *, u_int32_t)); static int __fop_inmem_dummy __P((DB *, DB_TXN *, const char *, u_int8_t *)); static int __fop_inmem_read_meta __P((DB *, DB_TXN *, const char *, u_int32_t)); static int __fop_inmem_swap __P((DB *, DB *, DB_TXN *, - const char *, const char *, const char *, u_int32_t)); + const char *, const char *, const char *, DB_LOCKER *)); static int __fop_ondisk_dummy __P((DB *, DB_TXN *, const char *, u_int8_t *, u_int32_t)); static int __fop_ondisk_swap __P((DB *, DB *, DB_TXN *, - const char *, const char *, const char *, u_int32_t, u_int32_t)); + const char *, const char *, const char *, DB_LOCKER *, u_int32_t)); /* * Acquire the environment meta-data lock. The parameters are the @@ -93,14 +92,14 @@ static int __fop_ondisk_swap __P((DB *, DB *, DB_TXN *, * handle lock. * * PUBLIC: int __fop_lock_handle __P((DB_ENV *, - * PUBLIC: DB *, u_int32_t, db_lockmode_t, DB_LOCK *, u_int32_t)); + * PUBLIC: DB *, DB_LOCKER *, db_lockmode_t, DB_LOCK *, u_int32_t)); * */ int __fop_lock_handle(dbenv, dbp, locker, mode, elockp, flags) DB_ENV *dbenv; DB *dbp; - u_int32_t locker; + DB_LOCKER *locker; db_lockmode_t mode; DB_LOCK *elockp; u_int32_t flags; @@ -147,7 +146,7 @@ __fop_lock_handle(dbenv, dbp, locker, mode, elockp, flags) LOCK_INIT(*elockp); } - dbp->cur_lid = locker; + dbp->cur_locker = locker; return (ret); } @@ -208,10 +207,11 @@ __fop_file_setup(dbp, txn, name, mode, flags, retidp) DB_ENV *dbenv; DB_FH *fhp; DB_LOCK elock; + DB_LOCKER *locker; DB_TXN *stxn; DBTYPE save_type; size_t len; - u_int32_t dflags, locker, oflags; + u_int32_t dflags, oflags; u_int8_t mbuf[DBMETASIZE]; int created_locker, create_ok, ret, retries, t_ret, tmp_created; int truncating, was_inval; @@ -239,14 +239,14 @@ __fop_file_setup(dbp, txn, name, mode, flags, retidp) if (LOCKING_ON(dbenv) && !F_ISSET(dbp, DB_AM_COMPENSATE) && !F_ISSET(dbp, DB_AM_RECOVER) && - dbp->lid == DB_LOCK_INVALIDID) { - if ((ret = __lock_id(dbenv, &dbp->lid, NULL)) != 0) + dbp->locker == DB_LOCK_INVALIDID) { + if ((ret = __lock_id(dbenv, NULL, &dbp->locker)) != 0) goto err; created_locker = 1; } LOCK_INIT(dbp->handle_lock); - locker = txn == NULL ? dbp->lid : txn->txnid; + locker = txn == NULL ? dbp->locker : txn->locker; oflags = 0; if (F_ISSET(dbp, DB_AM_INMEM)) @@ -288,10 +288,10 @@ retry: if (name == NULL) ret = ENOENT; else if (F_ISSET(dbp, DB_AM_INMEM)) { - ret = __db_dbenv_mpool(dbp, name, flags); + ret = __db_env_mpool(dbp, name, flags); /* - * We are using __db_dbenv_open as a check for existence. - * However, db_dbenv_mpool does an actual open and there + * We are using __db_env_open as a check for existence. + * However, __db_env_mpool does an actual open and there * are scenarios where the object exists, but cannot be * opened, because our settings don't match those internally. * We need to check for that explicitly. We'll need the @@ -302,7 +302,7 @@ retry: was_inval = 1; save_type = dbp->type; dbp->type = DB_UNKNOWN; - ret = __db_dbenv_mpool(dbp, name, flags); + ret = __db_env_mpool(dbp, name, flags); dbp->type = save_type; } } else @@ -326,8 +326,8 @@ retry: */ /* Open file (if there is one). */ -reopen: if (!F_ISSET(dbp, DB_AM_INMEM) && - (ret = __os_open(dbenv, real_name, oflags, 0, &fhp)) != 0) +reopen: if (!F_ISSET(dbp, DB_AM_INMEM) && (ret = + __os_open(dbenv, real_name, 0, oflags, 0, &fhp)) != 0) goto err; /* Case 2: DB_TRUNCATE: we must do the creation in place. */ @@ -429,9 +429,10 @@ reopen: if (!F_ISSET(dbp, DB_AM_INMEM) && if ((ret = __db_refresh(dbp, txn, DB_NOSYNC, NULL, 1)) != 0) goto err; - ret = __db_dbenv_mpool(dbp, name, flags); + ret = __db_env_mpool(dbp, name, flags); } else - ret = __os_open(dbenv, real_name, 0, 0, &fhp); + ret = + __os_open(dbenv, real_name, 0, 0, 0, &fhp); if (ret != 0) { if ((ret = @@ -452,7 +453,7 @@ reopen: if (!F_ISSET(dbp, DB_AM_INMEM) && LF_ISSET(DB_FCNTL_LOCKING) && txn == NULL ? 1 : 0, &len)) != 0 || (ret = __db_meta_setup(dbenv, dbp, real_name, - (DBMETA *)mbuf, flags, 1)) != 0) + (DBMETA *)mbuf, flags, DB_CHK_META)) != 0) goto err; } @@ -532,7 +533,8 @@ reopen: if (!F_ISSET(dbp, DB_AM_INMEM) && (ret = __ENV_LPUT(dbenv, elock)) != 0) goto err; -create: if (txn != NULL && IS_REP_CLIENT(dbenv)) { +create: if (txn != NULL && IS_REP_CLIENT(dbenv) && + !F_ISSET(dbp, DB_AM_NOT_DURABLE)) { __db_errx(dbenv, "Transactional create on replication client disallowed"); ret = EINVAL; @@ -631,7 +633,7 @@ creat2: if (!F_ISSET(dbp, DB_AM_INMEM)) { dbp, locker, DB_LOCK_WRITE, &elock, NOWAIT_FLAG(txn))) != 0) goto err; if (tmpname != NULL && tmpname != name && (ret = __fop_rename(dbenv, - stxn, tmpname, name, dbp->fileid, DB_APP_DATA, dflags)) != 0) + stxn, tmpname, name, dbp->fileid, DB_APP_DATA, 1, dflags)) != 0) goto err; if (stxn != NULL) { @@ -659,8 +661,8 @@ err: CLOSE_HANDLE(dbp, fhp); (void)__ENV_LPUT(dbenv, dbp->handle_lock); (void)__ENV_LPUT(dbenv, elock); if (created_locker) { - (void)__lock_id_free(dbenv, dbp->lid); - dbp->lid = DB_LOCK_INVALIDID; + (void)__lock_id_free(dbenv, dbp->locker); + dbp->locker = NULL; } } @@ -787,12 +789,12 @@ __fop_subdb_setup(dbp, txn, mname, name, mode, flags) /* * Hijack the master's locker ID as well, so that our locks don't * conflict with the master's. Since we're closing the master, - * that lid would just have been freed anyway. Once we've gotten + * that locker would just have been freed anyway. Once we've gotten * the locker id, we need to acquire the handle lock for this * subdatabase. */ - dbp->lid = mdbp->lid; - mdbp->lid = DB_LOCK_INVALIDID; + dbp->locker = mdbp->locker; + mdbp->locker = NULL; DB_TEST_RECOVERY(dbp, DB_TEST_POSTLOG, ret, mname); @@ -806,7 +808,7 @@ __fop_subdb_setup(dbp, txn, mname, name, mode, flags) lkmode = F_ISSET(dbp, DB_AM_CREATED) || LF_ISSET(DB_WRITEOPEN) ? DB_LOCK_WRITE : DB_LOCK_READ; if ((ret = __fop_lock_handle(dbenv, dbp, - txn == NULL ? dbp->lid : txn->txnid, lkmode, NULL, + txn == NULL ? dbp->locker : txn->locker, lkmode, NULL, NOWAIT_FLAG(txn))) != 0) goto err; @@ -875,8 +877,8 @@ DB_TEST_RECOVERY_LABEL /* Now register the new event. */ if ((t_ret = __txn_lockevent(dbenv, txn, dbp, - &mdbp->handle_lock, dbp->lid == DB_LOCK_INVALIDID ? - mdbp->lid : dbp->lid)) != 0 && ret == 0) + &mdbp->handle_lock, dbp->locker == NULL ? + mdbp->locker : dbp->locker)) != 0 && ret == 0) ret = t_ret; } LOCK_INIT(mdbp->handle_lock); @@ -887,10 +889,22 @@ DB_TEST_RECOVERY_LABEL * mpool. If we're opening a subdb in an existing file, we can skip * the sync. */ - if ((t_ret =__db_close(mdbp, txn, - F_ISSET(dbp, DB_AM_CREATED_MSTR) ? 0 : DB_NOSYNC)) != 0 && - ret == 0) - ret = t_ret; + if (txn == NULL || F_ISSET(txn, TXN_CDSGROUP) || + F_ISSET(mdbp, DB_AM_RECOVER)) { + if ((t_ret = __db_close(mdbp, txn, + F_ISSET(dbp, DB_AM_CREATED_MSTR) ? 0 : DB_NOSYNC)) != 0 && + ret == 0) + ret = t_ret; + } else { + if (F_ISSET(dbp, DB_AM_CREATED_MSTR) && + (t_ret = __memp_fsync(mdbp->mpf)) != 0 && ret == 0) + ret = t_ret; + + if ((t_ret = + __txn_closeevent(dbenv, txn, mdbp)) != 0 && ret == 0) + ret = t_ret; + } + return (ret); } @@ -924,9 +938,9 @@ __fop_remove_setup(dbp, txn, name, flags) /* Create locker if necessary. */ retry: if (LOCKING_ON(dbenv)) { if (txn != NULL) - dbp->lid = txn->txnid; - else if (dbp->lid == DB_LOCK_INVALIDID) { - if ((ret = __lock_id(dbenv, &dbp->lid, NULL)) != 0) + dbp->locker = txn->locker; + else if (dbp->locker == DB_LOCK_INVALIDID) { + if ((ret = __lock_id(dbenv, NULL, &dbp->locker)) != 0) goto err; } } @@ -949,14 +963,14 @@ retry: if (LOCKING_ON(dbenv)) { * read the meta-data page and get the fileid so that we can lock * the handle. */ - GET_ENVLOCK(dbenv, dbp->lid, &elock); + GET_ENVLOCK(dbenv, dbp->locker, &elock); /* Open database. */ if (F_ISSET(dbp, DB_AM_INMEM)) { - if ((ret = __db_dbenv_mpool(dbp, name, flags)) == 0) + if ((ret = __db_env_mpool(dbp, name, flags)) == 0) ret = __os_strdup(dbenv, name, &dbp->dname); } else if (fhp == NULL) - ret = __os_open(dbenv, name, DB_OSO_RDONLY, 0, &fhp); + ret = __os_open(dbenv, name, 0, DB_OSO_RDONLY, 0, &fhp); if (ret != 0) goto err; @@ -965,8 +979,8 @@ retry: if (LOCKING_ON(dbenv)) { ret = __fop_inmem_read_meta(dbp, txn, name, flags); else if ((ret = __fop_read_meta(dbenv, name, mbuf, sizeof(mbuf), fhp, 0, NULL)) == 0) - ret = __db_meta_setup(dbenv, - dbp, name, (DBMETA *)mbuf, flags, 1); + ret = __db_meta_setup(dbenv, dbp, + name, (DBMETA *)mbuf, flags, DB_CHK_META | DB_CHK_NOLSN); if (ret != 0) goto err; @@ -977,7 +991,7 @@ retry: if (LOCKING_ON(dbenv)) { * prevent that. */ if ((ret = __fop_lock_handle(dbenv, - dbp, dbp->lid, DB_LOCK_WRITE, NULL, DB_LOCK_NOWAIT)) != 0) { + dbp, dbp->locker, DB_LOCK_WRITE, NULL, DB_LOCK_NOWAIT)) != 0) { /* * Close the file, block on the lock, clean up the dbp, and * then start all over again. @@ -990,7 +1004,7 @@ retry: if (LOCKING_ON(dbenv)) { (txn != NULL && F_ISSET(txn, TXN_NOWAIT))) goto err; else if ((ret = __fop_lock_handle(dbenv, - dbp, dbp->lid, DB_LOCK_WRITE, &elock, 0)) != 0) + dbp, dbp->locker, DB_LOCK_WRITE, &elock, 0)) != 0) goto err; if (F_ISSET(dbp, DB_AM_INMEM)) { @@ -998,7 +1012,7 @@ retry: if (LOCKING_ON(dbenv)) { (void)__db_refresh(dbp, txn, DB_NOSYNC, NULL, 1); } else { if (txn != NULL) - dbp->lid = DB_LOCK_INVALIDID; + dbp->locker = NULL; (void)__db_refresh(dbp, txn, DB_NOSYNC, NULL, 0); } goto retry; @@ -1096,7 +1110,6 @@ __fop_dummy(dbp, txn, old, new, flags) char *back; int ret, t_ret; u_int8_t mbuf[DBMETASIZE]; - u_int32_t locker; dbenv = dbp->dbenv; back = NULL; @@ -1104,7 +1117,6 @@ __fop_dummy(dbp, txn, old, new, flags) tmpdbp = NULL; DB_ASSERT(dbenv, txn != NULL); - locker = txn->txnid; /* * Begin sub transaction to encapsulate the rename. Note that we @@ -1118,7 +1130,7 @@ __fop_dummy(dbp, txn, old, new, flags) if ((ret = __db_backup_name(dbenv, new, stxn, &back)) != 0) goto err; /* Create a dummy dbp handle. */ - if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0) + if ((ret = __db_create_internal(&tmpdbp, dbenv, 0)) != 0) goto err; memset(mbuf, 0, sizeof(mbuf)); @@ -1130,8 +1142,9 @@ __fop_dummy(dbp, txn, old, new, flags) goto err; ret = F_ISSET(dbp, DB_AM_INMEM) ? - __fop_inmem_swap(dbp, tmpdbp, stxn, old, new, back, locker) : - __fop_ondisk_swap(dbp, tmpdbp, stxn, old, new, back, locker, flags); + __fop_inmem_swap(dbp, tmpdbp, stxn, old, new, back, txn->locker) : + __fop_ondisk_swap(dbp, + tmpdbp, stxn, old, new, back, txn->locker, flags); stxn = NULL; if (ret != 0) goto err; @@ -1190,7 +1203,7 @@ __fop_dbrename(dbp, old, new) * as that wouldn't be transaction-safe. We check explicitly * for ondisk files, but it's done memp_nameop for in-memory ones. */ - GET_ENVLOCK(dbenv, dbp->lid, &elock); + GET_ENVLOCK(dbenv, dbp->locker, &elock); ret = F_ISSET(dbp, DB_AM_INMEM) ? ENOENT : __os_exists(dbenv, real_new, NULL); @@ -1257,7 +1270,11 @@ __fop_inmem_create(dbp, name, txn, flags) (char *)p32, name, DB_FILE_ID_LEN - sizeof(u_int32_t)); dbp->preserve_fid = 1; - if (DBENV_LOGGING(dbenv) && dbp->log_filename != NULL) + if (DBENV_LOGGING(dbenv) && +#if !defined(DEBUG_WOP) && !defined(DIAGNOSTIC) + txn != NULL && +#endif + dbp->log_filename != NULL) memcpy(dbp->log_filename->ufid, dbp->fileid, DB_FILE_ID_LEN); } @@ -1266,10 +1283,14 @@ __fop_inmem_create(dbp, name, txn, flags) if ((ret = __memp_set_fileid(dbp->mpf, dbp->fileid)) != 0) goto err; - if ((ret = __db_dbenv_mpool(dbp, name, flags)) != 0) + if ((ret = __db_env_mpool(dbp, name, flags)) != 0) goto err; - if (name != NULL && DBENV_LOGGING(dbenv)) { + if (DBENV_LOGGING(dbenv) && +#if !defined(DEBUG_WOP) + txn != NULL && +#endif + name != NULL) { DB_INIT_DBT(name_dbt, name, strlen(name) + 1); memset(&fid_dbt, 0, sizeof(fid_dbt)); fid_dbt.data = dbp->fileid; @@ -1303,7 +1324,8 @@ __fop_inmem_read_meta(dbp, txn, name, flags) return (ret); ret = __db_meta_setup(dbp->dbenv, dbp, name, metap, flags, 1); - if ((t_ret = __memp_fput(dbp->mpf, metap, 0)) && ret == 0) + if ((t_ret = + __memp_fput(dbp->mpf, metap, dbp->priority)) && ret == 0) ret = t_ret; return (ret); @@ -1379,7 +1401,7 @@ __fop_inmem_dummy(dbp, txn, name, mbuf) memcpy(metap->uid, dbp->fileid, DB_FILE_ID_LEN); if ((t_ret = __memp_fput(dbp->mpf, metap, - ret == 0 ? 0 : DB_MPOOL_DISCARD)) != 0 && ret == 0) + ret == 0 ? dbp->priority : DB_PRIORITY_VERY_LOW)) != 0 && ret == 0) ret = t_ret; if (ret != 0) @@ -1395,7 +1417,8 @@ __fop_ondisk_swap(dbp, tmpdbp, txn, old, new, back, locker, flags) DB *dbp, *tmpdbp; DB_TXN *txn; const char *old, *new, *back; - u_int32_t locker, flags; + DB_LOCKER *locker; + u_int32_t flags; { DB_ENV *dbenv; DB_FH *fhp; @@ -1430,7 +1453,7 @@ retry: GET_ENVLOCK(dbenv, locker, &elock); * left a placeholder here. We need to check for that case * and allow this rename to succeed if that's the case. */ - if ((ret = __os_open(dbenv, realnew, 0, 0, &fhp)) != 0) + if ((ret = __os_open(dbenv, realnew, 0, 0, 0, &fhp)) != 0) goto err; if ((ret = __fop_read_meta(dbenv, realnew, mbuf, sizeof(mbuf), fhp, 0, NULL)) != 0 || @@ -1439,6 +1462,10 @@ retry: GET_ENVLOCK(dbenv, locker, &elock); ret = EEXIST; goto err; } + ret = __os_closehandle(dbenv, fhp); + fhp = NULL; + if (ret != 0) + goto err; /* * Now, try to acquire the handle lock. If the handle is locked @@ -1469,43 +1496,38 @@ retry: GET_ENVLOCK(dbenv, locker, &elock); if ((ret = __fop_lock_handle(dbenv, tmpdbp, locker, DB_LOCK_READ, NULL, DB_LOCK_NOWAIT)) != 0) { /* - * Someone holds a writelock. Try for the WRITELOCK - * and after we get it, retry. + * Someone holds a write-lock. Wait for the write-lock + * and after we get it, release it and start over. */ if ((ret = __fop_lock_handle(dbenv, tmpdbp, locker, DB_LOCK_WRITE, &elock, 0)) != 0) goto err; + if ((ret = + __lock_put(dbenv, &tmpdbp->handle_lock)) != 0) + goto err; + if ((ret = __db_refresh(tmpdbp, NULL, 0, NULL, 0)) != 0) + goto err; + goto retry; + } + /* We got the read lock; try to upgrade it. */ + ret = __fop_lock_handle(dbenv, + tmpdbp, locker, DB_LOCK_WRITE, + NULL, DB_LOCK_UPGRADE | DB_LOCK_NOWAIT); + if (ret != 0) { /* - * We now have the write lock; release it and start - * over. + * We did not get the writelock, so someone + * has the handle open. This is an error. */ (void)__lock_put(dbenv, &tmpdbp->handle_lock); - (void)__db_refresh(tmpdbp, NULL, 0, NULL, 0); - goto retry; - } else { - /* We got the read lock; try to upgrade it. */ - ret = __fop_lock_handle(dbenv, - tmpdbp, locker, DB_LOCK_WRITE, - NULL, DB_LOCK_UPGRADE | DB_LOCK_NOWAIT); - if (ret != 0) { - /* - * We did not get the writelock, so someone - * has the handle open. This is an error. - */ - (void)__lock_put(dbenv, &tmpdbp->handle_lock); - ret = EEXIST; - } else if (F_ISSET(tmpdbp, DB_AM_IN_RENAME)) - /* We got the lock and are renaming it. */ - ret = 0; - else { /* We got the lock, but the file exists. */ - (void)__lock_put(dbenv, &tmpdbp->handle_lock); - ret = EEXIST; - } + ret = EEXIST; + } else if (F_ISSET(tmpdbp, DB_AM_IN_RENAME)) + /* We got the lock and are renaming it. */ + ret = 0; + else { /* We got the lock, but the file exists. */ + (void)__lock_put(dbenv, &tmpdbp->handle_lock); + ret = EEXIST; } - if ((t_ret = __os_closehandle(dbenv, fhp)) != 0 && ret == 0) - ret = t_ret; - fhp = NULL; if (ret != 0) goto err; } @@ -1515,10 +1537,10 @@ retry: GET_ENVLOCK(dbenv, locker, &elock); * swap for the handle lock. */ if ((ret = __fop_rename(dbenv, - txn, old, new, dbp->fileid, DB_APP_DATA, dflags)) != 0) + txn, old, new, dbp->fileid, DB_APP_DATA, 1, dflags)) != 0) goto err; if ((ret = __fop_rename(dbenv, - txn, back, old, tmpdbp->fileid, DB_APP_DATA, dflags)) != 0) + txn, back, old, tmpdbp->fileid, DB_APP_DATA, 0, dflags)) != 0) goto err; if ((ret = __fop_lock_handle(dbenv, tmpdbp, locker, DB_LOCK_WRITE, &elock, NOWAIT_FLAG(txn))) != 0) @@ -1562,6 +1584,11 @@ err: if (txn != NULL) /* Ret must already be set, so void abort. */ (void)__txn_abort(txn); (void)__ENV_LPUT(dbenv, elock); + + if (fhp != NULL && + (t_ret = __os_closehandle(dbenv, fhp)) != 0 && ret == 0) + ret = t_ret; + if (realnew != NULL) __os_free(dbenv, realnew); if (realold != NULL) @@ -1574,7 +1601,7 @@ __fop_inmem_swap(olddbp, backdbp, txn, old, new, back, locker) DB *olddbp, *backdbp; DB_TXN *txn; const char *old, *new, *back; - u_int32_t locker; + DB_LOCKER *locker; { DB_ENV *dbenv; DB_LOCK elock; @@ -1587,12 +1614,12 @@ __fop_inmem_swap(olddbp, backdbp, txn, old, new, back, locker) dbenv = olddbp->dbenv; parent = txn->parent; retry: LOCK_INIT(elock); - if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0) + if ((ret = __db_create_internal(&tmpdbp, dbenv, 0)) != 0) return (ret); MAKE_INMEM(tmpdbp); GET_ENVLOCK(dbenv, locker, &elock); - if ((ret = __db_dbenv_mpool(tmpdbp, new, 0)) == 0) { + if ((ret = __db_env_mpool(tmpdbp, new, 0)) == 0) { /* * It is possible that the only reason this database exists is * because we've done a previous rename of it and we have @@ -1636,7 +1663,11 @@ retry: LOCK_INIT(elock); } /* Log the renames. */ - if (LOGGING_ON(dbenv)) { + if (LOGGING_ON(dbenv) +#ifndef DEBUG_WOP + && txn != NULL +#endif + ) { /* Rename old to new. */ DB_INIT_DBT(fid_dbt, olddbp->fileid, DB_FILE_ID_LEN); DB_INIT_DBT(n1_dbt, old, strlen(old) + 1); |