summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5B2.c44
-rw-r--r--src/H5B2cache.c43
-rw-r--r--src/H5B2dbg.c214
-rw-r--r--src/H5B2pkg.h16
-rw-r--r--src/H5B2private.h9
-rw-r--r--src/H5B2test.c187
-rwxr-xr-xsrc/Makefile.am3
-rw-r--r--src/Makefile.in19
8 files changed, 479 insertions, 56 deletions
diff --git a/src/H5B2.c b/src/H5B2.c
index e1550a1..05d8f54 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -47,10 +47,6 @@
/* Number of records that fit into leaf node */
#define H5B2_NUM_LEAF_REC(n,r) (((n)-H5B2_OVERHEAD_SIZE)/(r))
-/* Macro to retrieve pointer to i'th native key for leaf node */
-#define H5B2_INT_NKEY(i,shared,idx) ((i)->int_native+(shared)->nat_off[(idx)])
-#define H5B2_LEAF_NKEY(l,shared,idx) ((l)->leaf_native+(shared)->nat_off[(idx)])
-
/* Local typedefs */
@@ -62,7 +58,7 @@ static int H5B2_locate_record(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
unsigned nrec, size_t *rec_off, const uint8_t *native,
const void *udata);
static herr_t H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2,
- const H5B2_shared_t *shared);
+ H5RC_t *bt2_shared);
static herr_t H5B2_create_internal(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2,
H5B2_node_ptr_t *node_ptr);
@@ -363,14 +359,19 @@ H5B2_locate_record(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, const H5B2_shared_t *shared)
+H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, H5RC_t *bt2_shared)
{
+ H5B2_shared_t *shared; /* B-tree's shared info */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5B2_split_root)
HDassert(f);
HDassert(bt2);
+ HDassert(bt2_shared);
+
+ /* Get the pointer to the shared B-tree info */
+ shared=H5RC_GET_OBJ(bt2_shared);
HDassert(shared);
if(bt2->depth==0) {
@@ -393,13 +394,13 @@ H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, const H5B2_shared_t *share
old_leaf_ptr = bt2->root;
/* Protect both leafs */
- if (NULL == (old_leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, old_leaf_ptr.addr, shared->type, &old_leaf_ptr, H5AC_WRITE)))
+ if (NULL == (old_leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, old_leaf_ptr.addr, &(old_leaf_ptr.node_nrec), bt2_shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node")
- if (NULL == (new_leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, new_leaf_ptr.addr, shared->type, &new_leaf_ptr, H5AC_WRITE)))
+ if (NULL == (new_leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, new_leaf_ptr.addr, &(new_leaf_ptr.node_nrec), bt2_shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node")
/* Copy "upper half" of records to new leaf */
- HDmemcpy(new_leaf->leaf_native,H5B2_LEAF_NKEY(old_leaf,shared,mid_record+1),shared->type->nkey_size*(shared->split_leaf_nrec-(mid_record+1)));
+ HDmemcpy(new_leaf->leaf_native,H5B2_LEAF_NREC(old_leaf,shared,mid_record+1),shared->type->nkey_size*(shared->split_leaf_nrec-(mid_record+1)));
/* Create new internal node */
new_int_ptr.all_nrec=new_int_ptr.node_nrec=0;
@@ -407,11 +408,11 @@ H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, const H5B2_shared_t *share
HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to create new internal node")
/* Protect new internal node */
- if (NULL == (new_int = H5AC_protect(f, dxpl_id, H5AC_BT2_INT, new_int_ptr.addr, shared->type, &new_int_ptr, H5AC_WRITE)))
+ if (NULL == (new_int = H5AC_protect(f, dxpl_id, H5AC_BT2_INT, new_int_ptr.addr, &(new_int_ptr.node_nrec), bt2_shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree internal node")
/* Copy "middle" record to new internal node */
- HDmemcpy(new_int->int_native,H5B2_LEAF_NKEY(old_leaf,shared,mid_record),shared->type->nkey_size);
+ HDmemcpy(new_int->int_native,H5B2_LEAF_NREC(old_leaf,shared,mid_record),shared->type->nkey_size);
/* Update record counts in leaf nodes */
old_leaf_ptr.all_nrec = old_leaf_ptr.node_nrec = old_leaf->nrec = mid_record;
@@ -481,6 +482,8 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
void *udata)
{
H5B2_t *bt2=NULL; /* Pointer to the B-tree header */
+ H5RC_t *bt2_shared=NULL; /* Pointer to ref-counter for shared B-tree info */
+ hbool_t incr_rc=FALSE; /* Flag to indicate that we've incremented the B-tree's shared info reference count */
H5B2_shared_t *shared; /* Pointer to B-tree's shared information */
H5B2_node_ptr_t leaf_ptr; /* Node pointer info for leaf node */
H5B2_leaf_t *leaf=NULL; /* Pointer to leaf node */
@@ -502,6 +505,11 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
shared=H5RC_GET_OBJ(bt2->shared);
HDassert(shared);
+ /* Safely grab pointer to reference counted shared B-tree info, so we can release the B-tree header if necessary */
+ bt2_shared=bt2->shared;
+ H5RC_INC(bt2_shared);
+ incr_rc=TRUE;
+
/* Check if the root node is allocated yet */
if(!H5F_addr_defined(bt2->root.addr)) {
/* Create root node as leaf node in B-tree */
@@ -515,7 +523,7 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
else if((bt2->depth==0 && bt2->root.node_nrec==shared->split_leaf_nrec) ||
(bt2->depth>0 && bt2->root.node_nrec==shared->split_int_nrec)) {
/* Split root node */
- if(H5B2_split_root(f, dxpl_id, bt2, shared)<0)
+ if(H5B2_split_root(f, dxpl_id, bt2, bt2_shared)<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split root node")
} /* end if */
@@ -546,7 +554,7 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
/* Find correct leaf to insert node into */
while(depth>0) {
/* Lock B-tree current node */
- if (NULL == (internal = H5AC_protect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr->addr, shared->type, curr_node_ptr, H5AC_WRITE)))
+ if (NULL == (internal = H5AC_protect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr->addr, &(curr_node_ptr->node_nrec), bt2_shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree internal node")
/* Set information for current (root) node */
@@ -631,7 +639,7 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split child node")
HDassert((leaf_ptr.node_nrec-1)<shared->split_leaf_nrec); /* node pointer to leaf has already been incremented */
/* Look up the B-tree leaf node */
- if (NULL == (leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, leaf_ptr.addr, shared->type, &leaf_ptr, H5AC_WRITE)))
+ if (NULL == (leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, leaf_ptr.addr, &(leaf_ptr.node_nrec), bt2_shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node")
/* Sanity check number of records */
@@ -656,11 +664,11 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split child node")
/* Make room for new record */
if((unsigned)idx<leaf->nrec)
- HDmemmove(H5B2_LEAF_NKEY(leaf,shared,idx+1),H5B2_LEAF_NKEY(leaf,shared,idx),shared->type->nkey_size*(leaf->nrec-idx));
+ HDmemmove(H5B2_LEAF_NREC(leaf,shared,idx+1),H5B2_LEAF_NREC(leaf,shared,idx),shared->type->nkey_size*(leaf->nrec-idx));
} /* end else */
/* Make callback to store record in native form */
- if((shared->type->store)(f,dxpl_id,udata,H5B2_LEAF_NKEY(leaf,shared,idx))<0) {
+ if((shared->type->store)(f,dxpl_id,udata,H5B2_LEAF_NREC(leaf,shared,idx))<0) {
/* Release the B-tree leaf node */
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, leaf_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree leaf node")
@@ -679,6 +687,10 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split child node")
HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree leaf node")
done:
+ /* Check if we need to decrement the reference count for the B-tree's shared info */
+ if(incr_rc)
+ H5RC_DEC(bt2_shared);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2_insert() */
diff --git a/src/H5B2cache.c b/src/H5B2cache.c
index fa9538d..aaa72f9 100644
--- a/src/H5B2cache.c
+++ b/src/H5B2cache.c
@@ -14,16 +14,11 @@
/*-------------------------------------------------------------------------
*
- * Created: H5B2.c
+ * Created: H5B2cache.c
* Jan 31 2005
* Quincey Koziol <koziol@ncsa.uiuc.edu>
*
- * Purpose: Implements a B-tree, with several modifications from
- * the "standard" methods.
- *
- * Please see the documentation in:
- * doc/html/TechNotes/Btrees.html for a full description
- * of how they work, etc.
+ * Purpose: Implement v2 B-tree metadata cache methods.
*
*-------------------------------------------------------------------------
*/
@@ -52,11 +47,11 @@ static H5B2_t *H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const
static herr_t H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_t *b);
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_leaf_t *H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata);
+static H5B2_leaf_t *H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_shared);
static herr_t H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_leaf_t *l);
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);
-static H5B2_internal_t *H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata);
+static H5B2_internal_t *H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_shared);
static herr_t H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_internal_t *i);
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);
@@ -407,12 +402,12 @@ H5B2_cache_hdr_size(const H5F_t *f, const H5B2_t UNUSED *bt2, size_t *size_ptr)
*-------------------------------------------------------------------------
*/
static H5B2_leaf_t *
-H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2, void *_node_ptr)
+H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_bt2_shared)
{
- const H5B2_t *bt2 = (const H5B2_t *)_bt2;
- H5B2_node_ptr_t *node_ptr = (H5B2_node_ptr_t *)_node_ptr;
- H5B2_leaf_t *leaf = NULL;
+ 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_leaf_t *leaf = NULL;
uint8_t *p; /* Pointer into raw data buffer */
uint8_t *native; /* Pointer to native keys */
unsigned u; /* Local index variable */
@@ -423,14 +418,14 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2, vo
/* Check arguments */
HDassert(f);
HDassert(H5F_addr_defined(addr));
- HDassert(bt2);
+ HDassert(bt2_shared);
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;
+ leaf->shared = bt2_shared;
H5RC_INC(leaf->shared);
/* Get the pointer to the shared B-tree info */
@@ -461,7 +456,7 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2, vo
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree leaf native keys")
/* Set the number of records in the leaf */
- leaf->nrec = node_ptr->node_nrec;
+ leaf->nrec = *nrec;
/* Deserialize records for leaf node */
native=leaf->leaf_native;
@@ -695,12 +690,12 @@ H5B2_cache_leaf_size(const H5F_t UNUSED *f, const H5B2_leaf_t *leaf, size_t *siz
*-------------------------------------------------------------------------
*/
static H5B2_internal_t *
-H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2, void *_node_ptr)
+H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, void *_bt2_shared)
{
- const H5B2_t *bt2 = (const H5B2_t *)_bt2;
- H5B2_node_ptr_t *node_ptr = (H5B2_node_ptr_t *)_node_ptr;
- H5B2_internal_t *internal = NULL;
+ const unsigned *nrec = (const unsigned *)_nrec;
+ H5RC_t *bt2_shared = (H5RC_t *)_bt2_shared; /* Ref counter for shared B-tree info */
H5B2_shared_t *shared; /* Shared B-tree information */
+ H5B2_internal_t *internal = NULL;
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 */
@@ -712,14 +707,14 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2
/* Check arguments */
HDassert(f);
HDassert(H5F_addr_defined(addr));
- HDassert(bt2);
+ HDassert(bt2_shared);
if (NULL==(internal = H5FL_MALLOC(H5B2_internal_t)))
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 = bt2->shared;
+ internal->shared = bt2_shared;
H5RC_INC(internal->shared);
/* Get the pointer to the shared B-tree info */
@@ -754,7 +749,7 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree internal node pointers")
/* Set the number of records in the leaf */
- internal->nrec = node_ptr->node_nrec;
+ internal->nrec = *nrec;
/* Deserialize records for internal node */
native=internal->int_native;
@@ -768,7 +763,7 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_bt2
native += shared->type->nkey_size;
} /* end for */
- /* Serialize node pointers for internal node */
+ /* Deserialize node pointers for internal node */
int_node_ptr=internal->node_ptrs;
for(u=0; u<internal->nrec+1; u++) {
/* Decode node pointer */
diff --git a/src/H5B2dbg.c b/src/H5B2dbg.c
index bd18582..f0e3060 100644
--- a/src/H5B2dbg.c
+++ b/src/H5B2dbg.c
@@ -79,12 +79,14 @@ H5B2_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
*/
HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Tree type ID:",
- ((shared->type->id)==H5B2_GRP_NAME_ID ? "H5B2_GRP_NAME_ID" : "Unknown!"));
+ ((shared->type->id)==H5B2_TEST_ID ? "H5B2_TEST_ID" :
+ ((shared->type->id)==H5B2_GRP_NAME_ID ? "H5B2_GRP_NAME_ID" :
+ "Unknown!")));
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Size of node:",
shared->node_size);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
- "Size of raw (disk) key:",
+ "Size of raw (disk) record:",
shared->rkey_size);
HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Dirty flag:",
@@ -133,3 +135,211 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_int_debug
+ *
+ * Purpose: Prints debugging info about a B-tree internal node
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Feb 4 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth,
+ const H5B2_class_t *type, haddr_t hdr_addr, unsigned nrec)
+{
+ H5B2_t *bt2 = NULL;
+ H5B2_internal_t *internal = NULL;
+ H5B2_shared_t *shared; /* Shared B-tree information */
+ unsigned u; /* Local index variable */
+ char temp_str[128]; /* Temporary string, for formatting */
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5B2_int_debug, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ assert(f);
+ assert(H5F_addr_defined(addr));
+ assert(stream);
+ assert(indent >= 0);
+ assert(fwidth >= 0);
+
+ /*
+ * Load the B-tree header.
+ */
+ if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, hdr_addr, type, NULL, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree header")
+
+ /* Get the pointer to the shared B-tree info */
+ shared=H5RC_GET_OBJ(bt2->shared);
+ assert(shared);
+
+ /*
+ * Load the B-tree internal node
+ */
+ if (NULL == (internal = H5AC_protect(f, dxpl_id, H5AC_BT2_INT, addr, &nrec, bt2->shared, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree internal node")
+
+ /* Release the B-tree header */
+ if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, hdr_addr, bt2, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree header")
+ bt2 = NULL;
+
+ /*
+ * Print the values.
+ */
+ HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Tree type ID:",
+ ((shared->type->id)==H5B2_TEST_ID ? "H5B2_TEST_ID" :
+ ((shared->type->id)==H5B2_GRP_NAME_ID ? "H5B2_GRP_NAME_ID" :
+ "Unknown!")));
+ HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
+ "Size of node:",
+ shared->node_size);
+ HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
+ "Size of raw (disk) record:",
+ shared->rkey_size);
+ HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Dirty flag:",
+ internal->cache_info.is_dirty ? "True" : "False");
+ HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
+ "Number of records in node:",
+ internal->nrec);
+
+ /* Print all node pointers and records */
+ for(u=0; u<internal->nrec; u++) {
+ /* Print node pointer */
+ sprintf(temp_str,"Node pointer #%u: (all/node/addr)",u);
+ HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
+ temp_str,
+ internal->node_ptrs[u].all_nrec,
+ internal->node_ptrs[u].node_nrec,
+ internal->node_ptrs[u].addr);
+
+ /* Print record */
+ sprintf(temp_str,"Record #%u:",u);
+ HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
+ temp_str);
+ assert(H5B2_INT_NREC(internal,shared,u));
+ (void)(type->debug)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
+ H5B2_INT_NREC(internal,shared,u), NULL);
+ } /* end for */
+
+ /* Print final node pointer */
+ sprintf(temp_str,"Node pointer #%u: (all/node/addr)",u);
+ HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
+ temp_str,
+ internal->node_ptrs[u].all_nrec,
+ internal->node_ptrs[u].node_nrec,
+ internal->node_ptrs[u].addr);
+
+done:
+ if (internal && H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, addr, internal, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree internal node")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_leaf_debug
+ *
+ * Purpose: Prints debugging info about a B-tree leaf node
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Feb 7 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth,
+ const H5B2_class_t *type, haddr_t hdr_addr, unsigned nrec)
+{
+ H5B2_t *bt2 = NULL;
+ H5B2_leaf_t *leaf = NULL;
+ H5B2_shared_t *shared; /* Shared B-tree information */
+ unsigned u; /* Local index variable */
+ char temp_str[128]; /* Temporary string, for formatting */
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5B2_leaf_debug, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ assert(f);
+ assert(H5F_addr_defined(addr));
+ assert(stream);
+ assert(indent >= 0);
+ assert(fwidth >= 0);
+
+ /*
+ * Load the B-tree header.
+ */
+ if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, hdr_addr, type, NULL, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree header")
+
+ /* Get the pointer to the shared B-tree info */
+ shared=H5RC_GET_OBJ(bt2->shared);
+ assert(shared);
+
+ /*
+ * Load the B-tree leaf node
+ */
+ if (NULL == (leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, addr, &nrec, bt2->shared, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node")
+
+ /* Release the B-tree header */
+ if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, hdr_addr, bt2, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree header")
+ bt2 = NULL;
+
+ /*
+ * Print the values.
+ */
+ HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Tree type ID:",
+ ((shared->type->id)==H5B2_TEST_ID ? "H5B2_TEST_ID" :
+ ((shared->type->id)==H5B2_GRP_NAME_ID ? "H5B2_GRP_NAME_ID" :
+ "Unknown!")));
+ HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
+ "Size of node:",
+ shared->node_size);
+ HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
+ "Size of raw (disk) record:",
+ shared->rkey_size);
+ HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Dirty flag:",
+ leaf->cache_info.is_dirty ? "True" : "False");
+ HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
+ "Number of records in node:",
+ leaf->nrec);
+
+ /* Print all node pointers and records */
+ for(u=0; u<leaf->nrec; u++) {
+ /* Print record */
+ sprintf(temp_str,"Record #%u:",u);
+ HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
+ temp_str);
+ assert(H5B2_LEAF_NREC(leaf,shared,u));
+ (void)(type->debug)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
+ H5B2_LEAF_NREC(leaf,shared,u), NULL);
+ } /* end for */
+
+done:
+ if (leaf && H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, addr, leaf, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree leaf node")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+}
+
diff --git a/src/H5B2pkg.h b/src/H5B2pkg.h
index 001d0ca..b6aa65c 100644
--- a/src/H5B2pkg.h
+++ b/src/H5B2pkg.h
@@ -65,6 +65,11 @@
2 + /* Merge % of full (as integer, ie. "98" means 98%) */ \
H5B2_NODE_POINTER_SIZE(f)) /* Node pointer to root node in tree */
+/* Macro to retrieve pointer to i'th native key for leaf node */
+#define H5B2_INT_NREC(i,shared,idx) ((i)->int_native+(shared)->nat_off[(idx)])
+#define H5B2_LEAF_NREC(l,shared,idx) ((l)->leaf_native+(shared)->nat_off[(idx)])
+
+
/****************************/
/* Package Private Typedefs */
/****************************/
@@ -160,6 +165,11 @@ H5FL_EXTERN(H5B2_internal_t);
/* Declare a free list to manage the H5B2_leaf_t struct */
H5FL_EXTERN(H5B2_leaf_t);
+/* Internal v2 B-tree testing class */
+#ifdef H5B2_TESTING
+H5_DLLVAR const H5B2_class_t H5B2_TEST[1];
+#endif /* H5B2_TESTING */
+
/******************************/
/* Package Private Prototypes */
@@ -172,6 +182,12 @@ H5_DLL herr_t H5B2_cache_leaf_dest(H5F_t *f, H5B2_leaf_t *l);
H5_DLL herr_t H5B2_cache_internal_dest(H5F_t *f, H5B2_internal_t *i);
H5_DLL herr_t H5B2_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
FILE *stream, int indent, int fwidth, const H5B2_class_t *type);
+H5_DLL herr_t H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
+ FILE *stream, int indent, int fwidth, const H5B2_class_t *type,
+ haddr_t hdr_addr, unsigned nrec);
+H5_DLL herr_t H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
+ FILE *stream, int indent, int fwidth, const H5B2_class_t *type,
+ haddr_t hdr_addr, unsigned nrec);
#endif /* _H5B2pkg_H */
diff --git a/src/H5B2private.h b/src/H5B2private.h
index bd1515a..2635cae 100644
--- a/src/H5B2private.h
+++ b/src/H5B2private.h
@@ -49,12 +49,9 @@
/****************************/
/* B-tree IDs for various internal things. */
-/* Not really a "public" symbol, but that should be OK -QAK */
-/* Note - if more of these are added, any 'K' values (for internal or leaf
- * nodes) they use will need to be stored in the file somewhere. -QAK
- */
typedef enum H5B2_subid_t {
- H5B2_GRP_NAME_ID = 0, /* B-tree is for group links, ordered by name */
+ H5B2_TEST_ID = 0, /* B-tree is for testing (do not use for actual data) */
+ H5B2_GRP_NAME_ID, /* B-tree is for group links, ordered by name */
H5B2_NUM_BTREE_ID /* Number of B-tree key IDs (must be last) */
} H5B2_subid_t;
@@ -77,6 +74,8 @@ typedef struct H5B2_class_t {
herr_t (*decode)(const H5F_t *f, const uint8_t *raw, void *record); /* Decode record from disk storage form to native form */
/* Debug record values */
+ herr_t (*debug) (FILE *stream, const H5F_t *f, hid_t dxpl_id, /* Print a record for debugging */
+ int indent, int fwidth, const void *record, const void *udata);
} H5B2_class_t;
diff --git a/src/H5B2test.c b/src/H5B2test.c
new file mode 100644
index 0000000..99690fc
--- /dev/null
+++ b/src/H5B2test.c
@@ -0,0 +1,187 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/* Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu>
+ * Saturday, May 31, 2003
+ *
+ * Purpose: v2 B-tree testing functions.
+ */
+
+#define H5B2_PACKAGE /*suppress error about including H5B2pkg */
+#define H5B2_TESTING /*suppress warning about H5B2 testing funcs*/
+
+/* Private headers */
+#include "H5private.h" /* Generic Functions */
+#include "H5B2pkg.h" /* B-trees */
+
+/* Static Prototypes */
+static herr_t H5B2_test_store(const H5F_t *f, hid_t dxpl_id, const void *udata,
+ void *nrecord);
+static herr_t H5B2_test_compare(const H5F_t *f, hid_t dxpl_id, const void *rec1,
+ const void *rec2);
+static herr_t H5B2_test_encode(const H5F_t *f, uint8_t *raw,
+ const void *nrecord);
+static herr_t H5B2_test_decode(const H5F_t *f, const uint8_t *raw,
+ void *nrecord);
+static herr_t H5B2_test_debug(FILE *stream, const H5F_t *f, hid_t dxpl_id,
+ int indent, int fwidth, const void *record, const void *_udata);
+
+/* Package variables */
+const H5B2_class_t H5B2_TEST[1]={{ /* B-tree class information */
+ H5B2_TEST_ID, /* Type of B-tree */
+ sizeof(hsize_t), /* Size of native key */
+ H5B2_test_store, /* Record storage callback */
+ H5B2_test_compare, /* Record comparison callback */
+ H5B2_test_encode, /* Record encoding callback */
+ H5B2_test_decode, /* Record decoding callback */
+ H5B2_test_debug /* Record debugging callback */
+}};
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_test_store
+ *
+ * Purpose: Store native information into record for B-tree
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, February 3, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_test_store(const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *udata, void *nrecord)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_store)
+
+ *(hsize_t *)nrecord=*(const hsize_t *)udata;
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* H5B2_test_store() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_test_compare
+ *
+ * Purpose: Compare two native information records, according to some key
+ *
+ * Return: <0 if rec1 < rec2
+ * =0 if rec1 == rec2
+ * >0 if rec1 > rec2
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, February 3, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_test_compare(const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *rec1, const void *rec2)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_compare)
+
+ FUNC_LEAVE_NOAPI(*(const hssize_t *)rec1-*(const hssize_t *)rec2);
+} /* H5B2_test_compare() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_test_encode
+ *
+ * Purpose: Encode native information into raw form for storing on disk
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, February 3, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_test_encode(const H5F_t *f, uint8_t *raw, const void *nrecord)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_encode)
+
+ H5F_ENCODE_LENGTH(f, raw, *(const hsize_t *)nrecord);
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* H5B2_test_encode() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_test_decode
+ *
+ * Purpose: Decode raw disk form of record into native form
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Friday, February 4, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_test_decode(const H5F_t *f, const uint8_t *raw, void *nrecord)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_decode)
+
+ H5F_DECODE_LENGTH(f, raw, *(hsize_t *)nrecord);
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* H5B2_test_decode() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5B2_test_debug
+ *
+ * Purpose: Debug native form of record
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Friday, February 4, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_test_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, int indent, int fwidth,
+ const void *record, const void UNUSED *_udata)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_debug)
+
+ HDassert (record);
+
+ HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, "Record:",
+ *(const hsize_t *)record);
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* H5B2_test_debug() */
+
diff --git a/src/Makefile.am b/src/Makefile.am
index d3a9fba..3aaf85a 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,7 +39,8 @@ MOSTLYCLEANFILES=H5detect.o H5detect.lo H5detect H5Tinit.o H5Tinit.lo H5Tinit.c
DISTCLEAN=libhdf5.settings
# library sources
-libhdf5_la_SOURCES= H5.c H5A.c H5AC.c H5B.c H5B2.c H5B2cache.c H5B2dbg.c H5C.c \
+libhdf5_la_SOURCES= H5.c H5A.c H5AC.c H5B.c H5B2.c H5B2cache.c H5B2dbg.c \
+ H5B2test.c H5C.c \
H5D.c \
H5Dcontig.c \
H5Dcompact.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index 3299112..af2efc9 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -219,7 +219,8 @@ MOSTLYCLEANFILES = H5detect.o H5detect.lo H5detect H5Tinit.o H5Tinit.lo H5Tinit.
DISTCLEAN = libhdf5.settings
# library sources
-libhdf5_la_SOURCES = H5.c H5A.c H5AC.c H5B.c H5B2.c H5B2cache.c H5B2dbg.c H5C.c \
+libhdf5_la_SOURCES = H5.c H5A.c H5AC.c H5B.c H5B2.c H5B2cache.c H5B2dbg.c \
+ H5B2test.c H5C.c \
H5D.c \
H5Dcontig.c \
H5Dcompact.c \
@@ -290,11 +291,11 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libhdf5_la_LDFLAGS =
libhdf5_la_LIBADD =
am_libhdf5_la_OBJECTS = H5.lo H5A.lo H5AC.lo H5B.lo H5B2.lo H5B2cache.lo \
- H5B2dbg.lo H5C.lo H5D.lo H5Dcontig.lo H5Dcompact.lo H5Defl.lo \
- H5Dio.lo H5Distore.lo H5Dmpio.lo H5Dselect.lo H5Dtest.lo H5E.lo \
- H5F.lo H5Fdbg.lo H5FD.lo H5FDcore.lo H5FDfamily.lo \
- H5FDfphdf5.lo H5FDgass.lo H5FDlog.lo H5FDmpi.lo H5FDmpio.lo \
- H5FDmpiposix.lo H5FDmulti.lo H5FDsec2.lo H5FDsrb.lo \
+ H5B2dbg.lo H5B2test.lo H5C.lo H5D.lo H5Dcontig.lo H5Dcompact.lo \
+ H5Defl.lo H5Dio.lo H5Distore.lo H5Dmpio.lo H5Dselect.lo \
+ H5Dtest.lo H5E.lo H5F.lo H5Fdbg.lo H5FD.lo H5FDcore.lo \
+ H5FDfamily.lo H5FDfphdf5.lo H5FDgass.lo H5FDlog.lo H5FDmpi.lo \
+ H5FDmpio.lo H5FDmpiposix.lo H5FDmulti.lo H5FDsec2.lo H5FDsrb.lo \
H5FDstdio.lo H5FDstream.lo H5FL.lo H5FO.lo H5FP.lo \
H5FPclient.lo H5FPserver.lo H5FS.lo H5G.lo H5Gent.lo H5Gnode.lo \
H5Gstab.lo H5HG.lo H5HGdbg.lo H5HL.lo H5HLdbg.lo H5HP.lo H5I.lo \
@@ -329,8 +330,9 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/H5.Plo ./$(DEPDIR)/H5A.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/H5AC.Plo ./$(DEPDIR)/H5B.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/H5B2.Plo ./$(DEPDIR)/H5B2cache.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/H5B2dbg.Plo ./$(DEPDIR)/H5C.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/H5D.Plo ./$(DEPDIR)/H5Dcompact.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/H5B2dbg.Plo ./$(DEPDIR)/H5B2test.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/H5C.Plo ./$(DEPDIR)/H5D.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/H5Dcompact.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/H5Dcontig.Plo ./$(DEPDIR)/H5Defl.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/H5Dio.Plo ./$(DEPDIR)/H5Distore.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/H5Dmpio.Plo ./$(DEPDIR)/H5Dselect.Plo \
@@ -487,6 +489,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2cache.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2dbg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2test.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5C.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5D.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dcompact.Plo@am__quote@