mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-04-12 17:31:09 +08:00
[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)
This commit is contained in:
parent
9845d40eb5
commit
8d2ddf5170
23
src/H5B2.c
23
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)
|
||||
if(cmp >= 0)
|
||||
idx++;
|
||||
|
||||
/* Handle deleting a record from an internal node */
|
||||
if(cmp==0) {
|
||||
/* 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 */
|
||||
|
||||
|
||||
/* 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 */
|
||||
|
278
test/btree2.c
278
test/btree2.c
@ -2983,6 +2983,282 @@ error:
|
||||
return 1;
|
||||
} /* test_remove_level1_promote() */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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<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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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*2)) 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 w/redistrib");
|
||||
|
||||
/* Remove records from right leaf until its ready to redistribute */
|
||||
for(u=0; u < 33; u++) {
|
||||
record = (INSERT_SPLIT_ROOT_NREC*2)-(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*2)-(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*2)-(u+1))) TEST_ERROR;
|
||||
} /* end for */
|
||||
|
||||
record = 101;
|
||||
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 != 101) 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*2)-34) 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_2leaf_redistrib_right() */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: test_remove_level1_promote_2leaf_redistrib_middle
|
||||
*
|
||||
* 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_middle(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<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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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*2)) 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 middle leaf */
|
||||
TESTING("B-tree remove: promote from middle leaf of level-1 B-tree w/redistrib");
|
||||
|
||||
/* Remove records from right leaf until its ready to redistribute */
|
||||
for(u=0; u < 33; u++) {
|
||||
record = 43 + 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 != (43 + 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*2)-(u+1))) TEST_ERROR;
|
||||
} /* end for */
|
||||
|
||||
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*2)-34) 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_2leaf_redistrib_middle() */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
@ -3040,6 +3316,8 @@ HDfprintf(stderr,"Uncomment tests!\n");
|
||||
nerrors += test_remove_level1_2leaf_merge(fapl);
|
||||
nerrors += test_remove_level1_3leaf_merge(fapl);
|
||||
nerrors += test_remove_level1_promote(fapl);
|
||||
nerrors += test_remove_level1_promote_2leaf_redistrib_right(fapl);
|
||||
nerrors += test_remove_level1_promote_2leaf_redistrib_middle(fapl);
|
||||
#else /* QAK */
|
||||
HDfprintf(stderr,"Uncomment tests!\n");
|
||||
#endif /* QAK */
|
||||
|
Loading…
x
Reference in New Issue
Block a user