hdf5/test/swmr_generator.c
Quincey Koziol a2524671ca
Bring async branch to develop (#166)
* Add H5Fwait, H5Dwait, and other changes for async vol connector

* Revert temporary testing changes

* Add H5Fwait to header file

* Add H5VLreset_lib_state() routine.

* Correct VOL wrap context when retrieving library state for file open & create.

* Manage the API context's VOL connector state as part of the library state.

* Set the 'VOL connector property valid' flag when restoring the library state.

* Don't push new API context on stack when retrieving "current" one.

* Check for NULL VOL wrap context before decrementing refcount on it, when
freeing the API context state.

* Manage recount of underlying connector for VOL wrap context.

* Add H5TSmutex_acquire() and H5TSmutex_release() routines to acquire and
release the global lock on the HDF5 library.

* Update library with new functions related to library global lock

* Add asynchronous token API

* Add new lightweight FUNC_ENTER / LEAVE macros for helping to structure the
threadsafety (H5TS*) routines.

* Sync w/develop

* Initial event set code framework.

* Elaborate on the H5ES routines, starting to add API routines.

Update the "close ID" callbacks to allow asynchronous request tokens to be
passed in from an asynchronous close API call.

Refactor current asynchronous API routines (H5Fopen/H5Fclose and
H5Dread/H5Dread) to use event sets instead of directly working with request
tokens from the application.

Clean up a few other minor warnings & code style issues.

* Implement H5EScreate, H5ESget_count, and H5ESclose.

It should be possible to write a simple application that creates an event
set and uses it with H5Fopen_async, H5Dread_async, H5Dwrite_async, and
H5Fclose_async, then calls H5ESclose (which waits for all async events to
complete).

* Add source file for event set test.

* Refactor sync & async API routines to call common routine.

Move dataset API read / write routines to src/H5D.c, along with all the other
API routines.

Progress on "fake" async VOL connector, for testing.

* Modify async implementation to wrap async requests in a H5VL_object_t
struct so the VOL layer can find the connector when accessing the
request at a later point.

* Free the requests is H5ESclose.  Remove comments implying that request
wait, notify, and cancel callbacks should free the request.

* Fix bug in error handling in H5Fclose.

* Fix bugs in async file routines.  Rename H5VL_create_object_generic to
H5VL_create_object.

* Add explicit async version of H5Fcreate.

* Add more _async routines

* Correct typo for return value from H5Awrite changes

* Add H5EStest and H5ESwait routines

* Updated with API tracing info

* Fix NULL pointer dereference in H5ES__wait

* Add H5is_library_terminating() routine, so that VOL connectors can detect
when the library is shutting down.

* Fix typo

* Remove event from event set's linked list

* Move block of code so that vol_obj is valid

* Avoid setting properties in the DXPL when reseting the library state (and in
the test code).

* Refactor argument tracing to implement new capability for tracing arguments
of non-API routines, with the H5ARG_TRACE macro.   This macro is updated
automatically with the bin/trace script that runs as part of the autogen.sh
process.   Major changes were in src/H5trace.c and bin/trace, with the other
changes being cleanups to the argument lists, to improve their presentation
in the tracing output.

Also - added the "managed string" routines, which can dynamically allocate
strings, appending printf-formatted output to the string efficiently.

* Release memory for managed strings

* Fix printf() formats.

* More printf() format fixes.

* Add H5Eappend_stack routine and regression tests

* Clean up a few missed merge conflicts and update the error stacks.

* Remove unnecessary fork() operations and ten second sleep().

* Restore commented out attribute out, to better enable tracking down the previous failure

* Allow multiple H5ARG_TRACE macros within a routine to be updated

* Switch to using "new" H5ES_insert (which takes the arguments for the caller routine) for all event set operations.  Renames H5ES_insert_new to H5ES_insert and removes the previous H5ES_insert.

* Merge "managed" string routines into "ref-counted" strings, and refactor code to use them.

* Add missing file.

* Add caller's name and arguments to event, for error reporting

* Refactor event set setup for "API common" internal routines

* Checkin async API routines for H5A* and H5G* modules as listed in ID-283.
Fix couple h5dump expected output files due to the changes.

* Add some of the error query routines needed for event sets.

* Refactor to make async setup / teardown and "common" routines cleaner

* (1) Add async APIs to H5L, H5F, and H5D modules
(2) Fix errors in previous checkins of async APIs in H5A and H5G modules
(3) h5dump expected output changes

* Enhance event info, for better error handling

* Change name of temporary vol_obj variable, to help reduce coding errors

* Fix oversight with vol_obj pointer

* Minor code cleanup

* Add missing \'valid\' flag for VOL wrapper context, when restoring the library\'s state

* Run source formatter

* Change H5TSmutex lock and release to include a lock count

* Update error reporting ideas

* Minor updates to improve sanity checking for retrieving / restoring library state

* Updated with feedback from h5py team members

* Refactor internal event set list and event handling, add implementation for H5ESget_err_info

* Change the VOL request subclass callbacks that switch from using "H5ES_status_t" to "H5VL_request_status_t", and also add a H5VL_request_status_t* parameter to the 'cancel' callback in the request subclass.  Also more code quality cleanups to add iterator callbacks to internal event set routines.

* Update API tracing for new H5VL_request_status_t typedef

* Finish converting internal event set operations to use list iterator callbacks, instead of directly accessing the list structure

* Add H5VL_REQUEST_GET_ERR_STACK operation to request subclass, for retrieving a copy of the error stack for a failed asynchronous operation

* Remove 'canceled' event status from Java constants

* Be safer about releasing resources when inserting a newly opened/created object or file into an event set

* Remove H5EStest, add H5ES_WAIT_NONE for 0 timeout, and revise parameters to H5ESwait, to make it more "aggregate".

* Remove H5ES_STATUS_CANCELED from Java wrappers also

* (a) Add async APIs for H5O module as listed in jira issue ID-283.
(b) Remove verification of name parameter in async related routines for H55A and H5L modules
    because it is checked in H5VL_setup* routine.
(c) Modify h5dump expected output due to the async changes.

* Corrections based on PR feedback.

* Further changes to make based on PR feedback.

* Fix missed merge marker, and reformatted line

* Clean up some warnings

* Correct level of indirection

* Relocate prototype (and doxygen info) for H5Aclose

* Change non-static function declarations to be static

* Ensure that H5TSpublic.h header gets installed (#129)

* Add 'wrapper' versions of async calls, to allow language wrappers and layers on top of HDF5 to pass in their application information.

* Switch H5Aexists\*_async and H5Lexists\*_async to use flag to return status, instead of return value.  Make the corresponding changes through most of the v1 and v2 B-tree code.  Clean up warnings in H5public.h and cmpd_dtransform.c.

* Add H5Iregister_future routine and tests.

* Correct return value for H5Lexists_async

* Add H5_DLL macro to public H5ES API routines

* Update supported -> flags parameter for introspect_query callback

* Remove my email address.  Update passthrough VOL connector ID.

* Fix comment for post_open_api_common

* Remove unused non-blocking VOL connector

* Minor cleanup in async branch in preparation for merge to develop

* Update CMake and the Autotools to use the new pass-through VOL ID

* Fix for SWMR daily test failures (#160)

The H5I_register_using_existing_id() call did not initialize the future
ID callbacks, causing the library to segfault when it tried to
resolve those function pointers.

* Added selective async APIs (#150)

* Added selective async APIs

Description:
    Added the following APIs:
        H5Ropen_attr_async
        H5Ropen_object_async
        H5Ropen_region_async

        H5Mcreate_async
        H5Mopen_async
        H5Mput_async
        H5Mget_async
        H5Mclose_async

        H5Tcommit_async
        H5Topen_async
        H5Tcopy_async
        H5Tclose_async
    - Updated an expected output file to include a new internal function
      in the error stack for the failure case.

* Updated async APIs per reviews, including removing async version of
H5Tcopy.

* Removed statements that were added by mistake in the previous commit.

* Fix compile issues in H5M and warnings elsewhere

* Reformat code

* Brings VOL_LIST changes from develop. (#163)

Co-authored-by: Houjun Tang <htang4@lbl.gov>
Co-authored-by: Neil Fortner <nfortne2@hdfgroup.org>
Co-authored-by: vchoi <vchoi@jelly.ad.hdfgroup.org>
Co-authored-by: vchoi-hdfgroup <55293060+vchoi-hdfgroup@users.noreply.github.com>
Co-authored-by: jhendersonHDF <jhenderson@hdfgroup.org>
Co-authored-by: Dana Robinson <derobins@hdfgroup.org>
Co-authored-by: Dana Robinson <43805+derobins@users.noreply.github.com>
Co-authored-by: bmribler <39579120+bmribler@users.noreply.github.com>
2020-12-13 18:02:17 -06:00

356 lines
13 KiB
C

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: swmr_generator.c
*
* Purpose: Functions for building and setting up the SWMR test file
* and datasets.
*
*-------------------------------------------------------------------------
*/
/***********/
/* Headers */
/***********/
#include "h5test.h"
#include "swmr_common.h"
/*
* This file needs to access testing codefrom the H5O package.
*/
#define H5O_FRIEND /*suppress error about including H5Opkg */
#define H5O_TESTING
#include "H5Opkg.h" /* Object headers */
/****************/
/* Local Macros */
/****************/
#define CHUNK_SIZE 50 /* Chunk size for created datasets */
/********************/
/* Local Prototypes */
/********************/
static int gen_skeleton(const char *filename, hbool_t verbose, hbool_t swmr_write, int comp_level,
const char *index_type, unsigned random_seed);
static void usage(void);
/*-------------------------------------------------------------------------
* Function: gen_skeleton
*
* Purpose: Creates the HDF5 file and datasets which will be used in
* the SWMR testing.
*
* Parameters: const char *filename
* The SWMR test file's name.
*
* hbool_t verbose
* Whether verbose console output is desired.
*
* hbool_t swmr_write
* Whether to create the file with SWMR writing enabled
*
* int comp_level
* The zlib compression level to use. -1 = no compression.
*
* const char *index_type
* The chunk index type (b1 | b2 | ea | fa)
*
* unsigned random_seed
* The random seed to store in the file. The sparse tests use
* this value.
*
* Return: Success: 0
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
static int
gen_skeleton(const char *filename, hbool_t verbose, hbool_t swmr_write, int comp_level,
const char *index_type, unsigned random_seed)
{
hid_t fid; /* File ID for new HDF5 file */
hid_t fcpl; /* File creation property list */
hid_t fapl; /* File access property list */
hid_t dcpl; /* Dataset creation property list */
hid_t tid; /* Datatype for dataset elements */
hid_t sid; /* Dataspace ID */
hid_t aid; /* Attribute ID */
hsize_t dims[2] = {1, 0}; /* Dataset starting dimensions */
hsize_t max_dims[2] = {1, H5S_UNLIMITED}; /* Dataset maximum dimensions */
hsize_t chunk_dims[2] = {1, CHUNK_SIZE}; /* Chunk dimensions */
#ifdef FILLVAL_WORKS
symbol_t fillval; /* Dataset fill value */
#endif /* FILLVAL_WORKS */
unsigned u, v; /* Local index variable */
HDassert(filename);
HDassert(index_type);
/* Create file access property list */
if ((fapl = h5_fileaccess()) < 0)
return -1;
/* Can create a file for SWMR support with: (a) (write+latest-format) or (b) (SWMR
* write+non-latest-format) */
if (!swmr_write) {
if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
return -1;
}
/* There are two chunk indexes tested here.
* With one unlimited dimension, we get the extensible array index
* type, with two unlimited dimensions, we get a v2 B-tree.
*/
if (!HDstrcmp(index_type, "b2"))
max_dims[0] = H5S_UNLIMITED;
/* Create file creation property list */
if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
return -1;
/* Emit informational message */
if (verbose)
HDfprintf(stderr, "Creating file\n");
/* Create the file */
if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC | (swmr_write ? H5F_ACC_SWMR_WRITE : 0), fcpl, fapl)) < 0)
return -1;
/* Close file creation property list */
if (H5Pclose(fcpl) < 0)
return -1;
/* Close file access property list */
if (H5Pclose(fapl) < 0)
return -1;
/* Create attribute with (shared) random number seed - for sparse test */
if ((sid = H5Screate(H5S_SCALAR)) < 0)
return -1;
if ((aid = H5Acreate2(fid, "seed", H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
return -1;
if (H5Awrite(aid, H5T_NATIVE_UINT, &random_seed) < 0)
return -1;
if (H5Sclose(sid) < 0)
return -1;
/* Create datatype for creating datasets */
if ((tid = create_symbol_datatype()) < 0)
return -1;
/* Create dataspace for creating datasets */
if ((sid = H5Screate_simple(2, dims, max_dims)) < 0)
return -1;
/* Create dataset creation property list */
if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
return -1;
if (H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
return -1;
if (comp_level >= 0) {
if (H5Pset_deflate(dcpl, (unsigned)comp_level) < 0)
return -1;
} /* end if */
#ifdef FILLVAL_WORKS
/* Currently fill values do not work because they can bump the dataspace
* message to the second object header chunk. We should enable the fillval
* here when this is fixed. -NAF 8/11/11 */
HDmemset(&fillval, 0, sizeof(fillval));
fillval.rec_id = (uint64_t)ULLONG_MAX;
if (H5Pset_fill_value(dcpl, tid, &fillval) < 0)
return -1;
#endif /* FILLVAL_WORKS */
/* Emit informational message */
if (verbose)
HDfprintf(stderr, "Creating datasets\n");
/* Create the datasets */
for (u = 0; u < NLEVELS; u++)
for (v = 0; v < symbol_count[u]; v++) {
hid_t dsid; /* Dataset ID */
char name_buf[64];
hbool_t move_dataspace_message =
FALSE; /* Whether to move the dataspace message out of object header chunk #0 */
generate_name(name_buf, u, v);
if ((dsid = H5Dcreate2(fid, name_buf, tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
return -1;
/* Determine if the dataspace message for this dataset should be
* moved out of chunk #0 of the object header
* (Set to TRUE for every fourth dataset)
*/
move_dataspace_message = !(HDrandom() % 4);
if (move_dataspace_message) {
unsigned chunk_num; /* Object header chunk # for dataspace message */
/* Move the dataspace message to a new object header chunk */
if (H5O__msg_move_to_new_chunk_test(dsid, H5O_SDSPACE_ID) < 0)
return -1;
/* Retrieve the chunk # for the dataspace message */
chunk_num = UINT_MAX;
if (H5O__msg_get_chunkno_test(dsid, H5O_SDSPACE_ID, &chunk_num) < 0)
return -1;
/* Should not be in chunk #0 for now */
if (0 == chunk_num)
return -1;
} /* end if */
if (H5Dclose(dsid) < 0)
return -1;
} /* end for */
/* Emit informational message */
if (verbose)
HDfprintf(stderr, "Closing objects\n");
/* Close everythign */
if (H5Pclose(dcpl) < 0)
return -1;
if (H5Sclose(sid) < 0)
return -1;
if (H5Tclose(tid) < 0)
return -1;
if (H5Fclose(fid) < 0)
return -1;
return 0;
} /* end gen_skeleton() */
static void
usage(void)
{
HDprintf("\n");
HDprintf("Usage error!\n");
HDprintf("\n");
HDprintf("Usage: swmr_generator [-q] [-s] [-c <deflate compression level>]\n");
HDprintf(" [-i <index type>] [-r <random seed>]\n");
HDprintf("\n");
HDprintf("NOTE: The random seed option is only used by the sparse test. Other\n");
HDprintf(" tests specify the random seed as a reader/writer option.\n");
HDprintf("\n");
HDprintf("<deflate compression level> should be -1 (for no compression) or 0-9\n");
HDprintf("\n");
HDprintf("<index type> should be b2 or ea\n");
HDprintf("\n");
HDprintf("Defaults to verbose (no '-q' given), no SWMR_WRITE mode (no '-s' given) no\n");
HDprintf("compression ('-c -1'), v1 b-tree indexing (-i b1), and will generate a random\n");
HDprintf("seed (no -r given).\n");
HDprintf("\n");
HDexit(EXIT_FAILURE);
} /* end usage() */
int
main(int argc, const char *argv[])
{
int comp_level = -1; /* Compression level (-1 is no compression) */
hbool_t verbose = TRUE; /* Whether to emit some informational messages */
hbool_t swmr_write = FALSE; /* Whether to create file with SWMR_WRITE access */
const char *index_type = "b1"; /* Chunk index type */
hbool_t use_seed = FALSE; /* Set to TRUE if a seed was set on the command line */
unsigned random_seed = 0; /* Random # seed */
unsigned u; /* Local index variables */
int temp;
/* Parse command line options */
if (argc > 1) {
u = 1;
while (u < (unsigned)argc) {
if (argv[u][0] == '-') {
switch (argv[u][1]) {
/* Compress dataset chunks */
case 'c':
comp_level = HDatoi(argv[u + 1]);
if (comp_level < -1 || comp_level > 9)
usage();
u += 2;
break;
/* Chunk index type */
case 'i':
index_type = argv[u + 1];
if (HDstrcmp(index_type, "ea") && HDstrcmp(index_type, "b2"))
usage();
u += 2;
break;
/* Random # seed */
case 'r':
use_seed = TRUE;
temp = HDatoi(argv[u + 1]);
if (temp < 0)
usage();
else
random_seed = (unsigned)temp;
u += 2;
break;
/* Be quiet */
case 'q':
verbose = FALSE;
u++;
break;
/* Run with SWMR_WRITE */
case 's':
swmr_write = TRUE;
u++;
break;
default:
usage();
break;
} /* end switch */
} /* end if */
} /* end while */
} /* end if */
/* Emit informational message */
if (verbose) {
HDfprintf(stderr, "Parameters:\n");
HDfprintf(stderr, "\tswmr writes %s\n", swmr_write ? "on" : "off");
HDfprintf(stderr, "\tcompression level = %d\n", comp_level);
HDfprintf(stderr, "\tindex type = %s\n", index_type);
} /* end if */
/* Set the random seed */
if (!use_seed) {
struct timeval t;
HDgettimeofday(&t, NULL);
random_seed = (unsigned)(t.tv_usec);
} /* end if */
HDsrandom(random_seed);
/* ALWAYS emit the random seed for possible debugging */
HDfprintf(stderr, "Using generator random seed (used in sparse test only): %u\n", random_seed);
/* Emit informational message */
if (verbose)
HDfprintf(stderr, "Generating skeleton file: %s\n", FILENAME);
/* Generate file skeleton */
if (gen_skeleton(FILENAME, verbose, swmr_write, comp_level, index_type, random_seed) < 0) {
HDfprintf(stderr, "Error generating skeleton file!\n");
HDexit(EXIT_FAILURE);
} /* end if */
return 0;
}