From 2df8540798bfdc92833f67bc3b7e5186fb8b234b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 8 Mar 2005 11:18:58 -0500 Subject: [svn-r10162] Purpose: Bug fix & new tests Description: Fix several errors in record removel routines, which should now be feature complete for removing records at any location in the B-tree (further testing will verify this) Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti) --- src/H5B2.c | 14 +- test/btree2.c | 903 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 905 insertions(+), 12 deletions(-) diff --git a/src/H5B2.c b/src/H5B2.c index 60f170d..ba193eb 100644 --- a/src/H5B2.c +++ b/src/H5B2.c @@ -48,7 +48,7 @@ #define H5B2_NUM_LEAF_REC(n,r) (((n)-H5B2_OVERHEAD_SIZE)/(r)) /* Uncomment this macro to enable extra sanity checking */ -#define H5B2_DEBUG +/* #define H5B2_DEBUG */ /* Local typedefs */ @@ -1859,8 +1859,6 @@ H5B2_merge2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ left_addr = internal->node_ptrs[idx].addr; right_addr = internal->node_ptrs[idx+1].addr; -HDfprintf(stderr,"%s: Merging 2 internal nodes in B-tree, untested!\n",FUNC); -HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree") /* Lock left & right B-tree child nodes */ if (NULL == (left_internal = H5AC_protect(f, dxpl_id, child_class, left_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") @@ -2029,8 +2027,6 @@ H5B2_merge3(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *curr_node_ middle_addr = internal->node_ptrs[idx].addr; right_addr = internal->node_ptrs[idx+1].addr; -HDfprintf(stderr,"%s: Merging 2 internal nodes 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 == (left_internal = 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_CANTPROTECT, FAIL, "unable to load B-tree internal node") @@ -2119,7 +2115,7 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree") unsigned u; /* Local index variable */ /* Copy node pointers from middle node into left node */ - HDmemcpy(&(left_node_ptrs[0]),&(middle_node_ptrs[0]),sizeof(H5B2_node_ptr_t)*middle_nrec_move); + HDmemcpy(&(left_node_ptrs[*left_nrec+1]),&(middle_node_ptrs[0]),sizeof(H5B2_node_ptr_t)*middle_nrec_move); /* Count the number of records being moved into the left node */ for(u=0; ur)"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC*5); u++) { + record = u; + 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 != u) 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*21)-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_remove_level2_2internal_merge_left() */ + + +/*------------------------------------------------------------------------- + * Function: test_remove_level2_2internal_merge_right + * + * Purpose: Basic tests for the B-tree v2 code + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Tuesday, March 8, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_remove_level2_2internal_merge_right(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-2 B-tree with 3 internal nodes */ + for(u=0; ul)"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC*6); u++) { + record = (INSERT_SPLIT_ROOT_NREC*21) - (u + 1); + 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 != ((INSERT_SPLIT_ROOT_NREC*21) - (u + 1))) 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*21)-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_remove_level2_2internal_merge_right() */ + + +/*------------------------------------------------------------------------- + * Function: test_remove_level2_3internal_merge + * + * Purpose: Basic tests for the B-tree v2 code + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Tuesday, March 8, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_remove_level2_3internal_merge(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-2 B-tree with 3 internal nodes */ + for(u=0; u