summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-03-18 21:33:48 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-03-18 21:33:48 (GMT)
commita53790e16a5e7109a52e8b4a611954f52890a804 (patch)
tree7ebe9b191aeef1815621089914996f6259b8ada2
parentcac506d3fb8b2f0edc8b52d684849b8da9801840 (diff)
downloadhdf5-a53790e16a5e7109a52e8b4a611954f52890a804.zip
hdf5-a53790e16a5e7109a52e8b4a611954f52890a804.tar.gz
hdf5-a53790e16a5e7109a52e8b4a611954f52890a804.tar.bz2
[svn-r12122] Purpose:
Code update Description: Add basics of routine for reading information back out of a fractal heap. Platforms tested: FreeBSD 4.11 (sleipnir) Too minor to require h5committest
-rw-r--r--src/H5HF.c71
-rw-r--r--src/H5HFcache.c2
-rw-r--r--src/H5HFint.c92
-rw-r--r--src/H5HFpkg.h2
-rw-r--r--src/H5HFprivate.h2
-rw-r--r--test/fheap.c102
6 files changed, 264 insertions, 7 deletions
diff --git a/src/H5HF.c b/src/H5HF.c
index d5649d8..ac5990b 100644
--- a/src/H5HF.c
+++ b/src/H5HF.c
@@ -159,7 +159,7 @@ herr_t
H5HF_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t size,
const void *obj, void *id/*out*/)
{
- H5HF_t *fh = NULL; /* The new fractal heap header information */
+ H5HF_t *fh = NULL; /* The fractal heap header information */
H5HF_shared_t *shared; /* Shared fractal heap information */
unsigned hdr_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for header */
herr_t ret_value = SUCCEED;
@@ -198,7 +198,7 @@ HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "standalone blocks not supported ye
HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "'write once' managed blocks not supported yet")
} /* end if */
else {
- H5HF_section_free_node_t *sec_node;
+ H5HF_section_free_node_t *sec_node; /* Pointer to free space section */
/* Find free space in heap */
if(H5HF_man_find(fh->shared, dxpl_id, size, &sec_node) < 0)
@@ -221,3 +221,70 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_insert() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5HF_read
+ *
+ * Purpose: Read an object from a fractal heap into a buffer
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 18 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5HF_read(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_id,
+ void *obj/*out*/)
+{
+ H5HF_t *fh = NULL; /* The fractal heap header information */
+ H5HF_shared_t *shared; /* Shared fractal heap information */
+ const uint8_t *id = (const uint8_t *)_id; /* Object ID */
+ hsize_t obj_off; /* Object's offset in heap */
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_NOAPI(H5HF_read, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
+ HDassert(id);
+ HDassert(obj);
+
+ /*
+ * Load the fractal heap header.
+ */
+ if(NULL == (fh = H5AC_protect(f, dxpl_id, H5AC_FHEAP_HDR, addr, NULL, NULL, H5AC_READ)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
+
+ /* Get the pointer to the shared fractal heap info */
+ shared = H5RC_GET_OBJ(fh->shared);
+ HDassert(shared);
+
+ /* Decode the offset within the heap */
+ UINT64DECODE_VAR(id, obj_off, shared->heap_off_size);
+#ifdef QAK
+HDfprintf(stderr, "%s: obj_off = %Hu\n", FUNC, obj_off);
+#endif /* QAK */
+
+ /* Check for standalone object */
+ if(obj_off & 0) {
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "standalone blocks not supported yet")
+ } /* end if */
+ else {
+ /* Read object from managed heap blocks */
+ if(H5HF_man_read(fh->shared, dxpl_id, obj_off, obj) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't read object from fractal heap")
+ } /* end else */
+
+done:
+ if(fh && H5AC_unprotect(f, dxpl_id, H5AC_FHEAP_HDR, addr, fh, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap header")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_read() */
+
diff --git a/src/H5HFcache.c b/src/H5HFcache.c
index 2b34604..fbeecc8 100644
--- a/src/H5HFcache.c
+++ b/src/H5HFcache.c
@@ -1064,7 +1064,7 @@ H5HF_cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrows
iblock->next_dir_size = shared->man_dtable.cparam.start_block_size;
else
iblock->next_dir_size = shared->man_dtable.cparam.start_block_size * (1 << (iblock->next_dir_row - 1));
- if(heap_addr == 0)
+ if(iblock->block_off == 0)
iblock->max_direct_rows = shared->man_dtable.max_direct_rows;
else
HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, NULL, "computing max direct rows for non-root indirect block not supported yet")
diff --git a/src/H5HFint.c b/src/H5HFint.c
index 4464bb1..bbae6a2 100644
--- a/src/H5HFint.c
+++ b/src/H5HFint.c
@@ -1272,6 +1272,92 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5HF_man_read
+ *
+ * Purpose: Read an object from a managed heap
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 17 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5HF_man_read(H5RC_t *fh_shared, hid_t dxpl_id, hsize_t obj_off, void *obj)
+{
+ H5HF_shared_t *shared; /* Pointer to shared heap info */
+ unsigned row, col; /* Row & column for object's block */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_man_read)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(fh_shared);
+ HDassert(obj_off > 0);
+ HDassert(obj);
+
+ /* Get the pointer to the shared heap info */
+ shared = H5RC_GET_OBJ(fh_shared);
+ HDassert(shared);
+
+ /* Check for root direct block */
+ if(shared->man_dtable.curr_root_rows == 0) {
+ H5HF_parent_shared_t par_shared; /* Parent shared information */
+ H5HF_direct_t *dblock; /* Pointer to direct block to query */
+ size_t blk_off; /* Offset of object in block */
+ uint8_t *p; /* Temporary pointer to obj info in block */
+ size_t obj_size; /* Size of object */
+
+#ifdef QAK
+ /* Look up row & column for object */
+ if(H5HF_dtable_lookup(&shared->man_dtable, obj_off, &row, &col) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPUTE, FAIL, "can't compute row & column of object")
+HDfprintf(stderr, "%s: row = %u, col = %u\n", FUNC, row, col);
+#endif /* QAK */
+
+ /* Lock first (root) direct block */
+ par_shared.shared = fh_shared;
+ par_shared.parent = NULL;
+ par_shared.parent_entry = 0;
+ par_shared.parent_free_space = shared->total_man_free;
+ if(NULL == (dblock = H5AC_protect(shared->f, dxpl_id, H5AC_FHEAP_DBLOCK, shared->man_dtable.table_addr, &shared->man_dtable.cparam.start_block_size, &par_shared, H5AC_READ)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap direct block")
+
+ /* Compute offset of object within block */
+ HDassert((obj_off - dblock->block_off) < (hsize_t)shared->man_dtable.cparam.start_block_size);
+ blk_off = (size_t)(obj_off - dblock->block_off);
+
+ /* Point to location for object */
+ p = dblock->blk + blk_off;
+
+ /* Decode the length */
+ UINT64DECODE_VAR(p, obj_size, dblock->blk_off_size);
+
+ /* Skip over the free fragment size & ref count */
+ p += 1 + (shared->ref_count_obj ? shared->ref_count_size : 0);
+
+ /* Copy the object's data into the heap */
+ HDmemcpy(obj, p, obj_size);
+
+ /* Unlock first (root) direct block */
+ if(H5AC_unprotect(shared->f, dxpl_id, H5AC_FHEAP_DBLOCK, shared->man_dtable.table_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap direct block")
+ dblock = NULL;
+ } /* end if */
+ else {
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "root indirect blocks not supported yet")
+ } /* end else */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_man_read() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5HF_iblock_free
*
* Purpose: Free fractal heap indirect block
@@ -1465,6 +1551,7 @@ HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, NULL, "skipping direct block sizes not su
/* Check if we need a direct block past current allocation */
if(iblock->next_dir_row == iblock->ndir_rows) {
haddr_t old_addr; /* Old address of indirect block */
+ haddr_t new_addr; /* New address of indirect block */
unsigned new_nrows; /* New # of direct rows */
size_t u; /* Local index variable */
@@ -1499,7 +1586,7 @@ HDfprintf(stderr, "%s: new_nrows = %u\n", FUNC, new_nrows);
iblock->size = H5HF_MAN_INDIRECT_SIZE(shared, iblock);
/* Allocate space for the new indirect block on disk */
- if(HADDR_UNDEF == (shared->man_dtable.table_addr = H5MF_alloc(shared->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, (hsize_t)iblock->size)))
+ if(HADDR_UNDEF == (new_addr = H5MF_alloc(shared->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_STORAGE, H5E_NOSPACE, NULL, "file allocation failed for fractal heap indirect block")
/* Re-allocate direct block entry table */
@@ -1522,11 +1609,12 @@ HDfprintf(stderr, "%s: new_nrows = %u\n", FUNC, new_nrows);
HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap indirect block")
/* Move object in cache */
- if(H5AC_rename(shared->f, H5AC_FHEAP_IBLOCK, old_addr, shared->man_dtable.table_addr) < 0)
+ if(H5AC_rename(shared->f, H5AC_FHEAP_IBLOCK, old_addr, new_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSPLIT, NULL, "unable to move fractal heap root indirect block")
/* Update other shared header info */
shared->man_dtable.curr_root_rows = new_nrows;
+ shared->man_dtable.table_addr = new_addr;
/* Mark heap header as modified */
shared->dirty = TRUE;
diff --git a/src/H5HFpkg.h b/src/H5HFpkg.h
index 7ccf879..33a9d37 100644
--- a/src/H5HFpkg.h
+++ b/src/H5HFpkg.h
@@ -373,6 +373,8 @@ H5_DLL herr_t H5HF_man_find(H5RC_t *fh_shared, hid_t dxpl_id, size_t request,
H5_DLL herr_t H5HF_man_insert(H5RC_t *fh_shared, hid_t dxpl_id,
H5HF_section_free_node_t *sec_node, size_t obj_size, const void *obj,
void *id);
+H5_DLL herr_t H5HF_man_read(H5RC_t *fh_shared, hid_t dxpl_id, hsize_t obj_off,
+ void *obj);
/* Metadata cache callbacks */
H5_DLL herr_t H5HF_cache_hdr_dest(H5F_t *f, H5HF_t *fh);
diff --git a/src/H5HFprivate.h b/src/H5HFprivate.h
index b5abe9e..4454ee7 100644
--- a/src/H5HFprivate.h
+++ b/src/H5HFprivate.h
@@ -81,6 +81,8 @@ H5_DLL herr_t H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam,
haddr_t *addr_p);
H5_DLL herr_t H5HF_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t size,
const void *obj, void *id/*out*/);
+H5_DLL herr_t H5HF_read(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *id,
+ void *obj/*out*/);
#endif /* _H5HFprivate_H */
diff --git a/test/fheap.c b/test/fheap.c
index 5c3a54c..00dca95 100644
--- a/test/fheap.c
+++ b/test/fheap.c
@@ -352,6 +352,7 @@ test_abs_insert_first(hid_t fapl)
H5HF_create_t cparam; /* Creation parameters for heap */
haddr_t fh_addr; /* Address of fractal heap created */
unsigned char obj[10]; /* Buffer for object to insert */
+ unsigned char obj2[10]; /* Buffer for object to read */
hsize_t heap_id; /* Heap ID for object inserted */
unsigned u; /* Local index variable */
@@ -388,6 +389,13 @@ test_abs_insert_first(hid_t fapl)
FAIL_STACK_ERROR
if(check_stats(f, H5P_DATASET_XFER_DEFAULT, fh_addr, (hsize_t)1024, (hsize_t)1024, (hsize_t)0, (hsize_t)983, (hsize_t)1))
FAIL_STACK_ERROR
+
+ /* Check reading back in the object */
+ if(H5HF_read(f, dxpl, fh_addr, &heap_id, obj2) < 0)
+ FAIL_STACK_ERROR
+ if(HDmemcmp(obj, obj2, sizeof(obj)))
+ FAIL_STACK_ERROR
+
PASSED()
/* Close the file */
@@ -1002,6 +1010,94 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_abs_fill_second_row
+ *
+ * Purpose: Test inserting mult. objects into absolute heap, creating
+ * enough direct blocks to fill first row of root indirect
+ * block, then fill the second row also.
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Tuesday, March 14, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_abs_fill_second_row(hid_t fapl)
+{
+ hid_t file = -1; /* File ID */
+ hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
+ char filename[1024]; /* Filename to use */
+ H5F_t *f = NULL; /* Internal file object pointer */
+ H5HF_create_t cparam; /* Creation parameters for heap */
+ haddr_t fh_addr; /* Address of fractal heap created */
+ unsigned nobjs = 0; /* Number of objects inserted */
+ unsigned tot_nobjs = 0; /* Total number of objects inserted */
+ unsigned u; /* Local index variable */
+
+ /* Set the filename to use for this test (dependent on fapl) */
+ 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)))
+ STACK_ERROR
+
+ /* Create absolute heap */
+ init_std_cparam(&cparam);
+ if(H5HF_create(f, dxpl, &cparam, &fh_addr/*out*/) < 0)
+ FAIL_STACK_ERROR
+ if(!H5F_addr_defined(fh_addr))
+ FAIL_STACK_ERROR
+#ifndef QAK
+HDfprintf(stderr, "Fractal heap header address = %a\n", fh_addr);
+#endif /* QAK */
+
+ /*
+ * Test inserting mult. (small) objects to start second row in root indirect block
+ */
+ TESTING("inserting enough objects to fill second row of root indirect block");
+
+ /* Loop over filling direct blocks, until first root indirect row is full */
+ for(u = 0; u < STD_MAN_WIDTH; u++) {
+ /* Fill a direct heap block up */
+ if(fill_heap(f, dxpl, fh_addr, (hsize_t)(u + 1) * STD_MAN_START_BLOCK_SIZE, tot_nobjs, &nobjs))
+ FAIL_STACK_ERROR
+ tot_nobjs += nobjs;
+ } /* end for */
+
+ /* Loop over filling direct blocks, until second root indirect row is full */
+ for(u = 0; u < STD_MAN_WIDTH; u++) {
+ /* Fill a direct heap block up */
+ if(fill_heap(f, dxpl, fh_addr, (hsize_t)((STD_MAN_WIDTH * STD_MAN_START_BLOCK_SIZE) + (u + 1) * STD_MAN_START_BLOCK_SIZE), tot_nobjs, &nobjs))
+ FAIL_STACK_ERROR
+ tot_nobjs += nobjs;
+ } /* end for */
+
+ PASSED()
+
+ /* Close the file */
+ if(H5Fclose(file) < 0)
+ TEST_ERROR
+
+ /* All tests passed */
+ return(0);
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ } H5E_END_TRY;
+ return(1);
+} /* test_abs_fill_second_row() */
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Test the fractal heap code
@@ -1037,11 +1133,13 @@ main(void)
nerrors += test_abs_insert_fill_second(fapl);
nerrors += test_abs_insert_third_direct(fapl);
nerrors += test_abs_fill_first_row(fapl);
+ nerrors += test_abs_fill_first_row(fapl);
+ nerrors += test_abs_start_second_row(fapl);
#else /* QAK */
HDfprintf(stderr, "Uncomment tests!\n");
#endif /* QAK */
-#ifndef QAK
- nerrors += test_abs_start_second_row(fapl);
+#ifdef QAK
+ nerrors += test_abs_fill_second_row(fapl);
#else /* QAK */
HDfprintf(stderr, "Uncomment tests!\n");
#endif /* QAK */