[svn-r10504] Purpose:

New feature

Description:
    Add wrapper for v2 B-tree "neighbor" routine.

Platforms tested:
    FreeBSD 4.11 (sleipnir)
    Solaris 2.9 (shanti)
This commit is contained in:
Quincey Koziol 2005-03-29 16:26:25 -05:00
parent 785b356d40
commit d484bd9fb7
4 changed files with 376 additions and 13 deletions

View File

@ -655,14 +655,14 @@ done:
/*-------------------------------------------------------------------------
* Function: H5BT_locate_cb
*
* Purpose: v2 B-tree find callback
* Purpose: Block tracker "locate" callback
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, March 11, 2005
* Friday, March 25, 2005
*
* Modifications:
*
@ -718,14 +718,14 @@ H5BT_locate(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t size, haddr_t *locate
HDassert(H5F_addr_defined(addr));
/* Look up the block tracker header */
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_WRITE)))
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
/* Iterate through blocks, looking for first one that is large enough */
found.search_size = size;
found.found.addr = HADDR_UNDEF;
if (H5B2_iterate(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, H5BT_locate_cb, &found) < 0)
HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to locate block")
HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to iterate over blocks")
/* Update user's information, if block was found */
if(H5F_addr_defined(found.found.addr)) {
@ -745,6 +745,140 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5BT_locate() */
/*-------------------------------------------------------------------------
* Function: H5BT_iterate
*
* Purpose: Iterate over blocks in tracker, making callback for each
*
* If the callback returns non-zero, the iteration breaks out
* without finishing all the records.
*
* Return: Value from callback: non-negative on success, negative on error
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 25 2005
*
*-------------------------------------------------------------------------
*/
herr_t
H5BT_iterate(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5BT_operator_t op, void *op_data)
{
H5BT_t *bt = NULL; /* The new B-tree header information */
herr_t ret_value;
FUNC_ENTER_NOAPI(H5BT_iterate, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(op);
/* Look up the block tracker header */
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
/* Iterate through blocks, passing along op & op_data */
if ((ret_value = H5B2_iterate(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, (H5B2_operator_t)op, op_data)) < 0)
HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to iterate over blocks")
done:
/* Release the block tracker info */
if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_BLKTRK, H5E_CANTUNPROTECT, FAIL, "unable to release block tracker info")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5BT_iterate() */
/*-------------------------------------------------------------------------
* Function: H5BT_neighbor_cb
*
* Purpose: Block tracker "neighbor" callback
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Monday, March 28, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
H5BT_neighbor_cb(const void *_record, void *_op_data)
{
const H5BT_blk_info_t *record = (const H5BT_blk_info_t *)_record;
H5BT_blk_info_t *search = (H5BT_blk_info_t *)_op_data;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5BT_neighbor_cb)
/* Save block information for later */
*search = *record;
FUNC_LEAVE_NOAPI(SUCCEED);
} /* end H5BT_neighbor_cb() */
/*-------------------------------------------------------------------------
* Function: H5BT_neighbor
*
* Purpose: Locate block that is related to a given address
*
* Return: Non-negative on success, negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 28 2005
*
*-------------------------------------------------------------------------
*/
herr_t
H5BT_neighbor(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5BT_compare_t range,
haddr_t range_addr, H5BT_blk_info_t *found_block)
{
H5BT_t *bt = NULL; /* The new B-tree header information */
H5BT_blk_info_t find; /* Information for locating block */
H5BT_blk_info_t found; /* Block info found */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5BT_neighbor, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
/* Look up the block tracker header */
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
/* Iterate through blocks, looking for first one that is large enough */
find.addr = range_addr;
find.len = 0;
found.addr = HADDR_UNDEF;
if (H5B2_neighbor(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, (H5B2_compare_t)range,
&find, H5BT_neighbor_cb, &found) < 0)
HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to find neighbor for block")
/* Update user's information, if block was found */
if(H5F_addr_defined(found.addr))
*found_block = found;
done:
/* Release the block tracker info */
if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_BLKTRK, H5E_CANTUNPROTECT, FAIL, "unable to release block tracker info")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5BT_neighbor() */
/*-------------------------------------------------------------------------
* Function: H5BT_delete

View File

@ -32,7 +32,6 @@
/* Other private headers needed by this file */
#include "H5ACprivate.h" /* Metadata cache */
#include "H5B2private.h" /* v2 B-trees */
#include "H5FLprivate.h" /* Free Lists */
/**************************/
@ -87,12 +86,6 @@ typedef struct H5BT_t {
haddr_t bt2_addr; /* Address of v2 B-tree that holds block info */
} H5BT_t;
/* Info for a single block */
typedef struct H5BT_blk_info_t {
haddr_t addr; /* Address (offset) of block in file */
hsize_t len; /* Length of block in file */
} H5BT_blk_info_t;
/*****************************/
/* Package Private Variables */

View File

@ -30,17 +30,41 @@
#include "H5BTpublic.h"
/* Private headers needed by this file */
#include "H5B2private.h" /* v2 B-trees */
#include "H5Fprivate.h" /* File access */
/**************************/
/* Library Private Macros */
/**************************/
/* Define return values from operator callback function for H5BT_iterate */
/* (Actually, any positive value will cause the iterator to stop and pass back
* that positive value to the function that called the iterator)
*/
#define H5BT_ITER_ERROR H5B2_ITER_ERROR
#define H5BT_ITER_CONT H5B2_ITER_CONT
#define H5BT_ITER_STOP H5B2_ITER_STOP
/****************************/
/* Library Private Typedefs */
/****************************/
/* Info for a single block (stored as record in B-tree) */
typedef struct H5BT_blk_info_t {
haddr_t addr; /* Address (offset) of block in file */
hsize_t len; /* Length of block in file */
} H5BT_blk_info_t;
/* Define the operator callback function pointer for H5BT_iterate() */
typedef int (*H5BT_operator_t)(const H5BT_blk_info_t *record, void *op_data);
/* Comparisons for H5BT_neighbor() call */
typedef enum H5BT_compare_t {
H5BT_COMPARE_LESS = H5B2_COMPARE_LESS, /* Records with keys less than query value */
H5BT_COMPARE_GREATER = H5B2_COMPARE_GREATER /* Records with keys greater than query value */
} H5BT_compare_t;
/***************************************/
/* Library-private Function Prototypes */
@ -54,6 +78,10 @@ H5_DLL herr_t H5BT_get_total_size(H5F_t *f, hid_t dxpl_id, haddr_t addr,
hsize_t *tot_size);
H5_DLL herr_t H5BT_locate(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t size,
haddr_t *locate_addr, hsize_t *locate_size);
H5_DLL herr_t H5BT_iterate(H5F_t *f, hid_t dxpl_id, haddr_t addr,
H5BT_operator_t op, void *op_data);
H5_DLL herr_t H5BT_neighbor(H5F_t *f, hid_t dxpl_id, haddr_t addr,
H5BT_compare_t range, haddr_t range_addr, H5BT_blk_info_t *found_block);
H5_DLL herr_t H5BT_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr);
#endif /* _H5BTprivate_H */

