[svn-r10153] Purpose:

New feature

Description:
    Allow records in internal nodes to be removed, not just records in leaf
nodes.

Platforms tested:
    FreeBSD 4.11 (sleipnir)
    Solaris 2.9 (shanti)
This commit is contained in:
Quincey Koziol 2005-03-04 23:04:54 -05:00
parent 009f57c1ba
commit 9845d40eb5
7 changed files with 284 additions and 2 deletions

View File

@ -77,6 +77,8 @@ static herr_t H5B2_merge2(H5F_t *f, hid_t dxpl_id, unsigned depth,
static herr_t H5B2_merge3(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_swap_child(H5F_t *f, hid_t dxpl_id, unsigned depth,
H5B2_internal_t *internal, unsigned idx);
static herr_t H5B2_insert_internal(H5F_t *f, hid_t dxpl_id,
H5RC_t *bt2_shared, unsigned depth, H5AC_info_t *parent_cache_info,
H5B2_node_ptr_t *curr_node_ptr, void *udata);
@ -2198,6 +2200,109 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5B2_merge3 */
/*-------------------------------------------------------------------------
* Function: H5B2_swap_child
*
* Purpose: Swap a record in a node with a record in a child node
*
* Return: Success: Non-negative
*
* Failure: Negative
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 4 2005
*
*-------------------------------------------------------------------------
*/
static herr_t
H5B2_swap_child(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 child_addr; /* Address of child node */
void *child; /* Pointer to child node */
unsigned *child_nrec; /* Pointer to child # of records */
uint8_t *child_native; /* Pointer to 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_swap_child)
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 swap */
if(depth>1) {
H5B2_internal_t *child_internal; /* Pointer to internal node */
/* Setup information for unlocking child node */
child_class = H5AC_BT2_INT;
child_addr = child_internal->node_ptrs[idx].addr;
HDfprintf(stderr,"%s: Swapping with internal node in B-tree, untested!\n",FUNC);
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree")
/* Lock B-tree child nodes */
if (NULL == (child_internal = H5AC_protect(f, dxpl_id, child_class, child_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree internal node")
/* More setup for accessing child node information */
child = child_internal;
child_nrec = &(child_internal->nrec);
child_native = child_internal->int_native;
/* Mark child node as dirty now */
child_internal->cache_info.is_dirty = TRUE;
} /* end if */
else {
H5B2_leaf_t *child_leaf; /* Pointer to leaf node */
/* Setup information for unlocking child nodes */
child_class = H5AC_BT2_LEAF;
child_addr = internal->node_ptrs[idx].addr;
/* Lock B-tree child node */
if (NULL == (child_leaf = H5AC_protect(f, dxpl_id, child_class, child_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree leaf node")
/* More setup for accessing child node information */
child = child_leaf;
child_nrec = &(child_leaf->nrec);
child_native = child_leaf->leaf_native;
/* Mark child node as dirty now */
child_leaf->cache_info.is_dirty = TRUE;
} /* end else */
/* Swap records (use disk page as temporary buffer) */
HDmemcpy(shared->page, H5B2_NAT_NREC(child_native,shared,0), shared->type->nrec_size);
HDmemcpy(H5B2_NAT_NREC(child_native,shared,0), H5B2_INT_NREC(internal,shared,idx-1), shared->type->nrec_size);
HDmemcpy(H5B2_INT_NREC(internal,shared,idx-1), shared->page, shared->type->nrec_size);
/* Mark parent as dirty */
internal->cache_info.is_dirty = TRUE;
#ifdef H5B2_DEBUG
H5B2_assert_internal((hsize_t)0,shared,internal);
if(depth>1)
H5B2_assert_internal(internal->node_ptrs[idx].all_nrec,shared,child);
else
H5B2_assert_leaf(shared,child);
#endif /* H5B2_DEBUG */
/* Unlock child node */
if (H5AC_unprotect(f, dxpl_id, child_class, child_addr, child, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree child node")
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5B2_swap_child */
/*-------------------------------------------------------------------------
* Function: H5B2_insert_leaf
@ -3304,8 +3409,12 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
/* Handle deleting a record from an internal node */
if(cmp==0) {
HDfprintf(stderr,"%s: Deleting record in internal node of non-trival B-tree!\n",FUNC);
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree")
/* Increment the index to work with */
idx++;
/* Swap record to delete with record from child */
if(H5B2_swap_child(f,dxpl_id,depth,internal,idx) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTSWAP, FAIL, "Can't swap records in B-tree")
} /* end if */

View File

@ -163,6 +163,7 @@ hid_t H5E_CANTENCODE_g = FAIL; /* Unable to encode value */
hid_t H5E_CANTDECODE_g = FAIL; /* Unable to decode value */
hid_t H5E_CANTSPLIT_g = FAIL; /* Unable to split node */
hid_t H5E_CANTREDISTRIBUTE_g = FAIL; /* Unable to redistribute records */
hid_t H5E_CANTSWAP_g = FAIL; /* Unable to swap records */
hid_t H5E_CANTINSERT_g = FAIL; /* Unable to insert object */
hid_t H5E_CANTLIST_g = FAIL; /* Unable to list node */

View File

@ -605,6 +605,11 @@ if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to redistribute records"))==NUL
HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")
if((H5E_CANTREDISTRIBUTE_g = H5I_register(H5I_ERROR_MSG, msg))<0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message")
assert(H5E_CANTSWAP_g==(-1));
if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to swap records"))==NULL)
HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")
if((H5E_CANTSWAP_g = H5I_register(H5I_ERROR_MSG, msg))<0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message")
assert(H5E_CANTINSERT_g==(-1));
if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to insert object"))==NULL)
HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")

View File

@ -271,6 +271,7 @@ H5_DLLVAR hid_t H5E_CANTCOMPARE_g; /* Can't compare objects */
#define H5E_CANTDECODE (H5OPEN H5E_CANTDECODE_g)
#define H5E_CANTSPLIT (H5OPEN H5E_CANTSPLIT_g)
#define H5E_CANTREDISTRIBUTE (H5OPEN H5E_CANTREDISTRIBUTE_g)
#define H5E_CANTSWAP (H5OPEN H5E_CANTSWAP_g)
#define H5E_CANTINSERT (H5OPEN H5E_CANTINSERT_g)
#define H5E_CANTLIST (H5OPEN H5E_CANTLIST_g)
H5_DLLVAR hid_t H5E_NOTFOUND_g; /* Object not found */
@ -279,6 +280,7 @@ H5_DLLVAR hid_t H5E_CANTENCODE_g; /* Unable to encode value */
H5_DLLVAR hid_t H5E_CANTDECODE_g; /* Unable to decode value */
H5_DLLVAR hid_t H5E_CANTSPLIT_g; /* Unable to split node */
H5_DLLVAR hid_t H5E_CANTREDISTRIBUTE_g; /* Unable to redistribute records */
H5_DLLVAR hid_t H5E_CANTSWAP_g; /* Unable to swap records */
H5_DLLVAR hid_t H5E_CANTINSERT_g; /* Unable to insert object */
H5_DLLVAR hid_t H5E_CANTLIST_g; /* Unable to list node */

View File

@ -165,6 +165,7 @@ H5E_CANTENCODE_g=
H5E_CANTDECODE_g=
H5E_CANTSPLIT_g=
H5E_CANTREDISTRIBUTE_g=
H5E_CANTSWAP_g=
H5E_CANTINSERT_g=
H5E_CANTLIST_g=

View File

@ -163,6 +163,7 @@ MINOR, BTREE, H5E_CANTENCODE, Unable to encode value
MINOR, BTREE, H5E_CANTDECODE, Unable to decode value
MINOR, BTREE, H5E_CANTSPLIT, Unable to split node
MINOR, BTREE, H5E_CANTREDISTRIBUTE, Unable to redistribute records
MINOR, BTREE, H5E_CANTSWAP, Unable to swap records
MINOR, BTREE, H5E_CANTINSERT, Unable to insert object
MINOR, BTREE, H5E_CANTLIST, Unable to list node

View File

@ -2821,6 +2821,168 @@ error:
return 1;
} /* test_remove_level1_3leaf_merge() */
/*-------------------------------------------------------------------------
* Function: test_remove_level1_promote
*
* Purpose: Basic tests for the B-tree v2 code
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, March 4, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_remove_level1_promote(hid_t fapl)
{
hid_t file=-1;
char filename[1024];
H5F_t *f=NULL;
hsize_t record; /* Record to insert into tree */
hsize_t nrec; /* Number of records in B-tree */
haddr_t bt2_addr; /* Address of B-tree created */
haddr_t root_addr; /* Address of root 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);
TEST_ERROR;
}
/*
* Test v2 B-tree creation
*/
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;
}
/* Create level-1 B-tree with 5 leaves */
for(u=0; u<INSERT_SPLIT_ROOT_NREC*3; 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;
}
}
/* Query the number of records in the B-tree */
if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the # of records is correct */
if(nrec != (INSERT_SPLIT_ROOT_NREC*3)) TEST_ERROR;
/* Query the address of the root node in the B-tree */
if (H5B2_get_root_addr(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &root_addr)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the address of the root node is defined */
if(!H5F_addr_defined(root_addr)) TEST_ERROR;
/* Attempt to remove record from root node of a level-1 B-tree to force promotion from right leaf */
TESTING("B-tree remove: promote from right leaf of level-1 B-tree");
record = 181;
if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the record value is correct */
if(record != 181) TEST_ERROR;
/* Query the number of records in the B-tree */
if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the # of records is correct */
if(nrec != (INSERT_SPLIT_ROOT_NREC*3)-1) TEST_ERROR;
PASSED();
/* Attempt to remove record from root node of a level-1 B-tree to force promotion from left leaf */
TESTING("B-tree remove: promote from left leaf of level-1 B-tree");
record = 42;
if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the record value is correct */
if(record != 42) TEST_ERROR;
/* Query the number of records in the B-tree */
if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the # of records is correct */
if(nrec != (INSERT_SPLIT_ROOT_NREC*3)-2) TEST_ERROR;
PASSED();
/* Attempt to remove record from root node of a level-1 B-tree to force promotion from middle leaf */
TESTING("B-tree remove: promote from middle leaf of level-1 B-tree");
record = 85;
if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the record value is correct */
if(record != 85) TEST_ERROR;
/* Query the number of records in the B-tree */
if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Make certain that the # of records is correct */
if(nrec != (INSERT_SPLIT_ROOT_NREC*3)-3) TEST_ERROR;
PASSED();
if (H5Fclose(file)<0) TEST_ERROR;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file);
} H5E_END_TRY;
return 1;
} /* test_remove_level1_promote() */
/*-------------------------------------------------------------------------
* Function: main
@ -2877,6 +3039,7 @@ HDfprintf(stderr,"Uncomment tests!\n");
nerrors += test_remove_level1_redistrib(fapl);
nerrors += test_remove_level1_2leaf_merge(fapl);
nerrors += test_remove_level1_3leaf_merge(fapl);
nerrors += test_remove_level1_promote(fapl);
#else /* QAK */
HDfprintf(stderr,"Uncomment tests!\n");
#endif /* QAK */