mariadb/bdb/hash/hash_meta.c

126 lines
2.5 KiB
C
Raw Normal View History

2001-03-05 01:42:05 +01:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 12:57:05 +01:00
* Copyright (c) 1999-2002
2001-03-05 01:42:05 +01:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 12:57:05 +01:00
static const char revid[] = "$Id: hash_meta.c,v 11.19 2002/06/03 14:22:15 ubell Exp $";
2001-03-05 01:42:05 +01:00
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
#include "db_int.h"
2002-10-30 12:57:05 +01:00
#include "dbinc/db_page.h"
#include "dbinc/db_shash.h"
#include "dbinc/hash.h"
#include "dbinc/lock.h"
2001-03-05 01:42:05 +01:00
/*
* Acquire the meta-data page.
*
* PUBLIC: int __ham_get_meta __P((DBC *));
*/
int
__ham_get_meta(dbc)
DBC *dbc;
{
DB *dbp;
2002-10-30 12:57:05 +01:00
DB_ENV *dbenv;
DB_MPOOLFILE *mpf;
HASH *hashp;
HASH_CURSOR *hcp;
2001-03-05 01:42:05 +01:00
int ret;
dbp = dbc->dbp;
2002-10-30 12:57:05 +01:00
dbenv = dbp->dbenv;
mpf = dbp->mpf;
2001-03-05 01:42:05 +01:00
hashp = dbp->h_internal;
2002-10-30 12:57:05 +01:00
hcp = (HASH_CURSOR *)dbc->internal;
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
if (dbenv != NULL &&
STD_LOCKING(dbc) && !F_ISSET(dbc, DBC_RECOVER | DBC_COMPENSATE)) {
2001-03-05 01:42:05 +01:00
dbc->lock.pgno = hashp->meta_pgno;
2002-10-30 12:57:05 +01:00
if ((ret = dbenv->lock_get(dbenv, dbc->locker,
2001-03-05 01:42:05 +01:00
DB_NONBLOCK(dbc) ? DB_LOCK_NOWAIT : 0,
&dbc->lock_dbt, DB_LOCK_READ, &hcp->hlock)) != 0)
return (ret);
}
2002-10-30 12:57:05 +01:00
if ((ret = mpf->get(mpf,
2001-03-05 01:42:05 +01:00
&hashp->meta_pgno, DB_MPOOL_CREATE, &(hcp->hdr))) != 0 &&
2002-10-30 12:57:05 +01:00
LOCK_ISSET(hcp->hlock))
(void)dbenv->lock_put(dbenv, &hcp->hlock);
2001-03-05 01:42:05 +01:00
return (ret);
}
/*
* Release the meta-data page.
*
* PUBLIC: int __ham_release_meta __P((DBC *));
*/
int
__ham_release_meta(dbc)
DBC *dbc;
{
2002-10-30 12:57:05 +01:00
DB_MPOOLFILE *mpf;
2001-03-05 01:42:05 +01:00
HASH_CURSOR *hcp;
2002-10-30 12:57:05 +01:00
mpf = dbc->dbp->mpf;
2001-03-05 01:42:05 +01:00
hcp = (HASH_CURSOR *)dbc->internal;
if (hcp->hdr)
2002-10-30 12:57:05 +01:00
(void)mpf->put(mpf, hcp->hdr,
2001-03-05 01:42:05 +01:00
F_ISSET(hcp, H_DIRTY) ? DB_MPOOL_DIRTY : 0);
hcp->hdr = NULL;
2002-10-30 12:57:05 +01:00
if (!F_ISSET(dbc, DBC_RECOVER | DBC_COMPENSATE) &&
dbc->txn == NULL && LOCK_ISSET(hcp->hlock))
(void)dbc->dbp->dbenv->lock_put(dbc->dbp->dbenv, &hcp->hlock);
2001-03-05 01:42:05 +01:00
F_CLR(hcp, H_DIRTY);
return (0);
}
/*
* Mark the meta-data page dirty.
*
* PUBLIC: int __ham_dirty_meta __P((DBC *));
*/
int
__ham_dirty_meta(dbc)
DBC *dbc;
{
DB *dbp;
2002-10-30 12:57:05 +01:00
DB_ENV *dbenv;
2001-03-05 01:42:05 +01:00
DB_LOCK _tmp;
HASH *hashp;
HASH_CURSOR *hcp;
int ret;
dbp = dbc->dbp;
hashp = dbp->h_internal;
hcp = (HASH_CURSOR *)dbc->internal;
ret = 0;
2002-10-30 12:57:05 +01:00
if (STD_LOCKING(dbc) && !F_ISSET(dbc, DBC_RECOVER | DBC_COMPENSATE)) {
dbenv = dbp->dbenv;
2001-03-05 01:42:05 +01:00
dbc->lock.pgno = hashp->meta_pgno;
2002-10-30 12:57:05 +01:00
if ((ret = dbenv->lock_get(dbenv, dbc->locker,
2001-03-05 01:42:05 +01:00
DB_NONBLOCK(dbc) ? DB_LOCK_NOWAIT : 0,
&dbc->lock_dbt, DB_LOCK_WRITE, &_tmp)) == 0) {
2002-10-30 12:57:05 +01:00
ret = dbenv->lock_put(dbenv, &hcp->hlock);
2001-03-05 01:42:05 +01:00
hcp->hlock = _tmp;
}
}
if (ret == 0)
F_SET(hcp, H_DIRTY);
return (ret);
}