diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-10-23 20:11:11 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-10-23 20:11:11 (GMT) |
commit | 663919aa50f3c1d270239e06794c3fc6fff1ad9f (patch) | |
tree | e216367ffb327004461dd832c46b10044979cd21 /src/H5B2cache.c | |
parent | 7fcd1375d81540e10f96c39d2ded53e34a3fe474 (diff) | |
download | hdf5-663919aa50f3c1d270239e06794c3fc6fff1ad9f.zip hdf5-663919aa50f3c1d270239e06794c3fc6fff1ad9f.tar.gz hdf5-663919aa50f3c1d270239e06794c3fc6fff1ad9f.tar.bz2 |
[svn-r17738] Description:
Bring revisions 17649, 17657 and 17658 from trunk to 1.8 branch:
17649: Refactor v2 B-trees to pin the B-tree header in the cache instead
of using separate reference counted data structure.
17657: Refactor the v2 B-tree code to use an open & close call
internally, in preparation for making those part of the library
private APIs for dealing with v2 B-trees.
17658: Rename 'H5B2_t' -> 'H5B2_hdr_t' and 'bt2' -> 'hdr' in preparation
for make v2 B-tree open/close routines library private (instead
of static).
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Mac OS X/32 10.6.1 (amazon) in debug mode
Mac OS X/32 10.6.1 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Diffstat (limited to 'src/H5B2cache.c')
-rw-r--r-- | src/H5B2cache.c | 358 |
1 files changed, 165 insertions, 193 deletions
diff --git a/src/H5B2cache.c b/src/H5B2cache.c index 5882ce9..994d163 100644 --- a/src/H5B2cache.c +++ b/src/H5B2cache.c @@ -69,15 +69,15 @@ /********************/ /* Metadata cache callbacks */ -static H5B2_t *H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata); -static herr_t H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_t *b, unsigned UNUSED * flags_ptr); -static herr_t H5B2_cache_hdr_clear(H5F_t *f, H5B2_t *b, hbool_t destroy); -static herr_t H5B2_cache_hdr_size(const H5F_t *f, const H5B2_t *bt, size_t *size_ptr); -static H5B2_internal_t *H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_shared); +static H5B2_hdr_t *H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata); +static herr_t H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_hdr_t *hdr, unsigned UNUSED * flags_ptr); +static herr_t H5B2_cache_hdr_clear(H5F_t *f, H5B2_hdr_t *hdr, hbool_t destroy); +static herr_t H5B2_cache_hdr_size(const H5F_t *f, const H5B2_hdr_t *hdr, size_t *size_ptr); +static H5B2_internal_t *H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *udata2); static herr_t H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_internal_t *i, unsigned UNUSED * flags_ptr); static herr_t H5B2_cache_internal_clear(H5F_t *f, H5B2_internal_t *i, hbool_t destroy); static herr_t H5B2_cache_internal_size(const H5F_t *f, const H5B2_internal_t *i, size_t *size_ptr); -static H5B2_leaf_t *H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_shared); +static H5B2_leaf_t *H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_hdr); static herr_t H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_leaf_t *l, unsigned UNUSED * flags_ptr); static herr_t H5B2_cache_leaf_clear(H5F_t *f, H5B2_leaf_t *l, hbool_t destroy); static herr_t H5B2_cache_leaf_size(const H5F_t *f, const H5B2_leaf_t *l, size_t *size_ptr); @@ -135,7 +135,6 @@ const H5AC_class_t H5AC_BT2_LEAF[1] = {{ * Purpose: Loads a B-tree header from the disk. * * Return: Success: Pointer to a new B-tree. - * * Failure: NULL * * Programmer: Quincey Koziol @@ -144,22 +143,22 @@ const H5AC_class_t H5AC_BT2_LEAF[1] = {{ * *------------------------------------------------------------------------- */ -static H5B2_t * +static H5B2_hdr_t * H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void UNUSED *udata) { const H5B2_class_t *type = (const H5B2_class_t *) _type; /* Type of B-tree */ unsigned depth; /* Depth of B-tree */ size_t node_size, rrec_size; /* Size info for B-tree */ uint8_t split_percent, merge_percent; /* Split & merge %s for B-tree */ - H5B2_t *bt2 = NULL; /* B-tree info */ + H5B2_hdr_t *hdr = NULL; /* B-tree header */ size_t size; /* Header size */ uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ H5WB_t *wb = NULL; /* Wrapped buffer for header data */ uint8_t hdr_buf[H5B2_HDR_BUF_SIZE]; /* Buffer for header */ - uint8_t *hdr; /* Pointer to header buffer */ + uint8_t *buf; /* Pointer to header buffer */ uint8_t *p; /* Pointer into raw data buffer */ - H5B2_t *ret_value; /* Return value */ + H5B2_hdr_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5B2_cache_hdr_load, NULL) @@ -168,10 +167,10 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo HDassert(H5F_addr_defined(addr)); HDassert(type); - /* Allocate space for the B-tree data structure */ - if(NULL == (bt2 = H5FL_MALLOC(H5B2_t))) + /* Allocate new B-tree header and reset cache info */ + if(NULL == (hdr = H5FL_MALLOC(H5B2_hdr_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemset(&bt2->cache_info, 0, sizeof(H5AC_info_t)); + HDmemset(&hdr->cache_info, 0, sizeof(H5AC_info_t)); /* Wrap the local buffer for serialized header info */ if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf)))) @@ -181,15 +180,15 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo size = H5B2_HEADER_SIZE(f); /* Get a pointer to a buffer that's large enough for header */ - if(NULL == (hdr = (uint8_t *)H5WB_actual(wb, size))) + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't get actual buffer") /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_BTREE, addr, size, dxpl_id, hdr) < 0) + if(H5F_block_read(f, H5FD_MEM_BTREE, addr, size, dxpl_id, buf) < 0) HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree header") /* Get temporary pointer to serialized header */ - p = hdr; + p = buf; /* Magic number */ if(HDmemcmp(p, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) @@ -218,36 +217,39 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo merge_percent = *p++; /* Root node pointer */ - H5F_addr_decode(f, (const uint8_t **)&p, &(bt2->root.addr)); - UINT16DECODE(p, bt2->root.node_nrec); - H5F_DECODE_LENGTH(f, p, bt2->root.all_nrec); + H5F_addr_decode(f, (const uint8_t **)&p, &(hdr->root.addr)); + UINT16DECODE(p, hdr->root.node_nrec); + H5F_DECODE_LENGTH(f, p, hdr->root.all_nrec); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ - HDassert((size_t)(p - hdr) == size); + HDassert((size_t)(p - buf) == size); /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(hdr, (size - H5B2_SIZEOF_CHKSUM), 0); + computed_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM), 0); /* Verify checksum */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 B-tree header") - /* Initialize shared B-tree info */ - if(H5B2_shared_init(f, bt2, type, depth, node_size, rrec_size, split_percent, merge_percent) < 0) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't create shared B-tree info") + /* Initialize B-tree header info */ + if(H5B2_hdr_init(f, hdr, type, depth, node_size, rrec_size, split_percent, merge_percent) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, NULL, "can't initialize B-tree header info") + + /* Set the B-tree header's address */ + hdr->addr = addr; /* Set return value */ - ret_value = bt2; + ret_value = hdr; done: /* Release resources */ if(wb && H5WB_unwrap(wb) < 0) HDONE_ERROR(H5E_BTREE, H5E_CLOSEERROR, NULL, "can't close wrapped buffer") - if(!ret_value && bt2) - (void)H5B2_cache_hdr_dest(f, bt2); + if(!ret_value && hdr) + (void)H5B2_cache_hdr_dest(f, hdr); FUNC_LEAVE_NOAPI(ret_value) } /* end H5B2_cache_hdr_load() */ /*lint !e818 Can't make udata a pointer to const */ @@ -263,16 +265,12 @@ done: * Programmer: Quincey Koziol * koziol@ncsa.uiuc.edu * Feb 1 2005 - * Changes: JRM -- 8/21/06 - * Added the flags_ptr parameter. This parameter exists to - * allow the flush routine to report to the cache if the - * entry is resized or renamed as a result of the flush. - * *flags_ptr is set to H5C_CALLBACK__NO_FLAGS_SET on entry. * *------------------------------------------------------------------------- */ static herr_t -H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_t *bt2, unsigned UNUSED * flags_ptr) +H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, + H5B2_hdr_t *hdr, unsigned UNUSED * flags_ptr) { H5WB_t *wb = NULL; /* Wrapped buffer for header data */ uint8_t hdr_buf[H5B2_HDR_BUF_SIZE]; /* Buffer for header */ @@ -283,18 +281,16 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B /* check arguments */ HDassert(f); HDassert(H5F_addr_defined(addr)); - HDassert(bt2); + HDassert(hdr); - if (bt2->cache_info.is_dirty) { - H5B2_shared_t *shared; /* Shared B-tree information */ - uint8_t *hdr; /* Pointer to header buffer */ + if(hdr->cache_info.is_dirty) { + uint8_t *buf; /* Pointer to header buffer */ uint8_t *p; /* Pointer into raw data buffer */ size_t size; /* Header size on disk */ uint32_t metadata_chksum; /* Computed metadata checksum value */ - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(bt2->shared); - HDassert(shared); + /* Set the B-tree header's file context for this operation */ + hdr->f = f; /* Wrap the local buffer for serialized header info */ if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf)))) @@ -304,11 +300,11 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B size = H5B2_HEADER_SIZE(f); /* Get a pointer to a buffer that's large enough for header */ - if(NULL == (hdr = (uint8_t *)H5WB_actual(wb, size))) + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, FAIL, "can't get actual buffer") /* Get temporary pointer to serialized header */ - p = hdr; + p = buf; /* Magic number */ HDmemcpy(p, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); @@ -318,44 +314,44 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B *p++ = H5B2_HDR_VERSION; /* B-tree type */ - *p++ = shared->type->id; + *p++ = hdr->type->id; /* Node size (in bytes) */ - UINT32ENCODE(p, shared->node_size); + UINT32ENCODE(p, hdr->node_size); /* Raw key size (in bytes) */ - UINT16ENCODE(p, shared->rrec_size); + UINT16ENCODE(p, hdr->rrec_size); /* Depth of tree */ - UINT16ENCODE(p, shared->depth); + UINT16ENCODE(p, hdr->depth); /* Split & merge %s */ - H5_CHECK_OVERFLOW(shared->split_percent, /* From: */ unsigned, /* To: */ uint8_t); - *p++ = (uint8_t)shared->split_percent; - H5_CHECK_OVERFLOW(shared->merge_percent, /* From: */ unsigned, /* To: */ uint8_t); - *p++ = (uint8_t)shared->merge_percent; + H5_CHECK_OVERFLOW(hdr->split_percent, /* From: */ unsigned, /* To: */ uint8_t); + *p++ = (uint8_t)hdr->split_percent; + H5_CHECK_OVERFLOW(hdr->merge_percent, /* From: */ unsigned, /* To: */ uint8_t); + *p++ = (uint8_t)hdr->merge_percent; /* Root node pointer */ - H5F_addr_encode(f, &p, bt2->root.addr); - UINT16ENCODE(p, bt2->root.node_nrec); - H5F_ENCODE_LENGTH(f, p, bt2->root.all_nrec); + H5F_addr_encode(f, &p, hdr->root.addr); + UINT16ENCODE(p, hdr->root.node_nrec); + H5F_ENCODE_LENGTH(f, p, hdr->root.all_nrec); /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(hdr, (size - H5B2_SIZEOF_CHKSUM), 0); + metadata_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); /* Write the B-tree header. */ - HDassert((size_t)(p - hdr) == size); - if(H5F_block_write(f, H5FD_MEM_BTREE, addr, size, dxpl_id, hdr) < 0) + HDassert((size_t)(p - buf) == size); + if(H5F_block_write(f, H5FD_MEM_BTREE, addr, size, dxpl_id, buf) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree header to disk") - bt2->cache_info.is_dirty = FALSE; + hdr->cache_info.is_dirty = FALSE; } /* end if */ if(destroy) - if(H5B2_cache_hdr_dest(f, bt2) < 0) + if(H5B2_cache_hdr_dest(f, hdr) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree header") done: @@ -381,7 +377,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5B2_cache_hdr_dest(H5F_t *f, H5B2_t *bt2) +H5B2_cache_hdr_dest(H5F_t *f, H5B2_hdr_t *hdr) { herr_t ret_value = SUCCEED; /* Return value */ @@ -390,25 +386,26 @@ H5B2_cache_hdr_dest(H5F_t *f, H5B2_t *bt2) /* * Check arguments. */ - HDassert(bt2); + HDassert(hdr); + HDassert(hdr->rc == 0); /* If we're going to free the space on disk, the address must be valid */ - HDassert(!bt2->cache_info.free_file_space_on_destroy || H5F_addr_defined(bt2->cache_info.addr)); + HDassert(!hdr->cache_info.free_file_space_on_destroy || H5F_addr_defined(hdr->cache_info.addr)); /* Check for freeing file space for B-tree header */ - if(bt2->cache_info.free_file_space_on_destroy) { + if(hdr->cache_info.free_file_space_on_destroy) { /* Release the space on disk */ /* (XXX: Nasty usage of internal DXPL value! -QAK) */ - if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, bt2->cache_info.addr, (hsize_t)H5B2_HEADER_SIZE(f)) < 0) + if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, hdr->cache_info.addr, (hsize_t)H5B2_HEADER_SIZE(f)) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree header") } /* end if */ - /* Decrement reference count on shared B-tree info */ - if(bt2->shared) - H5RC_DEC(bt2->shared); + /* Release B-tree header info */ + if(H5B2_hdr_free(hdr) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree header info") /* Free B-tree header info */ - (void)H5FL_FREE(H5B2_t, bt2); + (void)H5FL_FREE(H5B2_hdr_t, hdr); done: FUNC_LEAVE_NOAPI(ret_value) @@ -429,7 +426,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5B2_cache_hdr_clear(H5F_t *f, H5B2_t *bt2, hbool_t destroy) +H5B2_cache_hdr_clear(H5F_t *f, H5B2_hdr_t *hdr, hbool_t destroy) { herr_t ret_value = SUCCEED; /* Return value */ @@ -438,13 +435,13 @@ H5B2_cache_hdr_clear(H5F_t *f, H5B2_t *bt2, hbool_t destroy) /* * Check arguments. */ - HDassert(bt2); + HDassert(hdr); /* Reset the dirty flag. */ - bt2->cache_info.is_dirty = FALSE; + hdr->cache_info.is_dirty = FALSE; if(destroy) - if(H5B2_cache_hdr_dest(f, bt2) < 0) + if(H5B2_cache_hdr_dest(f, hdr) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree header") done: @@ -468,7 +465,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5B2_cache_hdr_size(const H5F_t *f, const H5B2_t UNUSED *bt2, size_t *size_ptr) +H5B2_cache_hdr_size(const H5F_t *f, const H5B2_hdr_t UNUSED *hdr, size_t *size_ptr) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_cache_hdr_size) @@ -489,7 +486,6 @@ H5B2_cache_hdr_size(const H5F_t *f, const H5B2_t UNUSED *bt2, size_t *size_ptr) * Purpose: Loads a B-tree internal node from the disk. * * Return: Success: Pointer to a new B-tree internal node. - * * Failure: NULL * * Programmer: Quincey Koziol @@ -502,7 +498,6 @@ static H5B2_internal_t * H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_udata, void UNUSED *udata2) { const H5B2_int_load_ud1_t *udata = (const H5B2_int_load_ud1_t *)_udata; /* Pointer to user data */ - H5B2_shared_t *shared; /* Shared B-tree information */ H5B2_internal_t *internal = NULL; /* Internal node read */ uint8_t *p; /* Pointer into raw data buffer */ uint8_t *native; /* Pointer to native record info */ @@ -524,19 +519,21 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") HDmemset(&internal->cache_info, 0, sizeof(H5AC_info_t)); - /* Share common B-tree information */ - internal->shared = udata->bt2_shared; - H5RC_INC(internal->shared); + /* Set the B-tree header's file context for this operation */ + udata->hdr->f = f; - /* Get the pointer to the shared B-tree info */ - shared=(H5B2_shared_t *)H5RC_GET_OBJ(internal->shared); - HDassert(shared); + /* Increment ref. count on B-tree header */ + if(H5B2_hdr_incr(udata->hdr) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTINC, NULL, "can't increment ref. count on B-tree header") + + /* Share B-tree information */ + internal->hdr = udata->hdr; /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_BTREE, addr, shared->node_size, dxpl_id, shared->page)<0) + if(H5F_block_read(f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, dxpl_id, udata->hdr->page) < 0) HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree internal node") - p = shared->page; + p = udata->hdr->page; /* Magic number */ if(HDmemcmp(p, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC)) @@ -548,15 +545,15 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree internal node version") /* B-tree type */ - if (*p++ != (uint8_t)shared->type->id) - HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree type") + if(*p++ != (uint8_t)udata->hdr->type->id) + HGOTO_ERROR(H5E_BTREE, H5E_BADTYPE, NULL, "incorrect B-tree type") /* Allocate space for the native keys in memory */ - if((internal->int_native = (uint8_t *)H5FL_FAC_MALLOC(shared->node_info[udata->depth].nat_rec_fac)) == NULL) + if(NULL == (internal->int_native = (uint8_t *)H5FL_FAC_MALLOC(udata->hdr->node_info[udata->depth].nat_rec_fac))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree internal native keys") /* Allocate space for the node pointers in memory */ - if((internal->node_ptrs = (H5B2_node_ptr_t *)H5FL_FAC_MALLOC(shared->node_info[udata->depth].node_ptr_fac)) == NULL) + if(NULL == (internal->node_ptrs = (H5B2_node_ptr_t *)H5FL_FAC_MALLOC(udata->hdr->node_info[udata->depth].node_ptr_fac))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree internal node pointers") /* Set the number of records in the leaf & it's depth */ @@ -567,12 +564,12 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda native = internal->int_native; for(u = 0; u < internal->nrec; u++) { /* Decode record */ - if((shared->type->decode)(f, p, native) < 0) + if((udata->hdr->type->decode)(f, p, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, NULL, "unable to decode B-tree record") /* Move to next record */ - p += shared->rrec_size; - native += shared->type->nrec_size; + p += udata->hdr->rrec_size; + native += udata->hdr->type->nrec_size; } /* end for */ /* Deserialize node pointers for internal node */ @@ -580,9 +577,9 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda for(u = 0; u < internal->nrec + 1; u++) { /* Decode node pointer */ H5F_addr_decode(f, (const uint8_t **)&p, &(int_node_ptr->addr)); - UINT64DECODE_VAR(p, int_node_ptr->node_nrec, shared->max_nrec_size); + UINT64DECODE_VAR(p, int_node_ptr->node_nrec, udata->hdr->max_nrec_size); if(udata->depth > 1) - UINT64DECODE_VAR(p, int_node_ptr->all_nrec, shared->node_info[udata->depth - 1].cum_max_nrec_size) + UINT64DECODE_VAR(p, int_node_ptr->all_nrec, udata->hdr->node_info[udata->depth - 1].cum_max_nrec_size) else int_node_ptr->all_nrec = int_node_ptr->node_nrec; @@ -591,13 +588,13 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda } /* end for */ /* Compute checksum on internal node */ - computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); + computed_chksum = H5_checksum_metadata(udata->hdr->page, (size_t)(p - udata->hdr->page), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check parsing */ - HDassert((size_t)(p - shared->page) <= shared->node_size); + HDassert((size_t)(p - udata->hdr->page) <= udata->hdr->node_size); /* Verify checksum */ if(stored_chksum != computed_chksum) @@ -623,11 +620,6 @@ done: * Programmer: Quincey Koziol * koziol@ncsa.uiuc.edu * Feb 3 2005 - * Changes: JRM -- 8/21/06 - * Added the flags_ptr parameter. This parameter exists to - * allow the flush routine to report to the cache if the - * entry is resized or renamed as a result of the flush. - * *flags_ptr is set to H5C_CALLBACK__NO_FLAGS_SET on entry. * *------------------------------------------------------------------------- */ @@ -642,20 +634,19 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr HDassert(f); HDassert(H5F_addr_defined(addr)); HDassert(internal); + HDassert(internal->hdr); if(internal->cache_info.is_dirty) { - H5B2_shared_t *shared; /* Shared B-tree information */ uint8_t *p; /* Pointer into raw data buffer */ uint8_t *native; /* Pointer to native record info */ H5B2_node_ptr_t *int_node_ptr; /* Pointer to node pointer info */ uint32_t metadata_chksum; /* Computed metadata checksum value */ unsigned u; /* Local index variable */ - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(internal->shared); - HDassert(shared); + /* Set the B-tree header's file context for this operation */ + internal->hdr->f = f; - p = shared->page; + p = internal->hdr->page; /* Magic number */ HDmemcpy(p, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC); @@ -665,19 +656,19 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr *p++ = H5B2_INT_VERSION; /* B-tree type */ - *p++ = shared->type->id; - HDassert((size_t)(p - shared->page) == (H5B2_INT_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM)); + *p++ = internal->hdr->type->id; + HDassert((size_t)(p - internal->hdr->page) == (H5B2_INT_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM)); /* Serialize records for internal node */ native = internal->int_native; for(u = 0; u < internal->nrec; u++) { /* Encode record */ - if((shared->type->encode)(f, p, native) < 0) + if((internal->hdr->type->encode)(f, p, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record") /* Move to next record */ - p += shared->rrec_size; - native += shared->type->nrec_size; + p += internal->hdr->rrec_size; + native += internal->hdr->type->nrec_size; } /* end for */ /* Serialize node pointers for internal node */ @@ -685,23 +676,23 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr for(u = 0; u < internal->nrec + 1; u++) { /* Encode node pointer */ H5F_addr_encode(f, &p, int_node_ptr->addr); - UINT64ENCODE_VAR(p, int_node_ptr->node_nrec, shared->max_nrec_size); + UINT64ENCODE_VAR(p, int_node_ptr->node_nrec, internal->hdr->max_nrec_size); if(internal->depth > 1) - UINT64ENCODE_VAR(p, int_node_ptr->all_nrec, shared->node_info[internal->depth - 1].cum_max_nrec_size); + UINT64ENCODE_VAR(p, int_node_ptr->all_nrec, internal->hdr->node_info[internal->depth - 1].cum_max_nrec_size); /* Move to next node pointer */ int_node_ptr++; } /* end for */ /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); + metadata_chksum = H5_checksum_metadata(internal->hdr->page, (size_t)(p - internal->hdr->page), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); /* Write the B-tree internal node */ - HDassert((size_t)(p - shared->page) <= shared->node_size); - if(H5F_block_write(f, H5FD_MEM_BTREE, addr, shared->node_size, dxpl_id, shared->page) < 0) + HDassert((size_t)(p - internal->hdr->page) <= internal->hdr->node_size); + if(H5F_block_write(f, H5FD_MEM_BTREE, addr, internal->hdr->node_size, dxpl_id, internal->hdr->page) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree internal node to disk") internal->cache_info.is_dirty = FALSE; @@ -732,7 +723,6 @@ done: herr_t H5B2_cache_internal_dest(H5F_t *f, H5B2_internal_t *internal) { - H5B2_shared_t *shared; /* Shared B-tree information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5B2_cache_internal_dest) @@ -741,36 +731,36 @@ H5B2_cache_internal_dest(H5F_t *f, H5B2_internal_t *internal) * Check arguments. */ HDassert(internal); + HDassert(internal->hdr); /* If we're going to free the space on disk, the address must be valid */ HDassert(!internal->cache_info.free_file_space_on_destroy || H5F_addr_defined(internal->cache_info.addr)); - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(internal->shared); - HDassert(shared); - /* Check for freeing file space for B-tree internal node */ if(internal->cache_info.free_file_space_on_destroy) { /* Release the space on disk */ /* (XXX: Nasty usage of internal DXPL value! -QAK) */ - if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, internal->cache_info.addr, (hsize_t)shared->node_size) < 0) + if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, internal->cache_info.addr, (hsize_t)internal->hdr->node_size) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree internal node") } /* end if */ + /* Set the B-tree header's file context for this operation */ + internal->hdr->f = f; + /* Release internal node's native key buffer */ if(internal->int_native) - H5FL_FAC_FREE(shared->node_info[internal->depth].nat_rec_fac, internal->int_native); + H5FL_FAC_FREE(internal->hdr->node_info[internal->depth].nat_rec_fac, internal->int_native); /* Release internal node's node pointer buffer */ if(internal->node_ptrs) - H5FL_FAC_FREE(shared->node_info[internal->depth].node_ptr_fac, internal->node_ptrs); + H5FL_FAC_FREE(internal->hdr->node_info[internal->depth].node_ptr_fac, internal->node_ptrs); - /* Decrement reference count on shared B-tree info */ - if(internal->shared) - H5RC_DEC(internal->shared); + /* Decrement ref. count on B-tree header */ + if(H5B2_hdr_decr(internal->hdr) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTDEC, FAIL, "can't decrement ref. count on B-tree header") /* Free B-tree internal node info */ - (void)H5FL_FREE(H5B2_internal_t, internal); + H5FL_FREE(H5B2_internal_t, internal); done: FUNC_LEAVE_NOAPI(ret_value) @@ -832,20 +822,15 @@ done: static herr_t H5B2_cache_internal_size(const H5F_t UNUSED *f, const H5B2_internal_t *internal, size_t *size_ptr) { - H5B2_shared_t *shared; /* Shared B-tree information */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_cache_internal_size) /* check arguments */ HDassert(internal); + HDassert(internal->hdr); HDassert(size_ptr); - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(internal->shared); - HDassert(shared); - /* Set size value */ - *size_ptr = shared->node_size; + *size_ptr = internal->hdr->node_size; FUNC_LEAVE_NOAPI(SUCCEED) } /* H5B2_cache_internal_size() */ @@ -857,7 +842,6 @@ H5B2_cache_internal_size(const H5F_t UNUSED *f, const H5B2_internal_t *internal, * Purpose: Loads a B-tree leaf from the disk. * * Return: Success: Pointer to a new B-tree leaf node. - * * Failure: NULL * * Programmer: Quincey Koziol @@ -867,11 +851,10 @@ H5B2_cache_internal_size(const H5F_t UNUSED *f, const H5B2_internal_t *internal, *------------------------------------------------------------------------- */ static H5B2_leaf_t * -H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_bt2_shared) +H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_hdr) { const unsigned *nrec = (const unsigned *)_nrec; - H5RC_t *bt2_shared = (H5RC_t *)_bt2_shared; /* Shared B-tree information */ - H5B2_shared_t *shared; /* Shared B-tree information */ + H5B2_hdr_t *hdr = (H5B2_hdr_t *)_hdr; /* B-tree header information */ H5B2_leaf_t *leaf = NULL; /* Pointer to lead node loaded */ uint8_t *p; /* Pointer into raw data buffer */ uint8_t *native; /* Pointer to native keys */ @@ -885,25 +868,28 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v /* Check arguments */ HDassert(f); HDassert(H5F_addr_defined(addr)); - HDassert(bt2_shared); + HDassert(hdr); + /* Allocate new leaf node and reset cache info */ if(NULL == (leaf = H5FL_MALLOC(H5B2_leaf_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") HDmemset(&leaf->cache_info, 0, sizeof(H5AC_info_t)); - /* Share common B-tree information */ - leaf->shared = bt2_shared; - H5RC_INC(leaf->shared); + /* Set the B-tree header's file context for this operation */ + hdr->f = f; + + /* Increment ref. count on B-tree header */ + if(H5B2_hdr_incr(hdr) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTINC, NULL, "can't increment ref. count on B-tree header") - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(leaf->shared); - HDassert(shared); + /* Share B-tree header information */ + leaf->hdr = hdr; /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_BTREE, addr, shared->node_size, dxpl_id, shared->page) < 0) + if(H5F_block_read(f, H5FD_MEM_BTREE, addr, hdr->node_size, dxpl_id, hdr->page) < 0) HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree leaf node") - p = shared->page; + p = hdr->page; /* Magic number */ if(HDmemcmp(p, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC)) @@ -915,12 +901,12 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree leaf node version") /* B-tree type */ - if(*p++ != (uint8_t)shared->type->id) + if(*p++ != (uint8_t)hdr->type->id) HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree type") /* Allocate space for the native keys in memory */ - if((leaf->leaf_native = (uint8_t *)H5FL_FAC_MALLOC(shared->node_info[0].nat_rec_fac)) == NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree leaf native keys") + if(NULL == (leaf->leaf_native = (uint8_t *)H5FL_FAC_MALLOC(hdr->node_info[0].nat_rec_fac))) + HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree leaf native keys") /* Set the number of records in the leaf */ leaf->nrec = *nrec; @@ -929,22 +915,22 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v native = leaf->leaf_native; for(u = 0; u < leaf->nrec; u++) { /* Decode record */ - if((shared->type->decode)(f, p, native) < 0) + if((hdr->type->decode)(f, p, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record") /* Move to next record */ - p += shared->rrec_size; - native += shared->type->nrec_size; + p += hdr->rrec_size; + native += hdr->type->nrec_size; } /* end for */ /* Compute checksum on internal node */ - computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); + computed_chksum = H5_checksum_metadata(hdr->page, (size_t)(p - hdr->page), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check parsing */ - HDassert((size_t)(p - shared->page) <= shared->node_size); + HDassert((size_t)(p - hdr->page) <= hdr->node_size); /* Verify checksum */ if(stored_chksum != computed_chksum) @@ -955,7 +941,7 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v done: if(!ret_value && leaf) - (void)H5B2_cache_leaf_dest(f,leaf); + (void)H5B2_cache_leaf_dest(f, leaf); FUNC_LEAVE_NOAPI(ret_value) } /* H5B2_cache_leaf_load() */ /*lint !e818 Can't make udata a pointer to const */ @@ -971,13 +957,6 @@ done: * koziol@ncsa.uiuc.edu * Feb 2 2005 * - * Changes: JRM -- 8/21/06 - * Added the flags_ptr parameter. This parameter exists to - * allow the flush routine to report to the cache if the - * entry is resized or renamed as a result of the flush. - * *flags_ptr is set to H5C_CALLBACK__NO_FLAGS_SET on entry. - * - * *------------------------------------------------------------------------- */ static herr_t @@ -991,19 +970,18 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5 HDassert(f); HDassert(H5F_addr_defined(addr)); HDassert(leaf); + HDassert(leaf->hdr); if(leaf->cache_info.is_dirty) { - H5B2_shared_t *shared; /* Shared B-tree information */ uint8_t *p; /* Pointer into raw data buffer */ uint8_t *native; /* Pointer to native keys */ uint32_t metadata_chksum; /* Computed metadata checksum value */ unsigned u; /* Local index variable */ - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(leaf->shared); - HDassert(shared); + /* Set the B-tree header's file context for this operation */ + leaf->hdr->f = f; - p = shared->page; + p = leaf->hdr->page; /* magic number */ HDmemcpy(p, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC); @@ -1013,30 +991,30 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5 *p++ = H5B2_LEAF_VERSION; /* b-tree type */ - *p++ = shared->type->id; - HDassert((size_t)(p - shared->page) == (H5B2_LEAF_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM)); + *p++ = leaf->hdr->type->id; + HDassert((size_t)(p - leaf->hdr->page) == (H5B2_LEAF_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM)); /* Serialize records for leaf node */ native = leaf->leaf_native; for(u = 0; u < leaf->nrec; u++) { /* Encode record */ - if((shared->type->encode)(f, p, native) < 0) + if((leaf->hdr->type->encode)(f, p, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record") /* Move to next record */ - p += shared->rrec_size; - native += shared->type->nrec_size; + p += leaf->hdr->rrec_size; + native += leaf->hdr->type->nrec_size; } /* end for */ /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); + metadata_chksum = H5_checksum_metadata(leaf->hdr->page, (size_t)(p - leaf->hdr->page), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); /* Write the B-tree leaf node */ - HDassert((size_t)(p - shared->page) <= shared->node_size); - if(H5F_block_write(f, H5FD_MEM_BTREE, addr, shared->node_size, dxpl_id, shared->page) < 0) + HDassert((size_t)(p - leaf->hdr->page) <= leaf->hdr->node_size); + if(H5F_block_write(f, H5FD_MEM_BTREE, addr, leaf->hdr->node_size, dxpl_id, leaf->hdr->page) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree leaf node to disk") leaf->cache_info.is_dirty = FALSE; @@ -1067,7 +1045,6 @@ done: herr_t H5B2_cache_leaf_dest(H5F_t *f, H5B2_leaf_t *leaf) { - H5B2_shared_t *shared; /* Shared B-tree information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5B2_cache_leaf_dest) @@ -1076,32 +1053,32 @@ H5B2_cache_leaf_dest(H5F_t *f, H5B2_leaf_t *leaf) * Check arguments. */ HDassert(leaf); + HDassert(leaf->hdr); /* If we're going to free the space on disk, the address must be valid */ HDassert(!leaf->cache_info.free_file_space_on_destroy || H5F_addr_defined(leaf->cache_info.addr)); - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(leaf->shared); - HDassert(shared); - /* Check for freeing file space for B-tree leaf node */ if(leaf->cache_info.free_file_space_on_destroy) { /* Release the space on disk */ /* (XXX: Nasty usage of internal DXPL value! -QAK) */ - if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, leaf->cache_info.addr, (hsize_t)shared->node_size) < 0) + if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, leaf->cache_info.addr, (hsize_t)leaf->hdr->node_size) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree leaf node") } /* end if */ + /* Set the B-tree header's file context for this operation */ + leaf->hdr->f = f; + /* Release leaf's native key buffer */ if(leaf->leaf_native) - H5FL_FAC_FREE(shared->node_info[0].nat_rec_fac, leaf->leaf_native); + H5FL_FAC_FREE(leaf->hdr->node_info[0].nat_rec_fac, leaf->leaf_native); - /* Decrement reference count on shared B-tree info */ - if(leaf->shared) - H5RC_DEC(leaf->shared); + /* Decrement ref. count on B-tree header */ + if(H5B2_hdr_decr(leaf->hdr) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTDEC, FAIL, "can't decrement ref. count on B-tree header") /* Free B-tree leaf node info */ - (void)H5FL_FREE(H5B2_leaf_t, leaf); + H5FL_FREE(H5B2_leaf_t, leaf); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1163,20 +1140,15 @@ done: static herr_t H5B2_cache_leaf_size(const H5F_t UNUSED *f, const H5B2_leaf_t *leaf, size_t *size_ptr) { - H5B2_shared_t *shared; /* Shared B-tree information */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_cache_leaf_size) /* check arguments */ HDassert(leaf); + HDassert(leaf->hdr); HDassert(size_ptr); - /* Get the pointer to the shared B-tree info */ - shared = (H5B2_shared_t *)H5RC_GET_OBJ(leaf->shared); - HDassert(shared); - /* Set size value */ - *size_ptr = shared->node_size; + *size_ptr = leaf->hdr->node_size; FUNC_LEAVE_NOAPI(SUCCEED) } /* H5B2_cache_leaf_size() */ |