diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-02-11 06:50:20 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-02-11 06:50:20 (GMT) |
commit | 9bda1fcfd86752983d8d49232e0fb520da28dce6 (patch) | |
tree | fb8e6e68ff97b5952f0662c7d519918d593db32a | |
parent | ebfc303556d65d9952304995ce853fe2c3828963 (diff) | |
download | hdf5-9bda1fcfd86752983d8d49232e0fb520da28dce6.zip hdf5-9bda1fcfd86752983d8d49232e0fb520da28dce6.tar.gz hdf5-9bda1fcfd86752983d8d49232e0fb520da28dce6.tar.bz2 |
[svn-r9986] Purpose:
New feature & code cleanup
Description:
Change some references from 'keys' to 'records', which is more correct for
this implementation.
Added feature to allow preemptive 3 node record redistributions (for leaves
only currently)
Added feature to perform preemptive 3->4 node splits (for leaves only
currently)
Platforms tested:
FreeBSD 4.11 (sleipnir) w/parallel
Solaris 2.9 (shanti) w/purify
Too minor to require h5committest
-rw-r--r-- | src/H5B2.c | 457 | ||||
-rw-r--r-- | src/H5B2cache.c | 24 | ||||
-rw-r--r-- | src/H5B2dbg.c | 6 | ||||
-rw-r--r-- | src/H5B2pkg.h | 22 | ||||
-rw-r--r-- | src/H5B2private.h | 8 | ||||
-rw-r--r-- | test/btree2.c | 184 |
6 files changed, 619 insertions, 82 deletions
@@ -67,6 +67,8 @@ static herr_t H5B2_redistribute2(H5F_t *f, hid_t dxpl_id, unsigned depth, static herr_t H5B2_split2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ptr, H5AC_info_t *parent_cache_info, H5B2_internal_t *internal, unsigned idx); +static herr_t H5B2_redistribute3(H5F_t *f, hid_t dxpl_id, unsigned depth, + H5B2_internal_t *internal, unsigned idx); /* Package variables */ @@ -109,7 +111,7 @@ H5FL_DEFINE_STATIC(H5B2_shared_t); */ herr_t H5B2_shared_init (H5F_t *f, H5B2_t *bt2, const H5B2_class_t *type, - size_t node_size, size_t rkey_size, + size_t node_size, size_t rrec_size, unsigned split_percent, unsigned merge_percent) { H5B2_shared_t *shared = NULL; /* Shared B-tree information */ @@ -126,14 +128,14 @@ H5B2_shared_init (H5F_t *f, H5B2_t *bt2, const H5B2_class_t *type, shared->split_percent = split_percent; shared->merge_percent = merge_percent; shared->node_size = node_size; - shared->rkey_size = rkey_size; + shared->rrec_size = rrec_size; /* Compute derived information */ - shared->internal_nrec = H5B2_NUM_INT_REC(f,shared->node_size,shared->rkey_size); + shared->internal_nrec = H5B2_NUM_INT_REC(f,shared->node_size,shared->rrec_size); shared->split_int_nrec = (shared->internal_nrec * shared->split_percent)/100; shared->merge_int_nrec = (shared->internal_nrec * shared->merge_percent)/100; - shared->leaf_nrec = H5B2_NUM_LEAF_REC(shared->node_size,shared->rkey_size); + shared->leaf_nrec = H5B2_NUM_LEAF_REC(shared->node_size,shared->rrec_size); shared->split_leaf_nrec = (shared->leaf_nrec * shared->split_percent)/100; shared->merge_leaf_nrec = (shared->leaf_nrec * shared->merge_percent)/100; @@ -148,11 +150,11 @@ HDmemset(shared->page,0,shared->node_size); #endif /* H5_USING_PURIFY */ /* Create factory for internal node native record storage */ - if((shared->int_fac=H5FL_fac_init(type->nkey_size*shared->internal_nrec))==NULL) + if((shared->int_fac=H5FL_fac_init(type->nrec_size*shared->internal_nrec))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't create internal node native key block factory") /* Create factory for leaf node native record storage */ - if((shared->leaf_fac=H5FL_fac_init(type->nkey_size*shared->leaf_nrec))==NULL) + if((shared->leaf_fac=H5FL_fac_init(type->nrec_size*shared->leaf_nrec))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't create leaf node native key block factory") /* Create factory for internal node node pointer storage */ @@ -165,7 +167,7 @@ HDmemset(shared->page,0,shared->node_size); /* Initialize offsets in native key block */ for(u=0; u<MAX(shared->internal_nrec,shared->leaf_nrec); u++) - shared->nat_off[u]=type->nkey_size*u; + shared->nat_off[u]=type->nrec_size*u; /* Make shared B-tree info reference counted */ if(NULL==(bt2->shared=H5RC_create(shared,H5B2_shared_free))) @@ -252,7 +254,7 @@ done: */ herr_t H5B2_create(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, - size_t node_size, size_t rkey_size, + size_t node_size, size_t rrec_size, unsigned split_percent, unsigned merge_percent, haddr_t *addr_p) { H5B2_t *bt2 = NULL; /* The new B-tree header information */ @@ -266,7 +268,7 @@ H5B2_create(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, HDassert(f); HDassert(type); HDassert(node_size>0); - HDassert(rkey_size>0); + HDassert(rrec_size>0); HDassert(merge_percent>0 && merge_percent<=100); HDassert(split_percent>0 && split_percent<=100); HDassert(merge_percent<(split_percent/2)); @@ -285,7 +287,7 @@ H5B2_create(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, bt2->root.node_nrec = bt2->root.all_nrec = 0; /* Initialize shared B-tree info */ - if(H5B2_shared_init(f, bt2, type, node_size, rkey_size, split_percent, merge_percent)<0) + if(H5B2_shared_init(f, bt2, type, node_size, rrec_size, split_percent, merge_percent)<0) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "can't create shared B-tree info") /* Allocate space for the header on disk */ @@ -409,7 +411,7 @@ H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, H5RC_t *bt2_shared) 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_NREC(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->nrec_size*(shared->split_leaf_nrec-(mid_record+1))); /* Create new internal node */ new_int_ptr.all_nrec=new_int_ptr.node_nrec=0; @@ -421,7 +423,7 @@ H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2, H5RC_t *bt2_shared) 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_NREC(old_leaf,shared,mid_record),shared->type->nkey_size); + HDmemcpy(new_int->int_native,H5B2_LEAF_NREC(old_leaf,shared,mid_record),shared->type->nrec_size); /* Update record counts in leaf nodes */ old_leaf_ptr.all_nrec = old_leaf_ptr.node_nrec = old_leaf->nrec = mid_record; @@ -547,17 +549,17 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute recor unsigned move_nrec = *right_nrec - new_right_nrec; /* Number of records to move from right node to left */ /* Copy record from parent node down into left child */ - HDmemcpy(H5B2_NAT_NREC(left_native,shared,*left_nrec),H5B2_INT_NREC(internal,shared,idx),shared->type->nkey_size); + HDmemcpy(H5B2_NAT_NREC(left_native,shared,*left_nrec),H5B2_INT_NREC(internal,shared,idx),shared->type->nrec_size); /* See if we need to move records from right node */ if(move_nrec>1) - HDmemcpy(H5B2_NAT_NREC(left_native,shared,(*left_nrec+1)),H5B2_NAT_NREC(right_native,shared,0),shared->type->nkey_size*(move_nrec-1)); + HDmemcpy(H5B2_NAT_NREC(left_native,shared,(*left_nrec+1)),H5B2_NAT_NREC(right_native,shared,0),shared->type->nrec_size*(move_nrec-1)); /* Move record from right node into parent node */ - HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(right_native,shared,move_nrec),shared->type->nkey_size); + HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(right_native,shared,move_nrec),shared->type->nrec_size); /* Slide records in right node down */ - HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,move_nrec),shared->type->nkey_size*new_right_nrec); + HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,move_nrec),shared->type->nrec_size*new_right_nrec); /* Update number of records in child nodes */ *left_nrec += move_nrec; @@ -572,24 +574,24 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute recor /* Slide records in right node up */ HDmemmove(H5B2_NAT_NREC(right_native,shared,move_nrec), H5B2_NAT_NREC(right_native,shared,0), - shared->type->nkey_size*(*right_nrec)); + shared->type->nrec_size*(*right_nrec)); /* Copy record from parent node down into right child */ - HDmemcpy(H5B2_NAT_NREC(right_native,shared,(move_nrec-1)),H5B2_INT_NREC(internal,shared,idx),shared->type->nkey_size); + HDmemcpy(H5B2_NAT_NREC(right_native,shared,(move_nrec-1)),H5B2_INT_NREC(internal,shared,idx),shared->type->nrec_size); /* See if we need to move records from left node */ if(move_nrec>1) - HDmemcpy(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(left_native,shared,((*left_nrec-move_nrec)+1)),shared->type->nkey_size*(move_nrec-1)); + HDmemcpy(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(left_native,shared,((*left_nrec-move_nrec)+1)),shared->type->nrec_size*(move_nrec-1)); /* Move record from left node into parent node */ - HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(left_native,shared,(*left_nrec-move_nrec)),shared->type->nkey_size); + HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(left_native,shared,(*left_nrec-move_nrec)),shared->type->nrec_size); /* Update number of records in child nodes */ *left_nrec = new_left_nrec; *right_nrec += move_nrec; } /* end else */ - /* Update # of records in parent node */ + /* Update # of records in child nodes */ /* Hmm, this value for 'all_rec' wont' be right for internal nodes... */ internal->node_ptrs[idx].all_nrec = internal->node_ptrs[idx].node_nrec = *left_nrec; internal->node_ptrs[idx+1].all_nrec = internal->node_ptrs[idx+1].node_nrec = *right_nrec; @@ -626,13 +628,13 @@ H5B2_split2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ { const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ - haddr_t middle_addr; /* Addresses of middle child node */ + haddr_t middle_addr; /* Address of middle child node */ void *left_child, *right_child; /* Pointers to left & right child nodes */ - void *middle_child; /* Pointers to middle child node */ + void *middle_child; /* Pointer to middle child node */ unsigned *left_nrec, *right_nrec; /* Pointers to left & right child # of records */ - unsigned *middle_nrec; /* Pointers to middle child # of records */ + unsigned *middle_nrec; /* Pointer to middle child # of records */ uint8_t *left_native, *right_native; /* Pointers to left & right children's native records */ - uint8_t *middle_native; /* Pointers to middle child's native records */ + uint8_t *middle_native; /* Pointer to middle child's native records */ H5B2_shared_t *shared; /* B-tree's shared info */ herr_t ret_value=SUCCEED; /* Return value */ @@ -645,8 +647,8 @@ H5B2_split2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ shared=H5RC_GET_OBJ(internal->shared); HDassert(shared); - /* Slide records in parent node down one space, to make room for promoted record */ - HDmemmove(H5B2_INT_NREC(internal,shared,idx+2),H5B2_INT_NREC(internal,shared,idx+1),shared->type->nkey_size*(internal->nrec-(idx+1))); + /* Slide records in parent node up one space, to make room for promoted record */ + HDmemmove(H5B2_INT_NREC(internal,shared,idx+2),H5B2_INT_NREC(internal,shared,idx+1),shared->type->nrec_size*(internal->nrec-(idx+1))); HDmemmove(&(internal->node_ptrs[idx+2]),&(internal->node_ptrs[idx+1]),sizeof(H5B2_node_ptr_t)*(internal->nrec-idx)); /* Check for the kind of B-tree node to split */ @@ -667,7 +669,7 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split nodes") /* Lock left & right B-tree child nodes */ if (NULL == (left_leaf = H5AC_protect(f, dxpl_id, child_class, left_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE))) HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") - if (NULL == (right_leaf = H5AC_protect(f, dxpl_id, child_class, right_addr, &(internal->node_ptrs[idx+1].node_nrec), internal->shared, H5AC_WRITE))) + if (NULL == (right_leaf = H5AC_protect(f, dxpl_id, child_class, right_addr, &(internal->node_ptrs[idx+2].node_nrec), internal->shared, H5AC_WRITE))) HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") /* Create new empty "middle" leaf node */ @@ -684,19 +686,19 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split nodes") /* More setup for accessing child node information */ left_child = left_leaf; - right_child = right_leaf; middle_child = middle_leaf; + right_child = right_leaf; left_nrec = &(left_leaf->nrec); - right_nrec = &(right_leaf->nrec); middle_nrec = &(middle_leaf->nrec); + right_nrec = &(right_leaf->nrec); left_native = left_leaf->leaf_native; - right_native = right_leaf->leaf_native; middle_native = middle_leaf->leaf_native; + right_native = right_leaf->leaf_native; /* Mark child nodes as dirty now */ left_leaf->cache_info.is_dirty = TRUE; - right_leaf->cache_info.is_dirty = TRUE; middle_leaf->cache_info.is_dirty = TRUE; + right_leaf->cache_info.is_dirty = TRUE; } /* end else */ /* Sanity check */ @@ -717,31 +719,30 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split nodes") /* Copy record(s) from left node to proper location */ if(new_left_nrec<(*left_nrec-1)) { curr_middle_idx=*left_nrec-(new_left_nrec+1); - HDmemcpy(H5B2_NAT_NREC(middle_native,shared,0),H5B2_NAT_NREC(left_native,shared,(new_left_nrec+1)),shared->type->nkey_size*curr_middle_idx); + HDmemcpy(H5B2_NAT_NREC(middle_native,shared,0),H5B2_NAT_NREC(left_native,shared,(new_left_nrec+1)),shared->type->nrec_size*curr_middle_idx); } /* end if */ /* Copy record from parent node to proper location */ - HDmemcpy(H5B2_NAT_NREC(middle_native,shared,curr_middle_idx),H5B2_INT_NREC(internal,shared,idx),shared->type->nkey_size); + HDmemcpy(H5B2_NAT_NREC(middle_native,shared,curr_middle_idx),H5B2_INT_NREC(internal,shared,idx),shared->type->nrec_size); curr_middle_idx++; /* Copy record(s) from right node to proper location */ if(new_right_nrec<(*right_nrec-1)) - HDmemcpy(H5B2_NAT_NREC(middle_native,shared,curr_middle_idx),H5B2_NAT_NREC(right_native,shared,0),shared->type->nkey_size*(*right_nrec-(new_right_nrec+1))); - - /* Update # of records in middle node */ - *middle_nrec=new_middle_nrec; + HDmemcpy(H5B2_NAT_NREC(middle_native,shared,curr_middle_idx),H5B2_NAT_NREC(right_native,shared,0),shared->type->nrec_size*(*right_nrec-(new_right_nrec+1))); } /* end block */ + /* Update # of records in middle node */ + *middle_nrec=new_middle_nrec; /* Promote records to parent node from left & right nodes */ - HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(left_native,shared,new_left_nrec),shared->type->nkey_size); - HDmemcpy(H5B2_INT_NREC(internal,shared,idx+1),H5B2_NAT_NREC(right_native,shared,(*right_nrec-(new_right_nrec+1))),shared->type->nkey_size); + HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(left_native,shared,new_left_nrec),shared->type->nrec_size); + HDmemcpy(H5B2_INT_NREC(internal,shared,idx+1),H5B2_NAT_NREC(right_native,shared,(*right_nrec-(new_right_nrec+1))),shared->type->nrec_size); /* Update # of records in left node */ *left_nrec = new_left_nrec; /* Slide records in right node to proper position */ - HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,(*right_nrec-new_right_nrec)),shared->type->nkey_size*new_right_nrec); + HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,(*right_nrec-new_right_nrec)),shared->type->nrec_size*new_right_nrec); /* Update # of records in right node */ *right_nrec = new_right_nrec; @@ -766,14 +767,371 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split nodes") /* Unlock child nodes */ if (H5AC_unprotect(f, dxpl_id, child_class, left_addr, left_child, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + if (H5AC_unprotect(f, dxpl_id, child_class, middle_addr, middle_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") if (H5AC_unprotect(f, dxpl_id, child_class, right_addr, right_child, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5B2_split2 */ + + +/*------------------------------------------------------------------------- + * Function: H5B2_redistribute3 + * + * Purpose: Redistribute records between three nodes + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Feb 9 2005 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5B2_redistribute3(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_internal_t *internal, unsigned idx) +{ + const H5AC_class_t *child_class; /* Pointer to child node's class info */ + haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ + haddr_t middle_addr; /* Address of middle child node */ + void *left_child, *right_child; /* Pointers to child nodes */ + void *middle_child; /* Pointers to middle child node */ + unsigned *left_nrec, *right_nrec; /* Pointers to child # of records */ + unsigned *middle_nrec; /* Pointers to middle child # of records */ + uint8_t *left_native, *right_native; /* Pointers to childs' native records */ + uint8_t *middle_native; /* Pointers to middle child's native records */ + H5B2_shared_t *shared; /* B-tree's shared info */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5B2_redistribute3) + + HDassert(f); + HDassert(internal); + + /* Get the pointer to the shared B-tree info */ + shared=H5RC_GET_OBJ(internal->shared); + HDassert(shared); + + /* Check for the kind of B-tree node to redistribute */ + if(depth>1) { +HDfprintf(stderr,"%s: redistributing internal node! (need to handle node_ptrs)\n",FUNC); +HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute records") + } /* end if */ + else { + H5B2_leaf_t *left_leaf; /* Pointer to left leaf node */ + H5B2_leaf_t *middle_leaf; /* Pointer to middle leaf node */ + H5B2_leaf_t *right_leaf; /* Pointer to right leaf node */ + + /* Setup information for unlocking child nodes */ + child_class = H5AC_BT2_LEAF; + left_addr = internal->node_ptrs[idx-1].addr; + middle_addr = internal->node_ptrs[idx].addr; + right_addr = internal->node_ptrs[idx+1].addr; + + /* Lock B-tree child nodes */ + if (NULL == (left_leaf = H5AC_protect(f, dxpl_id, child_class, left_addr, &(internal->node_ptrs[idx-1].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + if (NULL == (middle_leaf = H5AC_protect(f, dxpl_id, child_class, middle_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + if (NULL == (right_leaf = H5AC_protect(f, dxpl_id, child_class, right_addr, &(internal->node_ptrs[idx+1].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + + /* More setup for child nodes */ + left_child = left_leaf; + middle_child = middle_leaf; + right_child = right_leaf; + left_nrec = &(left_leaf->nrec); + middle_nrec = &(middle_leaf->nrec); + right_nrec = &(right_leaf->nrec); + left_native = left_leaf->leaf_native; + middle_native = middle_leaf->leaf_native; + right_native = right_leaf->leaf_native; + + /* Mark child nodes as dirty now */ + left_leaf->cache_info.is_dirty = TRUE; + middle_leaf->cache_info.is_dirty = TRUE; + right_leaf->cache_info.is_dirty = TRUE; + } /* end else */ + + /* Redistribute records */ + { + /* Compute new # of records in each node */ + unsigned total_nrec = *left_nrec + *middle_nrec + *right_nrec + 2; + unsigned new_middle_nrec = (total_nrec-2)/3; + unsigned new_left_nrec = ((total_nrec-2)-new_middle_nrec)/2; + unsigned new_right_nrec = (total_nrec-2)-(new_left_nrec+new_middle_nrec); + + /* Move records into left node */ + if(new_left_nrec>*left_nrec) { + unsigned moved_middle_nrec=0; /* Number of records moved into left node */ + + /* Move left parent record down to left node */ + HDmemcpy(H5B2_NAT_NREC(left_native,shared,*left_nrec),H5B2_INT_NREC(internal,shared,idx-1),shared->type->nrec_size); + + /* Move records from middle node into left node */ + if((new_left_nrec-1)>*left_nrec) { + moved_middle_nrec = new_left_nrec-(*left_nrec+1); + HDmemcpy(H5B2_NAT_NREC(left_native,shared,*left_nrec+1),H5B2_NAT_NREC(middle_native,shared,0),shared->type->nrec_size*moved_middle_nrec); + } /* end if */ + + /* Move record from middle node up to parent node */ + HDmemcpy(H5B2_INT_NREC(internal,shared,idx-1),H5B2_NAT_NREC(middle_native,shared,moved_middle_nrec),shared->type->nrec_size); + moved_middle_nrec++; + + /* Slide records in middle node down */ + HDmemmove(H5B2_NAT_NREC(middle_native,shared,0),H5B2_NAT_NREC(middle_native,shared,moved_middle_nrec),shared->type->nrec_size*(*middle_nrec-moved_middle_nrec)); + } /* end if */ + + /* Move records into right node */ + if(new_right_nrec>*right_nrec) { + + /* Slide records in right node up */ + HDmemmove(H5B2_NAT_NREC(right_native,shared,(new_right_nrec-*right_nrec)),H5B2_NAT_NREC(right_native,shared,0),shared->type->nrec_size*(*right_nrec)); + + /* Move right parent record down to right node */ + HDmemcpy(H5B2_NAT_NREC(right_native,shared,(new_right_nrec-(*right_nrec+1))),H5B2_INT_NREC(internal,shared,idx),shared->type->nrec_size); + + /* Move records from middle node into right node */ + if((new_right_nrec-1)>*right_nrec) + HDmemcpy(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(middle_native,shared,new_middle_nrec+1),shared->type->nrec_size*(new_right_nrec-(*right_nrec+1))); + + /* Move record from middle node up to parent node */ + HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(middle_native,shared,new_middle_nrec),shared->type->nrec_size); + } /* end if */ + + /* Update # of records in nodes */ + *left_nrec = new_left_nrec; + *middle_nrec = new_middle_nrec; + *right_nrec = new_right_nrec; + } /* end block */ + + /* Update # of records in child nodes */ +/* Hmm, this value for 'all_rec' wont' be right for internal nodes... */ + internal->node_ptrs[idx-1].all_nrec = internal->node_ptrs[idx-1].node_nrec = *left_nrec; + internal->node_ptrs[idx].all_nrec = internal->node_ptrs[idx].node_nrec = *middle_nrec; + internal->node_ptrs[idx+1].all_nrec = internal->node_ptrs[idx+1].node_nrec = *right_nrec; + + /* Mark parent as dirty */ + internal->cache_info.is_dirty = TRUE; + + /* Unlock child nodes */ + if (H5AC_unprotect(f, dxpl_id, child_class, left_addr, left_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") if (H5AC_unprotect(f, dxpl_id, child_class, middle_addr, middle_child, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + if (H5AC_unprotect(f, dxpl_id, child_class, right_addr, right_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") done: FUNC_LEAVE_NOAPI(ret_value); -} /* end H5B2_split2 */ +} /* end H5B2_redistribute3 */ + + +/*------------------------------------------------------------------------- + * Function: H5B2_split3 + * + * Purpose: Perform a 3->4 node split + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Feb 10 2005 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5B2_split3(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ptr, + H5AC_info_t *parent_cache_info, H5B2_internal_t *internal, unsigned idx) +{ + const H5AC_class_t *child_class; /* Pointer to child node's class info */ + haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ + haddr_t middle_addr; /* Address of middle child node */ + haddr_t new_addr; /* Address of new child node */ + void *left_child, *right_child; /* Pointers to left & right child nodes */ + void *middle_child; /* Pointer to middle child node */ + void *new_child; /* Pointer to new child node */ + unsigned *left_nrec, *right_nrec; /* Pointers to left & right child # of records */ + unsigned *middle_nrec; /* Pointer to middle child # of records */ + unsigned *new_nrec; /* Pointer to new child # of records */ + uint8_t *left_native, *right_native; /* Pointers to left & right children's native records */ + uint8_t *middle_native; /* Pointer to middle child's native records */ + uint8_t *new_native; /* Pointer to new child's native records */ + H5B2_shared_t *shared; /* B-tree's shared info */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5B2_split3) + + HDassert(f); + HDassert(internal); + + /* Get the pointer to the shared B-tree info */ + shared=H5RC_GET_OBJ(internal->shared); + HDassert(shared); + + /* Slide records in parent node up one space, to make room for promoted record */ + HDmemmove(H5B2_INT_NREC(internal,shared,idx+2),H5B2_INT_NREC(internal,shared,idx+1),shared->type->nrec_size*(internal->nrec-(idx+1))); + HDmemmove(&(internal->node_ptrs[idx+2]),&(internal->node_ptrs[idx+1]),sizeof(H5B2_node_ptr_t)*(internal->nrec-idx)); + + /* Check for the kind of B-tree node to split */ + if(depth>1) { +HDfprintf(stderr,"%s: splitting internal node! (need to handle node_ptrs)\n",FUNC); +HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split nodes") + } /* end if */ + else { + H5B2_leaf_t *left_leaf; /* Pointer to left leaf node */ + H5B2_leaf_t *right_leaf; /* Pointer to right leaf node */ + H5B2_leaf_t *middle_leaf; /* Pointer to middle leaf node */ + H5B2_leaf_t *new_leaf; /* Pointer to new leaf node */ + + /* Setup information for unlocking child nodes */ + child_class = H5AC_BT2_LEAF; + left_addr = internal->node_ptrs[idx-1].addr; + middle_addr = internal->node_ptrs[idx].addr; + right_addr = internal->node_ptrs[idx+2].addr; + + /* Lock left & right B-tree child nodes */ + if (NULL == (left_leaf = H5AC_protect(f, dxpl_id, child_class, left_addr, &(internal->node_ptrs[idx-1].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + if (NULL == (middle_leaf = H5AC_protect(f, dxpl_id, child_class, middle_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + if (NULL == (right_leaf = H5AC_protect(f, dxpl_id, child_class, right_addr, &(internal->node_ptrs[idx+2].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + + /* Create new empty leaf node */ + internal->node_ptrs[idx+1].all_nrec=internal->node_ptrs[idx+1].node_nrec=0; + if(H5B2_create_leaf(f, dxpl_id, internal->shared, &(internal->node_ptrs[idx+1]))<0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to create new leaf node") + + /* Setup information for unlocking middle child node */ + new_addr = internal->node_ptrs[idx+1].addr; + + /* Lock "new" leaf node */ + if (NULL == (new_leaf = H5AC_protect(f, dxpl_id, child_class, new_addr, &(internal->node_ptrs[idx+1].node_nrec), internal->shared, H5AC_WRITE))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree leaf node") + + /* More setup for accessing child node information */ + left_child = left_leaf; + middle_child = middle_leaf; + new_child = new_leaf; + right_child = right_leaf; + left_nrec = &(left_leaf->nrec); + middle_nrec = &(middle_leaf->nrec); + new_nrec = &(new_leaf->nrec); + right_nrec = &(right_leaf->nrec); + left_native = left_leaf->leaf_native; + middle_native = middle_leaf->leaf_native; + new_native = new_leaf->leaf_native; + right_native = right_leaf->leaf_native; + + /* Mark child nodes as dirty now */ + left_leaf->cache_info.is_dirty = TRUE; + middle_leaf->cache_info.is_dirty = TRUE; + new_leaf->cache_info.is_dirty = TRUE; + right_leaf->cache_info.is_dirty = TRUE; + } /* end else */ + + /* Sanity check */ + HDassert(*left_nrec==*right_nrec); + HDassert(*left_nrec==*middle_nrec); + + /* Redistribute records */ + { + /* Compute new # of records in each node */ + unsigned total_nrec = *left_nrec + *middle_nrec + *right_nrec + 2; + unsigned new_new_nrec = (total_nrec-3)/4; + unsigned new_middle_nrec = ((total_nrec-3)-new_new_nrec)/3; + unsigned new_left_nrec = ((total_nrec-3)-(new_middle_nrec+new_new_nrec))/2; + unsigned new_right_nrec = (total_nrec-3)-(new_left_nrec+new_middle_nrec+new_new_nrec); + + /* Partially fill new node from right node */ + { + unsigned right_nrec_move = *right_nrec-new_right_nrec; + + /* Move right record down from parent into new node */ + HDmemcpy(H5B2_NAT_NREC(new_native,shared,(new_new_nrec-right_nrec_move)),H5B2_INT_NREC(internal,shared,idx),shared->type->nrec_size); + + /* Move records from right node to new node */ + HDmemcpy(H5B2_NAT_NREC(new_native,shared,((new_new_nrec-right_nrec_move)+1)),H5B2_NAT_NREC(right_native,shared,0),shared->type->nrec_size*(right_nrec_move-1)); + + /* Move record from right node up to parent node */ + HDmemcpy(H5B2_INT_NREC(internal,shared,idx+1),H5B2_NAT_NREC(right_native,shared,(right_nrec_move-1)),shared->type->nrec_size); + + /* Slide records in right node down */ + HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,right_nrec_move),shared->type->nrec_size*new_right_nrec); + } /* end block */ + + /* Finish filling new node from middle node */ + { + unsigned new_nrec_move = new_new_nrec-(*right_nrec-new_right_nrec); + + /* Move records from middle node to new node */ + HDmemcpy(H5B2_NAT_NREC(new_native,shared,0),H5B2_NAT_NREC(middle_native,shared,(*middle_nrec-new_nrec_move)),shared->type->nrec_size*new_nrec_move); + + /* Move record from middle node up to parent node */ + HDmemcpy(H5B2_INT_NREC(internal,shared,idx),H5B2_NAT_NREC(middle_native,shared,((*middle_nrec-new_nrec_move)-1)),shared->type->nrec_size); + + /* Slide records in middle node up */ + HDmemmove(H5B2_NAT_NREC(middle_native,shared,(new_middle_nrec-((*middle_nrec-new_nrec_move)-1))),H5B2_NAT_NREC(middle_native,shared,0),shared->type->nrec_size*(*middle_nrec-(new_nrec_move+1))); + } /* end block */ + + /* Fill middle node from left node */ + { + unsigned left_nrec_move = *left_nrec - new_left_nrec; + + /* Move record from parent node down to middle node */ + HDmemcpy(H5B2_NAT_NREC(middle_native,shared,(left_nrec_move-1)),H5B2_INT_NREC(internal,shared,idx-1),shared->type->nrec_size); + + /* Move records from left node to middle node */ + HDmemcpy(H5B2_NAT_NREC(middle_native,shared,0),H5B2_NAT_NREC(left_native,shared,(new_left_nrec+1)),shared->type->nrec_size*(left_nrec_move-1)); + } + + /* Move record from left node to parent node */ + HDmemcpy(H5B2_INT_NREC(internal,shared,idx-1),H5B2_NAT_NREC(left_native,shared,new_left_nrec),shared->type->nrec_size); + + /* Update # of records in nodes */ + *left_nrec = new_left_nrec; + *middle_nrec = new_middle_nrec; + *new_nrec = new_new_nrec; + *right_nrec = new_right_nrec; + } /* end block */ + + /* Update # of records in parent node */ +/* Hmm, this value for 'all_rec' wont' be right for internal nodes... */ + internal->node_ptrs[idx-1].all_nrec = internal->node_ptrs[idx-1].node_nrec = *left_nrec; + internal->node_ptrs[idx].all_nrec = internal->node_ptrs[idx].node_nrec = *middle_nrec; + internal->node_ptrs[idx+1].all_nrec = internal->node_ptrs[idx+1].node_nrec = *new_nrec; + internal->node_ptrs[idx+2].all_nrec = internal->node_ptrs[idx+2].node_nrec = *right_nrec; + internal->nrec++; + + /* Mark parent as dirty */ + internal->cache_info.is_dirty = TRUE; + + /* Update grandparent info */ + curr_node_ptr->node_nrec++; + + /* Mark grandparent as dirty */ + parent_cache_info->is_dirty = TRUE; + + /* Unlock child nodes */ + if (H5AC_unprotect(f, dxpl_id, child_class, left_addr, left_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + if (H5AC_unprotect(f, dxpl_id, child_class, middle_addr, middle_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + if (H5AC_unprotect(f, dxpl_id, child_class, new_addr, new_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + if (H5AC_unprotect(f, dxpl_id, child_class, right_addr, right_child, H5AC__NO_FLAGS_SET) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree child node") + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5B2_split3 */ /*------------------------------------------------------------------------- @@ -910,19 +1268,18 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr, } /* end else */ } /* end if */ else { -HDfprintf(stderr,"%s: middle child, idx=%d\n",FUNC,idx); if((depth==1 && ((internal->node_ptrs[idx+1].node_nrec<shared->split_leaf_nrec) || (internal->node_ptrs[idx-1].node_nrec<shared->split_leaf_nrec))) || (depth>1 && ((internal->node_ptrs[idx+1].node_nrec<shared->split_int_nrec) || (internal->node_ptrs[idx-1].node_nrec<shared->split_int_nrec)))) { -HDfprintf(stderr,"%s: Can redistribute records\n",FUNC); -HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute child node") + if(H5B2_redistribute3(f,dxpl_id,depth,internal,(unsigned)idx)<0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute child node records") } /* end if */ else { -HDfprintf(stderr,"%s: must split node\n",FUNC); -HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split child node") + if(H5B2_split3(f,dxpl_id,depth,curr_node_ptr,parent_cache_info,internal,(unsigned)idx)<0) + HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split child node") } /* end else */ } /* end else */ @@ -1019,7 +1376,7 @@ 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_NREC(leaf,shared,idx+1),H5B2_LEAF_NREC(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->nrec_size*(leaf->nrec-idx)); } /* end else */ /* Make callback to store record in native form */ @@ -1098,7 +1455,7 @@ H5B2_create_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, H5B2_node_ptr_t *n if((leaf->leaf_native=H5FL_FAC_MALLOC(shared->leaf_fac))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree leaf native keys") #ifdef H5_USING_PURIFY -HDmemset(leaf->leaf_native,0,shared->type->nkey_size*shared->leaf_nrec); +HDmemset(leaf->leaf_native,0,shared->type->nrec_size*shared->leaf_nrec); #endif /* H5_USING_PURIFY */ /* Set number of records */ @@ -1170,7 +1527,7 @@ H5B2_create_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, H5B2_node_ptr_ if((internal->int_native=H5FL_FAC_MALLOC(shared->int_fac))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree internal native keys") #ifdef H5_USING_PURIFY -HDmemset(internal->int_native,0,shared->type->nkey_size*shared->internal_nrec); +HDmemset(internal->int_native,0,shared->type->nrec_size*shared->internal_nrec); #endif /* H5_USING_PURIFY */ /* Allocate space for the node pointers in memory */ diff --git a/src/H5B2cache.c b/src/H5B2cache.c index aaa72f9..ddc402b 100644 --- a/src/H5B2cache.c +++ b/src/H5B2cache.c @@ -114,7 +114,7 @@ static H5B2_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; - size_t node_size, rkey_size; /* Size info for B-tree */ + size_t node_size, rrec_size; /* Size info for B-tree */ unsigned split_percent, merge_percent; /* Split & merge info for B-tree */ H5B2_t *bt2 = NULL; size_t size; @@ -163,7 +163,7 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo UINT32DECODE(p, node_size); /* raw key size (in bytes) */ - UINT16DECODE(p, rkey_size); + UINT16DECODE(p, rrec_size); /* depth of tree */ UINT16DECODE(p, bt2->depth); @@ -178,7 +178,7 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo H5F_DECODE_LENGTH(f, p, bt2->root.all_nrec); /* Initialize shared B-tree info */ - if(H5B2_shared_init(f, bt2, type, node_size, rkey_size, split_percent, merge_percent)<0) + if(H5B2_shared_init(f, bt2, type, node_size, rrec_size, split_percent, merge_percent)<0) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "can't create shared B-tree info") /* Set return value */ @@ -251,7 +251,7 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B UINT32ENCODE(p, shared->node_size); /* raw key size (in bytes) */ - UINT16ENCODE(p, shared->rkey_size); + UINT16ENCODE(p, shared->rrec_size); /* depth of tree */ UINT16ENCODE(p, bt2->depth); @@ -466,8 +466,8 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record"); /* Move to next record */ - p += shared->rkey_size; - native += shared->type->nkey_size; + p += shared->rrec_size; + native += shared->type->nrec_size; } /* end for */ /* Set return value */ @@ -535,8 +535,8 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5 HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record"); /* Move to next record */ - p += shared->rkey_size; - native += shared->type->nkey_size; + p += shared->rrec_size; + native += shared->type->nrec_size; } /* end for */ /* Write the B-tree leaf node */ @@ -759,8 +759,8 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nre HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record"); /* Move to next record */ - p += shared->rkey_size; - native += shared->type->nkey_size; + p += shared->rrec_size; + native += shared->type->nrec_size; } /* end for */ /* Deserialize node pointers for internal node */ @@ -841,8 +841,8 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record"); /* Move to next record */ - p += shared->rkey_size; - native += shared->type->nkey_size; + p += shared->rrec_size; + native += shared->type->nrec_size; } /* end for */ /* Serialize node pointers for internal node */ diff --git a/src/H5B2dbg.c b/src/H5B2dbg.c index f0e3060..0801a6f 100644 --- a/src/H5B2dbg.c +++ b/src/H5B2dbg.c @@ -87,7 +87,7 @@ H5B2_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, shared->node_size); HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Size of raw (disk) record:", - shared->rkey_size); + shared->rrec_size); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Dirty flag:", bt2->cache_info.is_dirty ? "True" : "False"); @@ -205,7 +205,7 @@ H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, shared->node_size); HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Size of raw (disk) record:", - shared->rkey_size); + shared->rrec_size); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Dirty flag:", internal->cache_info.is_dirty ? "True" : "False"); @@ -317,7 +317,7 @@ H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, shared->node_size); HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Size of raw (disk) record:", - shared->rkey_size); + shared->rrec_size); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Dirty flag:", leaf->cache_info.is_dirty ? "True" : "False"); diff --git a/src/H5B2pkg.h b/src/H5B2pkg.h index f330924..e410f7b 100644 --- a/src/H5B2pkg.h +++ b/src/H5B2pkg.h @@ -65,13 +65,13 @@ 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 native record buffer */ +/* Macro to retrieve pointer to i'th native record for native record buffer */ #define H5B2_NAT_NREC(b,shared,idx) (b+(shared)->nat_off[(idx)]) -/* Macro to retrieve pointer to i'th native key for internal node */ +/* Macro to retrieve pointer to i'th native record for internal node */ #define H5B2_INT_NREC(i,shared,idx) ((i)->int_native+(shared)->nat_off[(idx)]) -/* Macro to retrieve pointer to i'th native key for leaf node */ +/* Macro to retrieve pointer to i'th native record for leaf node */ #define H5B2_LEAF_NREC(l,shared,idx) ((l)->leaf_native+(shared)->nat_off[(idx)]) @@ -93,16 +93,16 @@ typedef struct H5B2_shared_t { /* Shared internal data structures */ const H5B2_class_t *type; /* Type of tree */ uint8_t *page; /* Disk page */ - H5FL_fac_head_t *int_fac; /* Factory for internal node native key blocks */ - H5FL_fac_head_t *leaf_fac; /* Factory for leaf node native key blocks */ + H5FL_fac_head_t *int_fac; /* Factory for internal node native record blocks */ + H5FL_fac_head_t *leaf_fac; /* Factory for leaf node native record blocks */ H5FL_fac_head_t *node_ptr_fac; /* Factory for internal node node pointer blocks */ - size_t *nat_off; /* Array of offsets of native keys */ + size_t *nat_off; /* Array of offsets of native records */ /* Information set by user */ unsigned split_percent; /* Percent full at which to split the node, when inserting */ unsigned merge_percent; /* Percent full at which to merge the node, when deleting */ - size_t node_size; /* Size of all nodes, in bytes */ - size_t rkey_size; /* Size of "raw" (on disk) key, in bytes */ + size_t node_size; /* Size of all nodes, in bytes */ + size_t rrec_size; /* Size of "raw" (on disk) record, in bytes */ /* Derived information from user's information */ size_t internal_nrec; /* Number of records which fit into an internal node */ @@ -131,7 +131,7 @@ typedef struct H5B2_leaf_t { /* Internal B-tree information */ H5RC_t *shared; /* Ref-counted shared info */ - uint8_t *leaf_native; /* Pointer to native keys */ + uint8_t *leaf_native; /* Pointer to native records */ unsigned nrec; /* Number of records in node */ } H5B2_leaf_t; @@ -142,7 +142,7 @@ typedef struct H5B2_internal_t { /* Internal B-tree information */ H5RC_t *shared; /* Ref-counted shared info */ - uint8_t *int_native; /* Pointer to native keys */ + uint8_t *int_native; /* Pointer to native records */ H5B2_node_ptr_t *node_ptrs; /* Pointer to node pointers */ unsigned nrec; /* Number of records in node */ } H5B2_internal_t; @@ -181,7 +181,7 @@ H5_DLLVAR const H5B2_class_t H5B2_TEST[1]; /******************************/ H5_DLL herr_t H5B2_shared_free (void *_shared); H5_DLL herr_t H5B2_shared_init (H5F_t *f, H5B2_t *bt2, const H5B2_class_t *type, - size_t node_size, size_t rkey_size, unsigned split_percent, unsigned merge_percent); + size_t node_size, size_t rrec_size, unsigned split_percent, unsigned merge_percent); H5_DLL herr_t H5B2_cache_hdr_dest(H5F_t *f, H5B2_t *b); 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); diff --git a/src/H5B2private.h b/src/H5B2private.h index 2635cae..51b5c2d 100644 --- a/src/H5B2private.h +++ b/src/H5B2private.h @@ -52,7 +52,7 @@ typedef enum H5B2_subid_t { 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_NUM_BTREE_ID /* Number of B-tree IDs (must be last) */ } H5B2_subid_t; /* @@ -61,10 +61,10 @@ typedef enum H5B2_subid_t { */ typedef struct H5B2_class_t { H5B2_subid_t id; /*id as found in file*/ - size_t nkey_size; /*size of native (memory) key*/ + size_t nrec_size; /*size of native (memory) record*/ /* Store & retrieve records */ - herr_t (*store)(const H5F_t *f, hid_t dxpl_id, const void *udata, void *nrecord); /* Store record in native key table */ + herr_t (*store)(const H5F_t *f, hid_t dxpl_id, const void *udata, void *nrecord); /* Store record in native record table */ /* Compare records, according to a key */ herr_t (*compare)(const H5F_t *f, hid_t dxpl_id, const void *rec1, const void *rec2); /* Compare two native records */ @@ -83,7 +83,7 @@ typedef struct H5B2_class_t { /* Library-private Function Prototypes */ /***************************************/ H5_DLL herr_t H5B2_create(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, - size_t node_size, size_t rkey_size, + size_t node_size, size_t rrec_size, unsigned split_percent, unsigned merge_percent, haddr_t *addr_p); H5_DLL herr_t H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, diff --git a/test/btree2.c b/test/btree2.c index dbaa232..6ab6ed6 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -469,7 +469,185 @@ error: H5Fclose(file); } H5E_END_TRY; return 1; -} /* test_insert_level1_2leaf_redistrib() */ +} /* test_insert_level1_2leaf_split() */ + + +/*------------------------------------------------------------------------- + * Function: test_insert_level1_3leaf_redistrib + * + * Purpose: Basic tests for the B-tree v2 code. This test inserts enough + * records to split the root node and force the tree to depth 1. + * It continues to add a more records to the each of the + * left and right leaf nodes after the split to force a 2 node + * split, adding another node to the B-tree, then continues to + * add records until a 3 node redistribution occurs + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Thursday, February 10, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_insert_level1_3leaf_redistrib(hid_t fapl) +{ + hid_t file=-1; + char filename[1024]; + H5F_t *f=NULL; + hsize_t record; /* Record to insert into tree */ + haddr_t bt2_addr; /* Address of B-tree created */ + unsigned u; /* Local index variable */ + + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + + /* Create the file to work on */ + if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR; + + /* Get a pointer to the internal file object */ + if (NULL==(f=H5I_object(file))) { + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + + /* + * Create v2 B-tree + */ + if (H5B2_create(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, 512, 8, 100, 40, &bt2_addr/*out*/)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + + /* + * Test inserting many records into v2 B-tree + */ + TESTING("B-tree many - redistribute 3 leaves in level 1 B-tree"); + + /* Insert enough records to force root to split into 2 leaves */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC; u++) { + record=u+INSERT_SPLIT_ROOT_NREC; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } + + /* Force split from left node into right node */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC; u++) { + record=u; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_insert_level1_3leaf_redistrib() */ + + +/*------------------------------------------------------------------------- + * Function: test_insert_level1_3leaf_split + * + * Purpose: Basic tests for the B-tree v2 code. This test inserts enough + * records to split the root node and force the tree to depth 1. + * It continues to add a more records to the each of the + * left and right leaf nodes after the split to force a 2 node + * split, adding another node to the B-tree, then continues to + * add records until a 3 node split occurs + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Thursday, February 10, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_insert_level1_3leaf_split(hid_t fapl) +{ + hid_t file=-1; + char filename[1024]; + H5F_t *f=NULL; + hsize_t record; /* Record to insert into tree */ + haddr_t bt2_addr; /* Address of B-tree created */ + unsigned u; /* Local index variable */ + + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + + /* Create the file to work on */ + if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR; + + /* Get a pointer to the internal file object */ + if (NULL==(f=H5I_object(file))) { + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + + /* + * Create v2 B-tree + */ + if (H5B2_create(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, 512, 8, 100, 40, &bt2_addr/*out*/)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + + /* + * Test inserting many records into v2 B-tree + */ + TESTING("B-tree many - split 3 leaves to 4 in level 1 B-tree"); + + /* Insert enough records to force root to split into 2 leaves */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC; u++) { + record=u+INSERT_SPLIT_ROOT_NREC*2; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } + + /* Force split from left node into right node */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC*2; u++) { + record=u; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_insert_level1_3leaf_split() */ /*------------------------------------------------------------------------- @@ -503,10 +681,12 @@ main(void) nerrors += test_insert_split_root(fapl); nerrors += test_insert_level1_2leaf_redistrib(fapl); nerrors += test_insert_level1_2leaf_split(fapl); + nerrors += test_insert_level1_3leaf_redistrib(fapl); + nerrors += test_insert_level1_3leaf_split(fapl); if (nerrors) goto error; puts("All v2 B-tree tests passed."); -#ifndef QAK +#ifdef QAK h5_cleanup(FILENAME, fapl); #else /* QAK */ HDfprintf(stderr,"Uncomment cleanup!\n"); |