00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1999, 2000 00005 * Sleepycat Software. All rights reserved. 00006 */ 00007 00008 #include "config.h" 00009 00010 #ifndef lint 00011 static const char revid[] = "$Id: hash__meta_8c-source.html,v 1.1 2008年06月08日 10:19:32 sebdiaz Exp $"; 00012 #endif /* not lint */ 00013 00014 #ifndef NO_SYSTEM_INCLUDES 00015 #include <sys/types.h> 00016 #include <errno.h> 00017 #endif 00018 00019 #include "db_int.h" 00020 #include "db_page.h" 00021 #include "hash.h" 00022 #include "db_shash.h" 00023 #include "lock.h" 00024 #include "txn.h" 00025 00026 /* 00027 * Acquire the meta-data page. 00028 * 00029 * PUBLIC: int CDB___ham_get_meta __P((DBC *)); 00030 */ 00031 int 00032 CDB___ham_get_meta(dbc) 00033 DBC *dbc; 00034 { 00035 HASH_CURSOR *hcp; 00036 HASH *hashp; 00037 DB *dbp; 00038 int ret; 00039 00040 hcp = (HASH_CURSOR *)dbc->internal; 00041 dbp = dbc->dbp; 00042 hashp = dbp->h_internal; 00043 00044 if (dbp->dbenv != NULL && 00045 STD_LOCKING(dbc) && !F_ISSET(dbc, DBC_RECOVER)) { 00046 dbc->lock.pgno = hashp->meta_pgno; 00047 if ((ret = CDB_lock_get(dbp->dbenv, dbc->locker, 00048 DB_NONBLOCK(dbc) ? DB_LOCK_NOWAIT : 0, 00049 &dbc->lock_dbt, DB_LOCK_READ, &hcp->hlock)) != 0) 00050 return (ret); 00051 } 00052 00053 if ((ret = CDB___ham_get_page(dbc->dbp, 00054 hashp->meta_pgno, (PAGE **)&(hcp->hdr))) != 0 && 00055 hcp->hlock.off != LOCK_INVALID) { 00056 (void)CDB_lock_put(dbc->dbp->dbenv, &hcp->hlock); 00057 hcp->hlock.off = LOCK_INVALID; 00058 } 00059 00060 return (ret); 00061 } 00062 00063 /* 00064 * Release the meta-data page. 00065 * 00066 * PUBLIC: int CDB___ham_release_meta __P((DBC *)); 00067 */ 00068 int 00069 CDB___ham_release_meta(dbc) 00070 DBC *dbc; 00071 { 00072 HASH_CURSOR *hcp; 00073 00074 hcp = (HASH_CURSOR *)dbc->internal; 00075 00076 if (hcp->hdr) 00077 (void)CDB___ham_put_page(dbc->dbp, (PAGE *)hcp->hdr, 00078 F_ISSET(hcp, H_DIRTY) ? 1 : 0); 00079 hcp->hdr = NULL; 00080 if (!F_ISSET(dbc, DBC_RECOVER) && 00081 dbc->txn == NULL && hcp->hlock.off != LOCK_INVALID) 00082 (void)CDB_lock_put(dbc->dbp->dbenv, &hcp->hlock); 00083 hcp->hlock.off = LOCK_INVALID; 00084 F_CLR(hcp, H_DIRTY); 00085 00086 return (0); 00087 } 00088 00089 /* 00090 * Mark the meta-data page dirty. 00091 * 00092 * PUBLIC: int CDB___ham_dirty_meta __P((DBC *)); 00093 */ 00094 int 00095 CDB___ham_dirty_meta(dbc) 00096 DBC *dbc; 00097 { 00098 DB *dbp; 00099 DB_LOCK _tmp; 00100 HASH *hashp; 00101 HASH_CURSOR *hcp; 00102 int ret; 00103 00104 dbp = dbc->dbp; 00105 hashp = dbp->h_internal; 00106 hcp = (HASH_CURSOR *)dbc->internal; 00107 00108 ret = 0; 00109 if (STD_LOCKING(dbc) && !F_ISSET(dbc, DBC_RECOVER)) { 00110 dbc->lock.pgno = hashp->meta_pgno; 00111 if ((ret = CDB_lock_get(dbp->dbenv, dbc->locker, 00112 DB_NONBLOCK(dbc) ? DB_LOCK_NOWAIT : 0, 00113 &dbc->lock_dbt, DB_LOCK_WRITE, &_tmp)) == 0) { 00114 ret = CDB_lock_put(dbp->dbenv, &hcp->hlock); 00115 hcp->hlock = _tmp; 00116 } 00117 } 00118 00119 if (ret == 0) 00120 F_SET(hcp, H_DIRTY); 00121 return (ret); 00122 }