From 8d2ddf51709999a74dd32df49e52509d82eee627 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sat, 5 Mar 2005 00:04:13 -0500 Subject: [svn-r10154] Purpose: Bug fix/new feature Description: Tweak the record promotion algorithm to get it working correctly when promoting and redistributing records. Added tests for that case. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti) --- src/H5B2.c | 23 +++-- test/btree2.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 288 insertions(+), 13 deletions(-) diff --git a/src/H5B2.c b/src/H5B2.c index 0296454..379a440 100644 --- a/src/H5B2.c +++ b/src/H5B2.c @@ -3404,20 +3404,9 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, /* Locate node pointer for child */ cmp=H5B2_locate_record(shared->type,internal->nrec,shared->nat_off,internal->int_native,udata,&idx); - if(cmp>0) - idx++; - - /* Handle deleting a record from an internal node */ - if(cmp==0) { - /* Increment the index to work with */ + if(cmp >= 0) 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 */ - - /* Set the number of redistribution retries */ /* This takes care of the case where a B-tree node needs to be * redistributed, but redistributing the node causes the index @@ -3470,12 +3459,20 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, /* Locate node pointer for child (after merge/redistribute) */ /* Actually, this can be easily updated (for 2-node redistrib.) and shouldn't require re-searching */ cmp=H5B2_locate_record(shared->type,internal->nrec,shared->nat_off,internal->int_native,udata,&idx); - if(cmp > 0) + if(cmp >= 0) idx++; /* Decrement the number of redistribution retries left */ retries--; } /* end while */ + + /* Handle deleting a record from an internal node */ + if(cmp==0) { + /* 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 */ + } /* end block */ /* Attempt to remove node */ diff --git a/test/btree2.c b/test/btree2.c index d2d3547..2f9cf5e 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -2985,6 +2985,282 @@ error: /*------------------------------------------------------------------------- + * Function: test_remove_level1_promote_2leaf_redistrib_right + * + * 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_2leaf_redistrib_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-1 B-tree with 3 leaves */ + for(u=0; u