View File

@ -35,6 +35,35 @@ const char *FILENAME[] = {
#define INSERT_MANY 100
/*-------------------------------------------------------------------------
* Function: iter_cb
*
* Purpose: Block tracker iterator callback
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, March 25, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
iter_cb(const H5BT_blk_info_t *record, void *_op_data)
{
haddr_t *addr = (haddr_t *)_op_data;
if(record->addr != *addr)
return(H5B2_ITER_ERROR);
*addr *= 2;
return(H5B2_ITER_CONT);
} /* end iter_cb() */
/*-------------------------------------------------------------------------
* Function: test_create
@ -1439,7 +1468,7 @@ error:
* Failure: 1
*
* Programmer: Quincey Koziol
* Monday, March 24, 2005
* Thursday, March 24, 2005
*
* Modifications:
*
@ -1544,6 +1573,181 @@ error:
return 1;
} /* test_locate() */
/*-------------------------------------------------------------------------
* Function: test_neighbor
*
* Purpose: Basic tests for the block tracker code
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Monday, March 28, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_neighbor(hid_t fapl)
{
hid_t file=-1;
char filename[1024];
H5F_t *f=NULL;
haddr_t bt_addr; /* Address of block tracker created */
H5BT_blk_info_t block; /* Block located */
haddr_t search_addr; /* Address of block to search for neighbor of */
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;
} /* end if */
if (H5BT_create(f, H5P_DATASET_XFER_DEFAULT, &bt_addr/*out*/)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Insert blocks */
block.addr = 2048;
block.len = 8;
for(u = 0; u < 10; u++) {
if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, block.addr, block.len)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Increment block address & size for next insertion */
block.addr *= 2;
block.len *= 2;
} /* end for */
TESTING("attempt to find neighbor of a block");
search_addr = 4097;
if (H5BT_neighbor(f, H5P_DATASET_XFER_DEFAULT, bt_addr, H5BT_COMPARE_LESS, search_addr, &block)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
if(block.addr != 4096) TEST_ERROR;
if(block.len != 16) TEST_ERROR;
search_addr = 4096;
if (H5BT_neighbor(f, H5P_DATASET_XFER_DEFAULT, bt_addr, H5BT_COMPARE_LESS, search_addr, &block)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
if(block.addr != 2048) TEST_ERROR;
if(block.len != 8) TEST_ERROR;
PASSED();
if (H5Fclose(file)<0) TEST_ERROR;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file);
} H5E_END_TRY;
return 1;
} /* test_locate() */
/*-------------------------------------------------------------------------
* Function: test_iterate
*
* Purpose: Basic tests for the block tracker code
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, March 25, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_iterate(hid_t fapl)
{
hid_t file=-1;
char filename[1024];
H5F_t *f=NULL;
haddr_t bt_addr; /* Address of block tracker created */
haddr_t block_addr; /* Address of block to insert */
hsize_t block_size; /* Size of block to insert */
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;
} /* end if */
if (H5BT_create(f, H5P_DATASET_XFER_DEFAULT, &bt_addr/*out*/)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Insert blocks */
block_addr = 2048;
block_size = 8;
for(u = 0; u < 10; u++) {
if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, block_addr, block_size)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
/* Increment block address & size for next insertion */
block_addr *= 2;
block_size *= 2;
} /* end for */
TESTING("iterating over blocks");
block_addr = 2048;
if (H5BT_iterate(f, H5P_DATASET_XFER_DEFAULT, bt_addr, iter_cb, &block_addr)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
goto error;
} /* end if */
PASSED();
if (H5Fclose(file)<0) TEST_ERROR;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file);
} H5E_END_TRY;
return 1;
} /* test_iterate() */
/*-------------------------------------------------------------------------
* Function: test_delete
@ -1716,8 +1920,12 @@ main(void)
nerrors += test_remove_whole(fapl);
nerrors += test_remove_partial_begin(fapl);
/* Test block tracker locate */
/* Test block tracker search functions */
nerrors += test_locate(fapl);
nerrors += test_neighbor(fapl);
/* Test block tracker iterate */
nerrors += test_iterate(fapl);
/* Test block tracker deletion */
nerrors += test_delete(fapl);