diff options
Diffstat (limited to 'db2/hash')
-rw-r--r-- | db2/hash/hash.c | 90 | ||||
-rw-r--r-- | db2/hash/hash_auto.c | 14 | ||||
-rw-r--r-- | db2/hash/hash_conv.c | 22 | ||||
-rw-r--r-- | db2/hash/hash_dup.c | 49 | ||||
-rw-r--r-- | db2/hash/hash_func.c | 6 | ||||
-rw-r--r-- | db2/hash/hash_page.c | 69 | ||||
-rw-r--r-- | db2/hash/hash_rec.c | 12 |
7 files changed, 143 insertions, 119 deletions
diff --git a/db2/hash/hash.c b/db2/hash/hash.c index 6d8c40057d..d986e08087 100644 --- a/db2/hash/hash.c +++ b/db2/hash/hash.c @@ -47,7 +47,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash.c 10.25 (Sleepycat) 8/24/97"; +static const char sccsid[] = "@(#)hash.c 10.27 (Sleepycat) 9/15/97"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -573,8 +573,6 @@ __ham_c_close(cursor) DBC *cursor; { DB *ldbp; - HTAB *hashp; - HASH_CURSOR *hcp; int ret; DEBUG_LWRITE(cursor->dbp, cursor->txn, "ham_c_close", NULL, NULL, 0); @@ -590,8 +588,32 @@ __ham_c_close(cursor) if (F_ISSET(cursor->dbp, DB_AM_THREAD) && (ret = __db_gethandle(cursor->dbp, __ham_hdup, &ldbp)) != 0) return (ret); - hashp = (HTAB *)ldbp->internal; - hcp = (HASH_CURSOR *)cursor->internal; + + ret = __ham_c_iclose(ldbp, cursor); + + if (F_ISSET(ldbp, DB_AM_THREAD)) + __db_puthandle(ldbp); + return (ret); +} +/* + * __ham_c_iclose -- + * + * Internal cursor close routine; assumes it is being passed the correct + * handle, rather than getting and putting a handle. + * + * PUBLIC: int __ham_c_iclose __P((DB *, DBC *)); + */ +int +__ham_c_iclose(dbp, dbc) + DB *dbp; + DBC *dbc; +{ + HASH_CURSOR *hcp; + HTAB *hashp; + int ret; + + hashp = (HTAB *)dbp->internal; + hcp = (HASH_CURSOR *)dbc->internal; ret = __ham_item_done(hashp, hcp, 0); if (hcp->big_key) @@ -602,19 +624,16 @@ __ham_c_close(cursor) /* * All cursors (except the default ones) are linked off the master. * Therefore, when we close the cursor, we have to remove it from - * the master, not the local one. When we are closing the file in - * its entirety, then we clear the THREAD bit and the master and - * local are identical, so we remove the correct one. + * the master, not the local one. + * XXX I am always removing from the master; what about local cursors? */ - DB_THREAD_LOCK(cursor->dbp); - TAILQ_REMOVE(&cursor->dbp->curs_queue, cursor, links); - DB_THREAD_UNLOCK(cursor->dbp); - - if (F_ISSET(cursor->dbp, DB_AM_THREAD)) - __db_puthandle(ldbp); + DB_THREAD_LOCK(dbc->dbp); + TAILQ_REMOVE(&dbc->dbp->curs_queue, dbc, links); + DB_THREAD_UNLOCK(dbc->dbp); FREE(hcp, sizeof(HASH_CURSOR)); - FREE(cursor, sizeof(DBC)); + FREE(dbc, sizeof(DBC)); + return (ret); } @@ -695,10 +714,9 @@ __ham_c_del(cursor, flags) hcp->dndx = 0; /* Case 2 */ hcp->dpgno = PGNO(hcp->dpagep); if (ppgno == PGNO_INVALID) - memcpy(P_ENTRY(hcp->pagep, - H_DATAINDEX(hcp->bndx)) + - SSZ(HOFFDUP, pgno), &hcp->dpgno, - sizeof(db_pgno_t)); + memcpy(HOFFDUP_PGNO(P_ENTRY(hcp->pagep, + H_DATAINDEX(hcp->bndx))), + &hcp->dpgno, sizeof(db_pgno_t)); F_SET(hcp, H_DELETED); } else /* Case 1 */ F_SET(hcp, H_DELETED); @@ -1051,18 +1069,17 @@ __ham_dup_return(hashp, hcp, val, flags) DBT *val; int flags; { - HKEYDATA *hk; PAGE *pp; DBT *myval, tmp_val; db_indx_t ndx; db_pgno_t pgno; - u_int8_t type; + u_int8_t *hk, type; int indx, ret; db_indx_t len; /* Check for duplicate and return the first one. */ ndx = H_DATAINDEX(hcp->bndx); - type = GET_HKEYDATA(hcp->pagep, ndx)->type; + type = HPAGE_TYPE(hcp->pagep, ndx); pp = hcp->pagep; myval = val; @@ -1088,7 +1105,8 @@ __ham_dup_return(hashp, hcp, val, flags) hcp->dndx = 0; hcp->dup_off = 0; do { - memcpy(&len, hk->data + hcp->dup_off, + memcpy(&len, + HKEYDATA_DATA(hk) + hcp->dup_off, sizeof(db_indx_t)); hcp->dup_off += DUP_SIZE(len); hcp->dndx++; @@ -1096,15 +1114,15 @@ __ham_dup_return(hashp, hcp, val, flags) hcp->dup_off -= DUP_SIZE(len); hcp->dndx--; } else { - memcpy(&len, hk->data, sizeof(db_indx_t)); + memcpy(&len, + HKEYDATA_DATA(hk), sizeof(db_indx_t)); hcp->dup_off = 0; hcp->dndx = 0; } hcp->dup_len = len; } else if (type == H_OFFDUP) { F_SET(hcp, H_ISDUP); - memcpy(&pgno, - P_ENTRY(hcp->pagep, ndx) + SSZ(HOFFDUP, pgno), + memcpy(&pgno, HOFFDUP_PGNO(P_ENTRY(hcp->pagep, ndx)), sizeof(db_pgno_t)); if (flags == DB_LAST || flags == DB_PREV) { indx = (int)hcp->dndx; @@ -1166,7 +1184,7 @@ __ham_overwrite(hashp, hcp, nval) DBT *nval; { DBT *myval, tmp_val; - HKEYDATA *hk; + u_int8_t *hk; if (F_ISSET(hashp->dbp, DB_AM_DUP)) return (__ham_add_dup(hashp, hcp, nval, DB_KEYLAST)); @@ -1176,10 +1194,9 @@ __ham_overwrite(hashp, hcp, nval) F_SET(&tmp_val, DB_DBT_PARTIAL); tmp_val.doff = 0; hk = H_PAIRDATA(hcp->pagep, hcp->bndx); - if (hk->type == H_OFFPAGE) + if (HPAGE_PTYPE(hk) == H_OFFPAGE) memcpy(&tmp_val.dlen, - (u_int8_t *)hk + SSZ(HOFFPAGE, tlen), - sizeof(u_int32_t)); + HOFFPAGE_TLEN(hk), sizeof(u_int32_t)); else tmp_val.dlen = LEN_HDATA(hcp->pagep, hashp->hdr->pagesize,hcp->bndx); @@ -1207,10 +1224,10 @@ __ham_lookup(hashp, hcp, key, sought, mode) u_int32_t sought; db_lockmode_t mode; { - HKEYDATA *hk; db_pgno_t pgno; u_int32_t tlen; int match, ret, t_ret; + u_int8_t *hk; /* * Set up cursor so that we're looking for space to add an item @@ -1229,14 +1246,12 @@ __ham_lookup(hashp, hcp, key, sought, mode) break; hk = H_PAIRKEY(hcp->pagep, hcp->bndx); - switch (hk->type) { + switch (HPAGE_PTYPE(hk)) { case H_OFFPAGE: - memcpy(&tlen, (u_int8_t *)hk + SSZ(HOFFPAGE, tlen), - sizeof(u_int32_t)); + memcpy(&tlen, HOFFPAGE_TLEN(hk), sizeof(u_int32_t)); if (tlen == key->size) { memcpy(&pgno, - (u_int8_t *)hk + SSZ(HOFFPAGE, pgno), - sizeof(db_pgno_t)); + HOFFPAGE_PGNO(hk), sizeof(db_pgno_t)); match = __db_moff(hashp->dbp, key, pgno); if (match == 0) { F_SET(hcp, H_OK); @@ -1247,7 +1262,8 @@ __ham_lookup(hashp, hcp, key, sought, mode) case H_KEYDATA: if (key->size == LEN_HKEY(hcp->pagep, hashp->hdr->pagesize, hcp->bndx) && - memcmp(key->data, hk->data, key->size) == 0) { + memcmp(key->data, + HKEYDATA_DATA(hk), key->size) == 0) { F_SET(hcp, H_OK); return (0); } diff --git a/db2/hash/hash_auto.c b/db2/hash/hash_auto.c index f8ab80c8ee..2279de9668 100644 --- a/db2/hash/hash_auto.c +++ b/db2/hash/hash_auto.c @@ -138,7 +138,7 @@ __ham_insdel_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_insdel_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_insdel_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_insdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -335,7 +335,7 @@ __ham_newpage_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_newpage_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_newpage_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_newpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -498,7 +498,7 @@ __ham_splitmeta_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_splitmeta_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_splitmeta_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_splitmeta: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -659,7 +659,7 @@ __ham_splitdata_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_splitdata_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_splitdata_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_splitdata: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -851,7 +851,7 @@ __ham_replace_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_replace_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_replace_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_replace: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -1053,7 +1053,7 @@ __ham_newpgno_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_newpgno_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_newpgno_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_newpgno: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, @@ -1218,7 +1218,7 @@ __ham_ovfl_print(notused1, dbtp, lsnp, notused3, notused4) notused3 = 0; notused4 = NULL; - if((ret = __ham_ovfl_read(dbtp->data, &argp)) != 0) + if ((ret = __ham_ovfl_read(dbtp->data, &argp)) != 0) return (ret); printf("[%lu][%lu]ham_ovfl: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", (u_long)lsnp->file, diff --git a/db2/hash/hash_conv.c b/db2/hash/hash_conv.c index 22901af950..9cebe72390 100644 --- a/db2/hash/hash_conv.c +++ b/db2/hash/hash_conv.c @@ -7,7 +7,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash_conv.c 10.3 (Sleepycat) 6/21/97"; +static const char sccsid[] = "@(#)hash_conv.c 10.4 (Sleepycat) 9/15/97"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -20,12 +20,11 @@ static const char sccsid[] = "@(#)hash_conv.c 10.3 (Sleepycat) 6/21/97"; #include "hash.h" /* - * __h_pgin, __ham_pgout -- - * Convert host-specific page layout to/from the host-independent - * format stored on disk. + * __ham_pgin -- + * Convert host-specific page layout from the host-independent format + * stored on disk. * * PUBLIC: int __ham_pgin __P((db_pgno_t, void *, DBT *)); - * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *)); */ int __ham_pgin(pg, pp, cookie) @@ -49,9 +48,17 @@ __ham_pgin(pg, pp, cookie) if (!pginfo->needswap) return (0); - return (pg == PGNO_METADATA ? __ham_mswap(pp) : __db_pgin(pg, pp)); + return (pg == PGNO_METADATA ? + __ham_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp)); } +/* + * __ham_pgout -- + * Convert host-specific page layout to the host-independent format + * stored on disk. + * + * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *)); + */ int __ham_pgout(pg, pp, cookie) db_pgno_t pg; @@ -63,7 +70,8 @@ __ham_pgout(pg, pp, cookie) pginfo = (DB_PGINFO *)cookie->data; if (!pginfo->needswap) return (0); - return (pg == PGNO_METADATA ? __ham_mswap(pp) : __db_pgout(pg, pp)); + return (pg == PGNO_METADATA ? + __ham_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp)); } /* diff --git a/db2/hash/hash_dup.c b/db2/hash/hash_dup.c index c9590fa49d..71bd1c5eb0 100644 --- a/db2/hash/hash_dup.c +++ b/db2/hash/hash_dup.c @@ -42,7 +42,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash_dup.c 10.6 (Sleepycat) 9/3/97"; +static const char sccsid[] = "@(#)hash_dup.c 10.7 (Sleepycat) 9/15/97"; #endif /* not lint */ /* @@ -99,9 +99,9 @@ __ham_add_dup(hashp, hcp, nval, flags) int flags; { DBT pval, tmp_val; - HKEYDATA *hk; u_int32_t del_len, new_size; int ret; + u_int8_t *hk; if (flags == DB_CURRENT && hcp->dpgno == PGNO_INVALID) del_len = hcp->dup_len; @@ -128,8 +128,8 @@ __ham_add_dup(hashp, hcp, nval, flags) * the addition of the new item will make the set large, or * if there isn't enough room on this page to add the next item. */ - if (hk->type != H_OFFDUP && - (hk->type == H_OFFPAGE || ISBIG(hashp, new_size) || + if (HPAGE_PTYPE(hk) != H_OFFDUP && + (HPAGE_PTYPE(hk) == H_OFFPAGE || ISBIG(hashp, new_size) || DUP_SIZE(nval->size) - del_len > P_FREESPACE(hcp->pagep))) { if ((ret = __ham_dup_convert(hashp, hcp)) != 0) @@ -139,16 +139,17 @@ __ham_add_dup(hashp, hcp, nval, flags) } /* There are two separate cases here: on page and off page. */ - if (hk->type != H_OFFDUP) { - if (hk->type != H_DUPLICATE) { - hk->type = H_DUPLICATE; + if (HPAGE_PTYPE(hk) != H_OFFDUP) { + if (HPAGE_PTYPE(hk) != H_DUPLICATE) { + HPAGE_PTYPE(hk) = H_DUPLICATE; pval.flags = 0; - pval.data = hk->data; + pval.data = HKEYDATA_DATA(hk); pval.size = LEN_HDATA(hcp->pagep, hashp->hdr->pagesize, hcp->bndx); - if ((ret = __ham_make_dup(&pval, &tmp_val, &hcp->big_data, - &hcp->big_datalen)) != 0 || - (ret = __ham_replpair(hashp, hcp, &tmp_val, 1)) != 0) + if ((ret = + __ham_make_dup(&pval, &tmp_val, &hcp->big_data, + &hcp->big_datalen)) != 0 || (ret = + __ham_replpair(hashp, hcp, &tmp_val, 1)) != 0) return (ret); } @@ -187,8 +188,7 @@ __ham_add_dup(hashp, hcp, nval, flags) /* If we get here, then we're on duplicate pages. */ if (hcp->dpgno == PGNO_INVALID) { - memcpy(&hcp->dpgno, - (u_int8_t *)hk + SSZ(HOFFDUP, pgno), sizeof(db_pgno_t)); + memcpy(&hcp->dpgno, HOFFDUP_PGNO(hk), sizeof(db_pgno_t)); hcp->dndx = 0; } @@ -259,14 +259,13 @@ __ham_dup_convert(hashp, hcp) * Now put the duplicates onto the new page. */ dbt.flags = 0; - switch (((HKEYDATA *)H_PAIRDATA(hcp->pagep, hcp->bndx))->type) { + switch (HPAGE_PTYPE(H_PAIRDATA(hcp->pagep, hcp->bndx))) { case H_KEYDATA: /* Simple case, one key on page; move it to dup page. */ dndx = 0; dbt.size = LEN_HDATA(hcp->pagep, hashp->hdr->pagesize, hcp->bndx); - dbt.data = - ((HKEYDATA *)H_PAIRDATA(hcp->pagep, hcp->bndx))->data; + dbt.data = HKEYDATA_DATA(H_PAIRDATA(hcp->pagep, hcp->bndx)); ret = __db_pitem(hashp->dbp, hcp->dpagep, (u_int32_t)dndx, BKEYDATA_SIZE(dbt.size), NULL, &dbt); if (ret == 0) @@ -289,7 +288,7 @@ __ham_dup_convert(hashp, hcp) __ham_dirty_page(hashp, hcp->dpagep); break; case H_DUPLICATE: - p = ((HKEYDATA *)H_PAIRDATA(hcp->pagep, hcp->bndx))->data; + p = HKEYDATA_DATA(H_PAIRDATA(hcp->pagep, hcp->bndx)); pend = p + LEN_HDATA(hcp->pagep, hashp->hdr->pagesize, hcp->bndx); @@ -366,24 +365,23 @@ __ham_check_move(hashp, hcp, add_len) { DBT k, d; DB_LSN new_lsn; - HKEYDATA *hk; PAGE *next_pagep; db_pgno_t next_pgno; int rectype, ret; u_int32_t new_datalen, old_len; + u_int8_t *hk; /* * Check if we can do whatever we need to on this page. If not, * then we'll have to move the current element to a new page. */ - hk = H_PAIRDATA(hcp->pagep, hcp->bndx); /* * If the item is already off page duplicates or an offpage item, * then we know we can do whatever we need to do in-place */ - if (hk->type == H_OFFDUP || hk->type == H_OFFPAGE) + if (HPAGE_PTYPE(hk) == H_OFFDUP || HPAGE_PTYPE(hk) == H_OFFPAGE) return (0); old_len = @@ -443,22 +441,25 @@ __ham_check_move(hashp, hcp, add_len) rectype = PUTPAIR; k.flags = 0; d.flags = 0; - if (H_PAIRKEY(hcp->pagep, hcp->bndx)->type == H_OFFPAGE) { + if (HPAGE_PTYPE( + H_PAIRKEY(hcp->pagep, hcp->bndx)) == H_OFFPAGE) { rectype |= PAIR_KEYMASK; k.data = H_PAIRKEY(hcp->pagep, hcp->bndx); k.size = HOFFPAGE_SIZE; } else { - k.data = H_PAIRKEY(hcp->pagep, hcp->bndx)->data; + k.data = + HKEYDATA_DATA(H_PAIRKEY(hcp->pagep, hcp->bndx)); k.size = LEN_HKEY(hcp->pagep, hashp->hdr->pagesize, hcp->bndx); } - if (hk->type == H_OFFPAGE) { + if (HPAGE_PTYPE(hk) == H_OFFPAGE) { rectype |= PAIR_DATAMASK; d.data = H_PAIRDATA(hcp->pagep, hcp->bndx); d.size = HOFFPAGE_SIZE; } else { - d.data = H_PAIRDATA(hcp->pagep, hcp->bndx)->data; + d.data = + HKEYDATA_DATA(H_PAIRDATA(hcp->pagep, hcp->bndx)); d.size = LEN_HDATA(hcp->pagep, hashp->hdr->pagesize, hcp->bndx); } diff --git a/db2/hash/hash_func.c b/db2/hash/hash_func.c index 2ef47afb57..1bf12c4948 100644 --- a/db2/hash/hash_func.c +++ b/db2/hash/hash_func.c @@ -47,7 +47,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash_func.c 10.6 (Sleepycat) 7/26/97"; +static const char sccsid[] = "@(#)hash_func.c 10.7 (Sleepycat) 9/16/97"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -64,7 +64,7 @@ static const char sccsid[] = "@(#)hash_func.c 10.6 (Sleepycat) 7/26/97"; * * PUBLIC: u_int32_t __ham_func2 __P((const void *, u_int32_t)); */ -#define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c)) +#define DCHARHASH(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c)) u_int32_t __ham_func2(key, len) @@ -81,7 +81,7 @@ __ham_func2(key, len) c = *k++; if (!c && k > e) break; - dcharhash(h, c); + DCHARHASH(h, c); } return (h); } diff --git a/db2/hash/hash_page.c b/db2/hash/hash_page.c index 68c31b14f9..8ba42da1a4 100644 --- a/db2/hash/hash_page.c +++ b/db2/hash/hash_page.c @@ -47,10 +47,9 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash_page.c 10.18 (Sleepycat) 8/21/97"; +static const char sccsid[] = "@(#)hash_page.c 10.24 (Sleepycat) 9/17/97"; #endif /* not lint */ - /* * PACKAGE: hashing * @@ -85,7 +84,7 @@ static const char sccsid[] = "@(#)hash_page.c 10.18 (Sleepycat) 8/21/97"; static int __ham_lock_bucket __P((DB *, HASH_CURSOR *, db_lockmode_t)); #ifdef DEBUG_SLOW -static void account_page(HTAB *, db_pgno_t, int); +static void __account_page(HTAB *, db_pgno_t, int); #endif /* @@ -121,7 +120,7 @@ __ham_item(hashp, cursorp, mode) * pointer to be the beginning of the datum. */ memcpy(&cursorp->dup_len, - H_PAIRDATA(cursorp->pagep, cursorp->bndx)->data + + HKEYDATA_DATA(H_PAIRDATA(cursorp->pagep, cursorp->bndx)) + cursorp->dup_off, sizeof(db_indx_t)); else if (F_ISSET(cursorp, H_ISDUP)) { /* Make sure we're not about to run off the page. */ @@ -326,8 +325,8 @@ __ham_item_prev(hashp, cursorp, mode) else { HASH_CURSOR *h; h = cursorp; - memcpy(&h->dup_len, - H_PAIRDATA(h->pagep, h->bndx)->data + memcpy(&h->dup_len, HKEYDATA_DATA( + H_PAIRDATA(h->pagep, h->bndx)) + h->dup_off - sizeof(db_indx_t), sizeof(db_indx_t)); cursorp->dup_off -= @@ -481,7 +480,7 @@ __ham_putitem(p, dbt, type) } else { off = HOFFSET(p) - HKEYDATA_SIZE(dbt->size); HOFFSET(p) = p->inp[n] = off; - PUT_HKEYDATA(GET_HKEYDATA(p, n), dbt->data, dbt->size, type); + PUT_HKEYDATA(P_ENTRY(p, n), dbt->data, dbt->size, type); } /* Adjust page info. */ @@ -524,24 +523,24 @@ __ham_del_pair(hashp, cursorp) * entry referring to the big item. */ ret = 0; - if (H_PAIRKEY(p, ndx)->type == H_OFFPAGE) { - memcpy(&pgno, (u_int8_t *)GET_HOFFPAGE(p, H_KEYINDEX(ndx)) + - SSZ(HOFFPAGE, pgno), sizeof(db_pgno_t)); + if (HPAGE_PTYPE(H_PAIRKEY(p, ndx)) == H_OFFPAGE) { + memcpy(&pgno, HOFFPAGE_PGNO(P_ENTRY(p, H_KEYINDEX(ndx))), + sizeof(db_pgno_t)); ret = __db_doff(hashp->dbp, pgno, __ham_del_page); } if (ret == 0) - switch (H_PAIRDATA(p, ndx)->type) { + switch (HPAGE_PTYPE(H_PAIRDATA(p, ndx))) { case H_OFFPAGE: memcpy(&pgno, - (u_int8_t *)GET_HOFFPAGE(p, H_DATAINDEX(ndx)) + - SSZ(HOFFPAGE, pgno), sizeof(db_pgno_t)); + HOFFPAGE_PGNO(P_ENTRY(p, H_DATAINDEX(ndx))), + sizeof(db_pgno_t)); ret = __db_doff(hashp->dbp, pgno, __ham_del_page); break; case H_OFFDUP: memcpy(&pgno, - (u_int8_t *)GET_HOFFDUP(p, H_DATAINDEX(ndx)) + - SSZ(HOFFDUP, pgno), sizeof(db_pgno_t)); + HOFFDUP_PGNO(P_ENTRY(p, H_DATAINDEX(ndx))), + sizeof(db_pgno_t)); ret = __db_ddup(hashp->dbp, pgno, __ham_del_page); break; } @@ -706,13 +705,12 @@ __ham_replpair(hashp, hcp, dbt, make_dup) DBT *dbt; u_int32_t make_dup; { - DBT old_dbt, tmp; + DBT old_dbt, tdata, tmp; DB_LSN new_lsn; - HKEYDATA *hk; u_int32_t len; int32_t change; int is_big, ret, type; - u_int8_t *beg, *dest, *end, *src; + u_int8_t *beg, *dest, *end, *hk, *src; /* * Big item replacements are handled in generic code. @@ -738,11 +736,10 @@ __ham_replpair(hashp, hcp, dbt, make_dup) change = dbt->size - dbt->dlen; hk = H_PAIRDATA(hcp->pagep, hcp->bndx); - is_big = hk->type == H_OFFPAGE; + is_big = HPAGE_PTYPE(hk) == H_OFFPAGE; if (is_big) - memcpy(&len, (u_int8_t *)hk + SSZ(HOFFPAGE, tlen), - sizeof(u_int32_t)); + memcpy(&len, HOFFPAGE_TLEN(hk), sizeof(u_int32_t)); else len = LEN_HKEYDATA(hcp->pagep, hashp->dbp->pgsize, H_DATAINDEX(hcp->bndx)); @@ -770,13 +767,14 @@ __ham_replpair(hashp, hcp, dbt, make_dup) &tmp, &hcp->big_key, &hcp->big_keylen)) != 0) return (ret); - type = hk->type; if (dbt->doff == 0 && dbt->dlen == len) { ret = __ham_del_pair(hashp, hcp); if (ret == 0) - ret = __ham_add_el(hashp, hcp, &tmp, dbt, type); + ret = __ham_add_el(hashp, + hcp, &tmp, dbt, H_KEYDATA); } else { /* Case B */ - DBT tdata; + type = HPAGE_PTYPE(hk) != H_OFFPAGE ? + HPAGE_PTYPE(hk) : H_KEYDATA; tdata.flags = 0; F_SET(&tdata, DB_DBT_MALLOC | DB_DBT_INTERNAL); @@ -824,7 +822,7 @@ err: free(tmp.data); * Set up pointer into existing data. Do it before the log * message so we can use it inside of the log setup. */ - beg = H_PAIRDATA(hcp->pagep, hcp->bndx)->data; + beg = HKEYDATA_DATA(H_PAIRDATA(hcp->pagep, hcp->bndx)); beg += dbt->doff; /* @@ -885,11 +883,11 @@ __ham_onpage_replace(pagep, pgsize, ndx, off, change, dbt) if (off < 0) len = pagep->inp[ndx] - HOFFSET(pagep); else if ((u_int32_t)off >= LEN_HKEYDATA(pagep, pgsize, ndx)) { - len = GET_HKEYDATA(pagep, ndx)->data + + len = HKEYDATA_DATA(P_ENTRY(pagep, ndx)) + LEN_HKEYDATA(pagep, pgsize, ndx) - src; zero_me = 1; } else - len = (GET_HKEYDATA(pagep, ndx)->data + off) - src; + len = (HKEYDATA_DATA(P_ENTRY(pagep, ndx)) + off) - src; dest = src - change; memmove(dest, src, len); if (zero_me) @@ -901,7 +899,7 @@ __ham_onpage_replace(pagep, pgsize, ndx, off, change, dbt) HOFFSET(pagep) -= change; } if (off >= 0) - memcpy(GET_HKEYDATA(pagep, ndx)->data + off, + memcpy(HKEYDATA_DATA(P_ENTRY(pagep, ndx)) + off, dbt->data, dbt->size); else memcpy(P_ENTRY(pagep, ndx), dbt->data, dbt->size); @@ -1319,7 +1317,7 @@ __ham_new_page(hashp, addr, type, pp) return (ret); #ifdef DEBUG_SLOW - account_page(hashp, addr, 1); + __account_page(hashp, addr, 1); #endif /* This should not be necessary because page-in should do it. */ P_INIT(pagep, @@ -1398,7 +1396,7 @@ __ham_put_page(dbp, pagep, is_dirty) int32_t is_dirty; { #ifdef DEBUG_SLOW - account_page((HTAB *)dbp->cookie, + __account_page((HTAB *)dbp->cookie, ((BKT *)((char *)pagep - sizeof(BKT)))->pgno, -1); #endif return (memp_fput(dbp->mpf, pagep, (is_dirty ? DB_MPOOL_DIRTY : 0))); @@ -1432,7 +1430,7 @@ __ham_get_page(dbp, addr, pagep) ret = memp_fget(dbp->mpf, &addr, DB_MPOOL_CREATE, pagep); #ifdef DEBUG_SLOW if (*pagep != NULL) - account_page((HTAB *)dbp->internal, addr, 1); + __account_page((HTAB *)dbp->internal, addr, 1); #endif return (ret); } @@ -1523,11 +1521,11 @@ __ham_overflow_page(dbp, type, pp) #ifdef DEBUG /* * PUBLIC: #ifdef DEBUG - * PUBLIC: int bucket_to_page __P((HTAB *, int)); + * PUBLIC: int __bucket_to_page __P((HTAB *, int)); * PUBLIC: #endif */ int -bucket_to_page(hashp, n) +__bucket_to_page(hashp, n) HTAB *hashp; int n; { @@ -1735,7 +1733,7 @@ __ham_dpair(dbp, p, pndx) #ifdef DEBUG_SLOW static void -account_page(hashp, pgno, inout) +__account_page(hashp, pgno, inout) HTAB *hashp; db_pgno_t pgno; int inout; @@ -1767,7 +1765,8 @@ account_page(hashp, pgno, inout) last--; } for (i = 0; i < last; i++, list[i].times++) - if (list[i].times > 20 && !is_bitmap_pgno(hashp, list[i].pgno)) + if (list[i].times > 20 && + !__is_bitmap_pgno(hashp, list[i].pgno)) (void)fprintf(stderr, "Warning: pg %lu has been out for %d times\n", (u_long)list[i].pgno, list[i].times); diff --git a/db2/hash/hash_rec.c b/db2/hash/hash_rec.c index 81d9bb5ea8..1b30be337d 100644 --- a/db2/hash/hash_rec.c +++ b/db2/hash/hash_rec.c @@ -47,7 +47,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)hash_rec.c 10.12 (Sleepycat) 8/22/97"; +static const char sccsid[] = "@(#)hash_rec.c 10.13 (Sleepycat) 9/15/97"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -364,11 +364,11 @@ __ham_replace_recover(logp, dbtp, lsnp, redo, info) DB *mdbp, *file_dbp; DB_MPOOLFILE *mpf; DBT dbt; - HKEYDATA *hk; HTAB *hashp; PAGE *pagep; int32_t grow; int change, cmp_n, cmp_p, getmeta, ret; + u_int8_t *hk; getmeta = 0; hashp = NULL; /* XXX: shut the compiler up. */ @@ -421,11 +421,11 @@ __ham_replace_recover(logp, dbtp, lsnp, redo, info) __ham_onpage_replace(pagep, file_dbp->pgsize, argp->ndx, argp->off, grow, &dbt); if (argp->makedup) { - hk = GET_HKEYDATA(pagep, argp->ndx); + hk = P_ENTRY(pagep, argp->ndx); if (redo) - hk->type = H_DUPLICATE; + HPAGE_PTYPE(hk) = H_DUPLICATE; else - hk->type = H_KEYDATA; + HPAGE_PTYPE(hk) = H_KEYDATA; } } @@ -738,7 +738,7 @@ __ham_ovfl_recover(logp, dbtp, lsnp, redo, info) DBT *dbtp; DB_LSN *lsnp; int redo; - void *info; + void *info; { __ham_ovfl_args *argp; DB *mdbp, *file_dbp; |