From c227f4ffa55010ea480773d9df9b68baba2b08e0 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sun, 11 Mar 2007 22:00:31 -0500 Subject: [svn-r13499] Description: Avoid storing the # of attributes in the "attribute info" message and regenerate it when the object is opened. Tested on: FreeBSD/32 6.2 (duty) --- src/H5Aint.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/H5Apkg.h | 2 ++ src/H5Oainfo.c | 8 ++------ src/H5Oattribute.c | 18 +++++++++--------- src/H5Ocache.c | 5 +++++ src/H5Ocopy.c | 1 + src/H5Opkg.h | 1 + src/H5Otest.c | 8 ++++---- 8 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/H5Aint.c b/src/H5Aint.c index 18b49f8..1af97d9 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -616,3 +616,53 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_attr_release_table() */ + +/*------------------------------------------------------------------------- + * Function: H5A_get_ainfo + * + * Purpose: Retrieves the "attribute info" message for an object. Also + * sets the number of attributes correctly, if it isn't set up yet. + * + * Return: Success: Ptr to message in native format. + * Failure: NULL + * + * Programmer: Quincey Koziol + * koziol@hdfgroup.org + * Mar 11 2007 + * + *------------------------------------------------------------------------- + */ +H5O_ainfo_t * +H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo) +{ + H5O_ainfo_t *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5A_get_ainfo, NULL) + + /* check arguments */ + HDassert(f); + HDassert(oh); + + /* Retrieve the "attribute info" structure */ + if(ret_value = H5O_msg_read_real(f, dxpl_id, oh, H5O_AINFO_ID, ainfo)) { + /* Check if we don't know how many attributes there are */ + if(ret_value->nattrs == HSIZET_MAX) { + /* Check if we are using "dense" attribute storage */ + if(H5F_addr_defined(ret_value->fheap_addr)) { + /* Retrieve # of records in "name" B-tree */ + /* (should be same # of records in all indices) */ + if(H5B2_get_nrec(f, dxpl_id, H5A_BT2_NAME, ret_value->name_bt2_addr, &ret_value->nattrs) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't retrieve # of records in index") + } /* end if */ + else + /* Retrieve # of attributes from object header */ + ret_value->nattrs = oh->attr_msgs_seen; + } /* end if */ + } /* end if */ + else + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "attribute info message not present") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5A_get_ainfo() */ + diff --git a/src/H5Apkg.h b/src/H5Apkg.h index c3fe261..3d96a9a 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -184,6 +184,8 @@ H5_DLL H5A_t *H5A_copy(H5A_t *new_attr, const H5A_t *old_attr); H5_DLL herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo); H5_DLL herr_t H5A_free(H5A_t *attr); H5_DLL herr_t H5A_close(H5A_t *attr); +H5_DLL H5O_ainfo_t *H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, + H5O_ainfo_t *ainfo); /* Attribute "dense" storage routines */ H5_DLL herr_t H5A_dense_create(H5F_t *f, hid_t dxpl_id, H5O_ainfo_t *ainfo); diff --git a/src/H5Oainfo.c b/src/H5Oainfo.c index 655cb5e..c49786d 100644 --- a/src/H5Oainfo.c +++ b/src/H5Oainfo.c @@ -127,8 +127,8 @@ H5O_ainfo_decode(H5F_t *f, hid_t UNUSED dxpl_id, unsigned UNUSED mesg_flags, ainfo->track_corder = (flags & H5O_AINFO_TRACK_CORDER) ? TRUE : FALSE; ainfo->index_corder = (flags & H5O_AINFO_INDEX_CORDER) ? TRUE : FALSE; - /* Number of attributes on the object */ - H5F_DECODE_LENGTH(f, p, ainfo->nattrs) + /* Set the number of attributes on the object to an invalid value, so we query it later */ + ainfo->nattrs = HSIZET_MAX; /* Max. creation order value for the object */ if(ainfo->track_corder) @@ -193,9 +193,6 @@ H5O_ainfo_encode(H5F_t *f, hbool_t UNUSED disable_shared, uint8_t *p, const void flags |= ainfo->index_corder ? H5O_AINFO_INDEX_CORDER : 0; *p++ = flags; - /* Number of attributes on the object */ - H5F_ENCODE_LENGTH(f, p, ainfo->nattrs) - /* Max. creation order value for the object */ if(ainfo->track_corder) UINT16ENCODE(p, ainfo->max_crt_idx); @@ -283,7 +280,6 @@ H5O_ainfo_size(const H5F_t *f, hbool_t UNUSED disable_shared, const void *_mesg) /* Set return value */ ret_value = 1 /* Version */ + 1 /* Index flags */ - + H5F_SIZEOF_SIZE(f) /* Number of attributes */ + (ainfo->track_corder ? 2 : 0) /* Curr. max. creation order value */ + H5F_SIZEOF_ADDR(f) /* Address of fractal heap to store "dense" attributes */ + H5F_SIZEOF_ADDR(f) /* Address of v2 B-tree for indexing names of attributes */ diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index f824ad9..45c1f8a 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -231,7 +231,7 @@ H5O_attr_create(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr) if(oh->version > H5O_VERSION_1) { hbool_t new_ainfo = FALSE; /* Flag to indicate that the attribute information is new */ - if(NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) { + if(NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) { /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -468,7 +468,7 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -748,7 +748,7 @@ H5O_attr_write(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -973,7 +973,7 @@ H5O_attr_rename(const H5O_loc_t *loc, hid_t dxpl_id, const char *old_name, /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -1066,7 +1066,7 @@ H5O_attr_iterate_real(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id, /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -1337,7 +1337,7 @@ H5O_attr_remove(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo))) + if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -1423,7 +1423,7 @@ H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo))) + if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -1512,7 +1512,7 @@ H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh) H5O_ainfo_t ainfo; /* Attribute information for object */ /* Attempt to get the attribute information from the object header */ - if(H5O_msg_read_real(f, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) ret_value = ainfo.nattrs; else { /* Clear error stack from not finding attribute info */ @@ -1643,7 +1643,7 @@ H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(loc->file, dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); diff --git a/src/H5Ocache.c b/src/H5Ocache.c index 774055a..5259a8e 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -611,6 +611,11 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, /* Increment the count of link messages */ oh->link_msgs_seen++; } /* end if */ + /* Check if next message to examine is an attribute message */ + else if(H5O_ATTR_ID == oh->mesg[curmesg].type->id) { + /* Increment the count of attribute messages */ + oh->attr_msgs_seen++; + } /* end if */ } /* end for */ } /* end while */ diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 748d780..5549cd6 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -343,6 +343,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, oh_dst->flags = oh_src->flags; oh_dst->skipped_mesg_size = oh_src->skipped_mesg_size; oh_dst->link_msgs_seen = oh_src->link_msgs_seen; + oh_dst->attr_msgs_seen = oh_src->attr_msgs_seen; oh_dst->sizeof_size = H5F_SIZEOF_SIZE(oloc_dst->file); oh_dst->sizeof_addr = H5F_SIZEOF_ADDR(oloc_dst->file); diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 3df402f..0fc1aa6 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -267,6 +267,7 @@ struct H5O_t { H5O_mesg_t *mesg; /*array of messages */ size_t skipped_mesg_size; /*size of skipped messages (for sanity checking) */ size_t link_msgs_seen; /* # of link messages seen when loading header */ + size_t attr_msgs_seen; /* # of attribute messages seen when loading header */ /* Chunk management (not stored) */ size_t nchunks; /*number of chunks */ diff --git a/src/H5Otest.c b/src/H5Otest.c index dc516c6..41c79ef 100644 --- a/src/H5Otest.c +++ b/src/H5Otest.c @@ -112,7 +112,7 @@ H5O_is_attr_dense_test(hid_t oid) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(oloc->file, H5AC_ind_dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -174,7 +174,7 @@ H5O_is_attr_empty_test(hid_t oid) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5O_msg_read_real(oloc->file, H5AC_ind_dxpl_id, oh, H5O_AINFO_ID, &ainfo))) + if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo))) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -252,7 +252,7 @@ H5O_num_attrs_test(hid_t oid, hsize_t *nattrs) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(oloc->file, H5AC_ind_dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); @@ -327,7 +327,7 @@ H5O_attr_dense_info_test(hid_t oid, hsize_t *name_count, hsize_t *corder_count) /* Check for attribute info stored */ ainfo.fheap_addr = HADDR_UNDEF; - if(oh->version > H5O_VERSION_1 && NULL == H5O_msg_read_real(oloc->file, H5AC_ind_dxpl_id, oh, H5O_AINFO_ID, &ainfo)) + if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) /* Clear error stack from not finding attribute info */ H5E_clear_stack(NULL); -- cgit v0.12