From da3eeee908eb6f6432b7fb15ce211c890d097dd5 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 10 Mar 2005 22:45:56 -0500 Subject: [svn-r10189] Purpose: New feature & bug fix Description: Support inserting multiple blocks Start tracking the metadata about the blocks. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti) --- src/H5BT.c | 53 ++++++++++++++++++++++++++++++++++++++++- test/blocktrack.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/H5BT.c b/src/H5BT.c index fa59af0..89a31c5 100644 --- a/src/H5BT.c +++ b/src/H5BT.c @@ -33,12 +33,22 @@ /* Local macros */ -/* v2 B-tree info */ +/* v2 B-tree settings */ #define H5BT_BT2_NODE_SIZE 512 #define H5BT_BT2_RREC_SIZE(f) (H5F_SIZEOF_ADDR(f) + H5F_SIZEOF_SIZE(f)) /* Offset & length of block tracked */ #define H5BT_BT2_SPLIT_PERC 100 #define H5BT_BT2_MERGE_PERC 40 +/* Bit flags for block tracker size status */ +#define H5BT_STATUS_MAX_VALID 0x01 /* Maximum block size valid over all blocks tracked */ + /* If this flag is not set, then only part of the blocks have been */ + /* searched to determine the current maximum block size. This can happen */ + /* during block shrinks or removals */ +#define H5BT_STATUS_MIN_VALID 0x01 /* Minimum block size valid over all blocks tracked */ + /* If this flag is not set, then only part of the blocks have been */ + /* searched to determine the current minimum block size. This can happen */ + /* during block expansions or removals */ + /* Local typedefs */ /* Local prototypes */ @@ -86,6 +96,8 @@ H5BT_create(H5F_t *f, hid_t dxpl_id, haddr_t *addr_p) /* Assign internal information */ bt->cache_info.is_dirty = TRUE; + bt->max_block_size = 0; /* Indicate that the value is invalid */ + bt->min_block_size = HSIZET_MAX; /* Indicate that the value is invalid */ /* Allocate space for the header on disk */ if (HADDR_UNDEF==(*addr_p=H5MF_alloc(f, H5FD_MEM_BLKTRK, dxpl_id, (hsize_t)H5BT_SIZE(f)))) @@ -160,6 +172,7 @@ H5BT_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, haddr_t offset, hsize_t lengt H5BT_blk_info_t lower, upper; /* Info for blocks less than & greater than new block */ hbool_t lower_valid = FALSE, upper_valid = FALSE; /* Lower & upper blocks valid? */ H5BT_blk_info_t new_block; /* Info for new block */ + hsize_t nblks; /* Number of blocks tracked */ herr_t ret_value=SUCCEED; FUNC_ENTER_NOAPI(H5BT_insert, FAIL) @@ -202,11 +215,13 @@ H5BT_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, haddr_t offset, hsize_t lengt /* Clear any errors from H5B2_neighbor() */ H5E_clear_stack(NULL); +#ifdef QAK /* Check for merged blocks */ if(lower_valid || upper_valid) { HDfprintf(stderr,"%s: Lower & upper block merging not supported yet!\n",FUNC); HGOTO_ERROR(H5E_BLKTRK, H5E_UNSUPPORTED, FAIL, "lower or upper block found!") } /* end if */ +#endif /* QAK */ /* Insert new block into B-tree */ new_block.addr = offset; @@ -214,6 +229,42 @@ HGOTO_ERROR(H5E_BLKTRK, H5E_UNSUPPORTED, FAIL, "lower or upper block found!") if(H5B2_insert(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, &new_block) < 0) HDONE_ERROR(H5E_BLKTRK, H5E_CANTINSERT, FAIL, "unable to insert block") +/* Update block tracker metadata */ + + /* Determine the number of blocks being tracked */ + if(H5B2_get_nrec(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, &nblks) < 0) + HDONE_ERROR(H5E_BLKTRK, H5E_CANTINSERT, FAIL, "unable to determine # of blocks") + + /* This is the only block tracked so far */ + if(nblks == 1) { + bt->max_block_size = length; + bt->max_block_cnt = 1; + bt->status |= H5BT_STATUS_MAX_VALID; + bt->min_block_size = length; + bt->min_block_cnt = 1; + bt->status |= H5BT_STATUS_MAX_VALID; + } /* end if */ + else { + /* Update maximum block size */ + if (length > bt->max_block_size) { + bt->max_block_size = length; + bt->max_block_cnt = 1; + } /* end if */ + else if (length == bt->max_block_size) + bt->max_block_cnt++; + + /* Update minimum block size */ + if (length < bt->min_block_size) { + bt->min_block_size = length; + bt->min_block_cnt = 1; + } /* end if */ + else if (length == bt->min_block_size) + bt->min_block_cnt++; + } /* end if */ + + /* Increment total number of bytes tracked in all blocks */ + bt->tot_block_size += length; + done: /* Release the block tracker info */ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0) diff --git a/test/blocktrack.c b/test/blocktrack.c index 2b271a2..8929bfc 100644 --- a/test/blocktrack.c +++ b/test/blocktrack.c @@ -31,6 +31,8 @@ const char *FILENAME[] = { NULL }; +#define INSERT_MANY 100 + /*------------------------------------------------------------------------- * Function: test_create @@ -156,6 +158,74 @@ error: /*------------------------------------------------------------------------- + * Function: test_insert_many + * + * Purpose: Basic tests for the block tracker code + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Thursday, March 10, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_insert_many(hid_t fapl) +{ + hid_t file=-1; + char filename[1024]; + H5F_t *f=NULL; + haddr_t bt_addr; /* Address of block tracker 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; + } /* 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 */ + + /* + * Test inserting many, non-overlapping, non-mergeable blocks + */ + TESTING("insert many blocks"); + for(u = 0; u < INSERT_MANY; u++) { + if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)(u*50), (hsize_t)20)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + } /* end for */ + + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_insert_many() */ + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Test the block tracker code @@ -186,6 +256,7 @@ main(void) /* Test block tracker insertion */ nerrors += test_insert_one(fapl); + nerrors += test_insert_many(fapl); if (nerrors) goto error; puts("All block tracker tests passed."); -- cgit v0.12