[svn-r10044] Purpose:

New feature

Description:
    Allow internal nodes in v2 B-tree to perform 2 node redistribution

Platforms tested:
    FreeBSD 4.11 (sleipnir)
    Solaris 2.9 (shanti)
This commit is contained in:
Quincey Koziol 2005-02-18 16:21:47 -05:00
parent 5352cb3f53
commit cd93442df6
2 changed files with 184 additions and 6 deletions

View File

@ -572,7 +572,9 @@ H5B2_redistribute2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_internal_t *int
void *left_child, *right_child; /* Pointers to child nodes */
unsigned *left_nrec, *right_nrec; /* Pointers to child # of records */
uint8_t *left_native, *right_native; /* Pointers to childs' native records */
H5B2_node_ptr_t *left_node_ptrs=NULL, *right_node_ptrs=NULL;/* Pointers to childs' node pointer info */
H5B2_shared_t *shared; /* B-tree's shared info */
int left_moved_nrec=0, right_moved_nrec=0; /* Number of records moved, for internal redistrib */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5B2_redistribute2)
@ -586,8 +588,33 @@ H5B2_redistribute2(H5F_t *f, hid_t dxpl_id, unsigned depth, H5B2_internal_t *int
/* 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")
H5B2_internal_t *left_internal; /* Pointer to left internal node */
H5B2_internal_t *right_internal; /* Pointer to right internal node */
/* Setup information for unlocking child nodes */
child_class = H5AC_BT2_INT;
left_addr = internal->node_ptrs[idx].addr;
right_addr = internal->node_ptrs[idx+1].addr;
/* 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_CANTLOAD, FAIL, "unable to load B-tree leaf node")
if (NULL == (right_internal = 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_internal;
right_child = right_internal;
left_nrec = &(left_internal->nrec);
right_nrec = &(right_internal->nrec);
left_native = left_internal->int_native;
right_native = right_internal->int_native;
left_node_ptrs = left_internal->node_ptrs;
right_node_ptrs = right_internal->node_ptrs;
/* Mark child nodes as dirty now */
left_internal->cache_info.is_dirty = TRUE;
right_internal->cache_info.is_dirty = TRUE;
} /* end if */
else {
H5B2_leaf_t *left_leaf; /* Pointer to left leaf node */
@ -637,6 +664,24 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute recor
/* Slide records in right node down */
HDmemmove(H5B2_NAT_NREC(right_native,shared,0),H5B2_NAT_NREC(right_native,shared,move_nrec),shared->type->nrec_size*new_right_nrec);
/* Handle node pointers, if we have an internal node */
if(depth>1) {
int moved_nrec=move_nrec; /* Total number of records moved, for internal redistrib */
unsigned u; /* Local index variable */
/* Count the number of records being moved */
for(u=0; u<move_nrec; u++)
moved_nrec += right_node_ptrs[u].all_nrec;
left_moved_nrec = moved_nrec;
right_moved_nrec = -moved_nrec;
/* Copy node pointers from right node to left */
HDmemcpy(&(left_node_ptrs[*left_nrec+1]),&(right_node_ptrs[0]),sizeof(H5B2_node_ptr_t)*move_nrec);
/* Slide node pointers in right node down */
HDmemmove(&(right_node_ptrs[0]),&(right_node_ptrs[move_nrec]),sizeof(H5B2_node_ptr_t)*(new_right_nrec+1));
} /* end if */
/* Update number of records in child nodes */
*left_nrec += move_nrec;
*right_nrec = new_right_nrec;
@ -662,15 +707,42 @@ HGOTO_ERROR(H5E_BTREE, H5E_CANTREDISTRIBUTE, FAIL, "unable to redistribute recor
/* 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->nrec_size);
/* Handle node pointers, if we have an internal node */
if(depth>1) {
int moved_nrec=move_nrec; /* Total number of records moved, for internal redistrib */
unsigned u; /* Local index variable */
/* Slide node pointers in right node up */
HDmemmove(&(right_node_ptrs[move_nrec]),&(right_node_ptrs[0]),sizeof(H5B2_node_ptr_t)*(*right_nrec+1));
/* Copy node pointers from left node to right */
HDmemcpy(&(right_node_ptrs[0]),&(left_node_ptrs[new_left_nrec+1]),sizeof(H5B2_node_ptr_t)*move_nrec);
/* Count the number of records being moved */
for(u=0; u<move_nrec; u++)
moved_nrec += right_node_ptrs[u].all_nrec;
left_moved_nrec = -moved_nrec;
right_moved_nrec = moved_nrec;
} /* end if */
/* Update number of records in child nodes */
*left_nrec = new_left_nrec;
*right_nrec += move_nrec;
} /* end else */
/* 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;
internal->node_ptrs[idx].node_nrec = *left_nrec;
internal->node_ptrs[idx+1].node_nrec = *right_nrec;
/* Update total # of records in child B-trees */
if(depth>1) {
internal->node_ptrs[idx].all_nrec += left_moved_nrec;
internal->node_ptrs[idx+1].all_nrec += right_moved_nrec;
} /* end if */
else {
internal->node_ptrs[idx].all_nrec = internal->node_ptrs[idx].node_nrec;
internal->node_ptrs[idx+1].all_nrec = internal->node_ptrs[idx+1].node_nrec;
} /* end else */
/* Unlock child nodes */
if (H5AC_unprotect(f, dxpl_id, child_class, left_addr, left_child, H5AC__NO_FLAGS_SET) < 0)

View File

@ -1090,7 +1090,112 @@ error:
H5Fclose(file);
} H5E_END_TRY;
return 1;
} /* test_insert_level2_leaf_redistrib() */
} /* test_insert_level2_leaf_split() */
/*-------------------------------------------------------------------------
* Function: test_insert_level2_2internal_redistrib
*
* Purpose: Basic tests for the B-tree v2 code. This test inserts enough
* records to make a level 2 B-tree and then adds enough more
* records to force the left-most and right-most internal nodes to
* redistribute.
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, February 18, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_insert_level2_2internal_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 */
hsize_t idx; /* Index within B-tree, for iterator */
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 insert - redist. 2 internal (r->l) in level 2 B-tree");
/* Insert enough records to force root to split into 2 internal nodes */
/* Also forces right-most internal node to redistribute */
for(u=0; u<INSERT_SPLIT_ROOT_NREC*16; u++) {
record=u+(INSERT_SPLIT_ROOT_NREC*3);
if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
}
}
PASSED();
TESTING("B-tree insert - redist. 2 internal (l->r) in level 2 B-tree");
/* Force left-most internal node to redistribute */
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;
}
}
/* Iterate over B-tree to check records have been inserted correctly */
idx = 0;
if(H5B2_iterate(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, iter_cb, &idx)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
}
/* Make certain that the index is correct */
if(idx != (INSERT_SPLIT_ROOT_NREC*19)) TEST_ERROR;
PASSED();
if (H5Fclose(file)<0) TEST_ERROR;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file);
} H5E_END_TRY;
return 1;
} /* test_insert_level2_2internal_redistrib() */
/*-------------------------------------------------------------------------
@ -1129,6 +1234,7 @@ main(void)
nerrors += test_insert_make_level2(fapl);
nerrors += test_insert_level2_leaf_redistrib(fapl);
nerrors += test_insert_level2_leaf_split(fapl);
nerrors += test_insert_level2_2internal_redistrib(fapl);
if (nerrors) goto error;
puts("All v2 B-tree tests passed.");