summaryrefslogtreecommitdiff
path: root/db/btree/bt_open.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2007-07-16 16:48:14 +0300
committerPanu Matilainen <pmatilai@redhat.com>2007-07-16 16:48:14 +0300
commit2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79 (patch)
treee12ee52087506ac8c7a5eee83b17497d98df2d40 /db/btree/bt_open.c
parentb754fe19fd387ca5fe8e7c00ddaa25c898fa192f (diff)
downloadlibrpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.gz
librpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.bz2
librpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.zip
Update internal BDB to version 4.5.20
Diffstat (limited to 'db/btree/bt_open.c')
-rw-r--r--db/btree/bt_open.c95
1 files changed, 49 insertions, 46 deletions
diff --git a/db/btree/bt_open.c b/db/btree/bt_open.c
index e890c5dd7..916223258 100644
--- a/db/btree/bt_open.c
+++ b/db/btree/bt_open.c
@@ -1,8 +1,8 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2004
- * Sleepycat Software. All rights reserved.
+ * Copyright (c) 1996-2006
+ * Oracle Corporation. All rights reserved.
*/
/*
* Copyright (c) 1990, 1993, 1994, 1995, 1996
@@ -39,23 +39,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bt_open.c,v 11.92 2004/04/29 14:39:47 ubell Exp $
+ * $Id: bt_open.c,v 12.12 2006/08/24 14:44:44 bostic Exp $
*/
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/crypto.h"
#include "dbinc/db_page.h"
#include "dbinc/db_swap.h"
#include "dbinc/btree.h"
-#include "dbinc/db_shash.h"
#include "dbinc/lock.h"
#include "dbinc/log.h"
#include "dbinc/mp.h"
@@ -89,7 +82,7 @@ __bam_open(dbp, txn, name, base_pgno, flags)
* comparison routine to get it right.
*/
if (t->bt_compare == __bam_defcmp && t->bt_prefix != __bam_defpfx) {
- __db_err(dbp->dbenv,
+ __db_errx(dbp->dbenv,
"prefix comparison may not be specified for default comparison routine");
return (EINVAL);
}
@@ -100,7 +93,7 @@ __bam_open(dbp, txn, name, base_pgno, flags)
*/
if (B_MINKEY_TO_OVFLSIZE(dbp, t->bt_minkey, dbp->pgsize) >
B_MINKEY_TO_OVFLSIZE(dbp, DEFMINKEYPAGE, dbp->pgsize)) {
- __db_err(dbp->dbenv,
+ __db_errx(dbp->dbenv,
"bt_minkey value of %lu too high for page size of %lu",
(u_long)t->bt_minkey, (u_long)dbp->pgsize);
return (EINVAL);
@@ -137,7 +130,7 @@ __bam_metachk(dbp, name, btm)
switch (vers) {
case 6:
case 7:
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: btree version %lu requires a version upgrade",
name, (u_long)vers);
return (DB_OLD_VERSION);
@@ -145,7 +138,7 @@ __bam_metachk(dbp, name, btm)
case 9:
break;
default:
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: unsupported btree version: %lu", name, (u_long)vers);
return (EINVAL);
}
@@ -178,7 +171,7 @@ __bam_metachk(dbp, name, btm)
F_SET(dbp, DB_AM_DUP);
else
if (F_ISSET(dbp, DB_AM_DUP)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: DB_DUP specified to open method but not set in database",
name);
return (EINVAL);
@@ -194,7 +187,7 @@ __bam_metachk(dbp, name, btm)
return (ret);
} else
if (F_ISSET(dbp, DB_AM_RECNUM)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: DB_RECNUM specified to open method but not set in database",
name);
return (EINVAL);
@@ -206,7 +199,7 @@ __bam_metachk(dbp, name, btm)
F_SET(dbp, DB_AM_FIXEDLEN);
} else
if (F_ISSET(dbp, DB_AM_FIXEDLEN)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: DB_FIXEDLEN specified to open method but not set in database",
name);
return (EINVAL);
@@ -218,7 +211,7 @@ __bam_metachk(dbp, name, btm)
F_SET(dbp, DB_AM_RENUMBER);
} else
if (F_ISSET(dbp, DB_AM_RENUMBER)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: DB_RENUMBER specified to open method but not set in database",
name);
return (EINVAL);
@@ -228,7 +221,7 @@ __bam_metachk(dbp, name, btm)
F_SET(dbp, DB_AM_SUBDB);
else
if (F_ISSET(dbp, DB_AM_SUBDB)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: multiple databases specified but not supported by file",
name);
return (EINVAL);
@@ -240,7 +233,7 @@ __bam_metachk(dbp, name, btm)
F_SET(dbp, DB_AM_DUPSORT);
} else
if (dbp->dup_compare != NULL) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"%s: duplicate sort specified but not supported in database",
name);
return (EINVAL);
@@ -256,10 +249,10 @@ __bam_metachk(dbp, name, btm)
wrong_type:
if (dbp->type == DB_BTREE)
- __db_err(dbenv,
+ __db_errx(dbenv,
"open method type is Btree, database type is Recno");
else
- __db_err(dbenv,
+ __db_errx(dbenv,
"open method type is Recno, database type is Btree");
return (EINVAL);
}
@@ -285,6 +278,7 @@ __bam_read_root(dbp, txn, base_pgno, flags)
int ret, t_ret;
COMPQUIET(flags, 0);
+
meta = NULL;
t = dbp->bt_internal;
LOCK_INIT(metalock);
@@ -299,7 +293,7 @@ __bam_read_root(dbp, txn, base_pgno, flags)
if ((ret =
__db_lget(dbc, 0, base_pgno, DB_LOCK_READ, 0, &metalock)) != 0)
goto err;
- if ((ret = __memp_fget(mpf, &base_pgno, 0, &meta)) != 0)
+ if ((ret = __memp_fget(mpf, &base_pgno, dbc->txn, 0, &meta)) != 0)
goto err;
/*
@@ -311,7 +305,6 @@ __bam_read_root(dbp, txn, base_pgno, flags)
* metadata page will be created/initialized elsewhere.
*/
if (meta->dbmeta.magic == DB_BTREEMAGIC) {
- t->bt_maxkey = meta->maxkey;
t->bt_minkey = meta->minkey;
t->re_pad = (int)meta->re_pad;
t->re_len = meta->re_len;
@@ -319,8 +312,8 @@ __bam_read_root(dbp, txn, base_pgno, flags)
t->bt_meta = base_pgno;
t->bt_root = meta->root;
} else {
- DB_ASSERT(IS_RECOVERING(dbp->dbenv) ||
- F_ISSET(dbp, DB_AM_RECOVER));
+ DB_ASSERT(dbp->dbenv,
+ IS_RECOVERING(dbp->dbenv) || F_ISSET(dbp, DB_AM_RECOVER));
}
/*
@@ -359,8 +352,12 @@ __bam_init_meta(dbp, meta, pgno, lsnp)
db_pgno_t pgno;
DB_LSN *lsnp;
{
+ DB_ENV *dbenv;
BTREE *t;
+ dbenv = dbp->dbenv;
+ t = dbp->bt_internal;
+
memset(meta, 0, sizeof(BTMETA));
meta->dbmeta.lsn = *lsnp;
meta->dbmeta.pgno = pgno;
@@ -371,8 +368,8 @@ __bam_init_meta(dbp, meta, pgno, lsnp)
FLD_SET(meta->dbmeta.metaflags, DBMETA_CHKSUM);
if (F_ISSET(dbp, DB_AM_ENCRYPT)) {
meta->dbmeta.encrypt_alg =
- ((DB_CIPHER *)dbp->dbenv->crypto_handle)->alg;
- DB_ASSERT(meta->dbmeta.encrypt_alg != 0);
+ ((DB_CIPHER *)dbenv->crypto_handle)->alg;
+ DB_ASSERT(dbenv, meta->dbmeta.encrypt_alg != 0);
meta->crypto_magic = meta->dbmeta.magic;
}
meta->dbmeta.type = P_BTREEMETA;
@@ -394,8 +391,6 @@ __bam_init_meta(dbp, meta, pgno, lsnp)
F_SET(&meta->dbmeta, BTM_RECNO);
memcpy(meta->dbmeta.uid, dbp->fileid, DB_FILE_ID_LEN);
- t = dbp->bt_internal;
- meta->maxkey = t->bt_maxkey;
meta->minkey = t->bt_minkey;
meta->re_len = t->re_len;
meta->re_pad = (u_int32_t)t->re_pad;
@@ -428,7 +423,7 @@ __bam_new_file(dbp, txn, fhp, name)
DBT pdbt;
PAGE *root;
db_pgno_t pgno;
- int ret;
+ int ret, t_ret;
void *buf;
dbenv = dbp->dbenv;
@@ -437,30 +432,36 @@ __bam_new_file(dbp, txn, fhp, name)
meta = NULL;
buf = NULL;
- if (name == NULL) {
+ if (F_ISSET(dbp, DB_AM_INMEM)) {
/* Build the meta-data page. */
pgno = PGNO_BASE_MD;
- if ((ret =
- __memp_fget(mpf, &pgno, DB_MPOOL_CREATE, &meta)) != 0)
+ if ((ret = __memp_fget(mpf, &pgno, txn,
+ DB_MPOOL_CREATE | DB_MPOOL_DIRTY, &meta)) != 0)
return (ret);
LSN_NOT_LOGGED(lsn);
__bam_init_meta(dbp, meta, PGNO_BASE_MD, &lsn);
meta->root = 1;
meta->dbmeta.last_pgno = 1;
- ret = __memp_fput(mpf, meta, DB_MPOOL_DIRTY);
+ if ((ret =
+ __db_log_page(dbp, txn, &lsn, pgno, (PAGE *)meta)) != 0)
+ goto err;
+ ret = __memp_fput(mpf, meta, 0);
meta = NULL;
if (ret != 0)
goto err;
/* Build the root page. */
pgno = 1;
- if ((ret =
- __memp_fget(mpf, &pgno, DB_MPOOL_CREATE, &root)) != 0)
+ if ((ret = __memp_fget(mpf, &pgno,
+ txn, DB_MPOOL_CREATE, &root)) != 0)
goto err;
P_INIT(root, dbp->pgsize, 1, PGNO_INVALID, PGNO_INVALID,
LEAFLEVEL, dbp->type == DB_RECNO ? P_LRECNO : P_LBTREE);
LSN_NOT_LOGGED(root->lsn);
- ret = __memp_fput(mpf, root, DB_MPOOL_DIRTY);
+ if ((ret =
+ __db_log_page(dbp, txn, &root->lsn, pgno, root)) != 0)
+ goto err;
+ ret = __memp_fput(mpf, root, 0);
root = NULL;
if (ret != 0)
goto err;
@@ -509,10 +510,12 @@ __bam_new_file(dbp, txn, fhp, name)
err: if (buf != NULL)
__os_free(dbenv, buf);
else {
- if (meta != NULL)
- (void)__memp_fput(mpf, meta, 0);
- if (root != NULL)
- (void)__memp_fput(mpf, root, 0);
+ if (meta != NULL &&
+ (t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
+ ret = t_ret;
+ if (root != NULL &&
+ (t_ret = __memp_fput(mpf, root, 0)) != 0 && ret == 0)
+ ret = t_ret;
}
return (ret);
}
@@ -551,8 +554,8 @@ __bam_new_subdb(mdbp, dbp, txn)
if ((ret = __db_lget(dbc,
0, dbp->meta_pgno, DB_LOCK_WRITE, 0, &metalock)) != 0)
goto err;
- if ((ret =
- __memp_fget(mpf, &dbp->meta_pgno, DB_MPOOL_CREATE, &meta)) != 0)
+ if ((ret = __memp_fget(mpf, &dbp->meta_pgno,
+ txn, DB_MPOOL_CREATE, &meta)) != 0)
goto err;
/* Build meta-data page. */
@@ -579,10 +582,10 @@ __bam_new_subdb(mdbp, dbp, txn)
goto err;
/* Release the metadata and root pages. */
- if ((ret = __memp_fput(mpf, meta, DB_MPOOL_DIRTY)) != 0)
+ if ((ret = __memp_fput(mpf, meta, 0)) != 0)
goto err;
meta = NULL;
- if ((ret = __memp_fput(mpf, root, DB_MPOOL_DIRTY)) != 0)
+ if ((ret = __memp_fput(mpf, root, 0)) != 0)
goto err;
root = NULL;
err: