1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: swmr_common.c
*
* Purpose: Utility functions for the SWMR test code.
*
*-------------------------------------------------------------------------
*/
/***********/
/* Headers */
/***********/
#include "h5test.h"
#include "swmr_common.h"
#include "vds_swmr.h"
/*******************/
/* Local Variables */
/*******************/
/* The SWMR data arrays:
*
* The code uses a 2-D jagged array of datasets. The first dimension is called
* the 'level' and there are five of them.
*
* #define NLEVELS 5
*
* The second dimension is the 'count' and there are quite a few datasets per
* 'level'.
*
* unsigned symbol_count[NLEVELS] = {100, 200, 400, 800, 1600};
*
* These datasets are created when the skeleton is generated and are initially
* empty. Each dataset has no upper bound on size (H5S_UNLIMITED). They
* are of compound type, with two members: an integer ID and an opaque
* 'data part'. The data part is not used by the SWMR testing.
*
* The SWMR testing will then randomly add and/or remove entries
* from these datasets. The selection of the level is skewed by a mapping
* table which preferentially hammers on the lower levels with their smaller
* number of datasets.
*
* static unsigned symbol_mapping[NMAPPING] = {0, 0, 0, 0, 1, 1, 2, 3, 4};
*
* The information about each dataset (name, hid_t, etc.) is stored in a
* separate array.
*
* symbol_info_t *symbol_info[NLEVELS];
*/
/* An array of dataset levels, used to select the level for a SWMR operation
* Note that this preferentially selects the lower levels with their smaller
* number of datasets.
*/
static unsigned symbol_mapping[NMAPPING] = {0, 0, 0, 0, 1, 1, 2, 3, 4};
/* The number of datasets at each level */
unsigned symbol_count[NLEVELS] = {100, 200, 400, 800, 1600};
/* Array of dataset information entries (1 per dataset) */
symbol_info_t *symbol_info[NLEVELS];
hsize_t PLANES[N_SOURCES][RANK] = {{1, SM_HEIGHT, WIDTH}, {1, LG_HEIGHT, WIDTH}, {1, SM_HEIGHT, WIDTH},
{1, LG_HEIGHT, WIDTH}, {1, SM_HEIGHT, WIDTH}, {1, LG_HEIGHT, WIDTH}};
char FILE_NAMES[N_SOURCES][NAME_LEN] = {{"vds_swmr_src_a.h5"}, {"vds_swmr_src_b.h5"}, {"vds_swmr_src_c.h5"},
{"vds_swmr_src_d.h5"}, {"vds_swmr_src_e.h5"}, {"vds_swmr_src_f.h5"}};
char VDS_FILE_NAME[NAME_LEN] = "vds_swmr.h5";
char SOURCE_DSET_PATH[NAME_LEN] = "/source_dset";
char VDS_DSET_NAME[NAME_LEN] = "vds_dset";
/*-------------------------------------------------------------------------
* Function: choose_dataset
*
* Purpose: Selects a random dataset in the SWMR file
*
* Parameters: N/A
*
* Return: Success: A pointer to information about a dataset.
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
symbol_info_t *
choose_dataset(void)
{
unsigned level; /* The level of the dataset */
unsigned offset; /* The "offset" of the dataset at that level */
/* Determine level of dataset */
level = symbol_mapping[HDrandom() % NMAPPING];
/* Determine the offset of the level */
offset = (unsigned)(HDrandom() % (int)symbol_count[level]);
return &symbol_info[level][offset];
} /* end choose_dataset() */
/*-------------------------------------------------------------------------
* Function: create_symbol_datatype
*
* Purpose: Create's the HDF5 datatype used for elements in the SWMR
* testing datasets.
*
* Parameters: N/A
*
* Return: Success: An HDF5 type ID
* Failure: -1
*
*-------------------------------------------------------------------------
*/
hid_t
create_symbol_datatype(void)
{
hid_t sym_type_id; /* Datatype ID for symbol */
hid_t opaq_type_id; /* Datatype ID for opaque part of record */
/* Create opaque datatype to represent other information for this record */
if ((opaq_type_id = H5Tcreate(H5T_OPAQUE, (size_t)DTYPE_SIZE)) < 0)
return -1;
/* Create compound datatype for symbol */
if ((sym_type_id = H5Tcreate(H5T_COMPOUND, sizeof(symbol_t))) < 0)
return -1;
/* Insert fields in symbol datatype */
if (H5Tinsert(sym_type_id, "rec_id", HOFFSET(symbol_t, rec_id), H5T_NATIVE_UINT64) < 0)
return -1;
if (H5Tinsert(sym_type_id, "info", HOFFSET(symbol_t, info), opaq_type_id) < 0)
return -1;
/* Close opaque datatype */
if (H5Tclose(opaq_type_id) < 0)
return -1;
return sym_type_id;
} /* end create_symbol_datatype() */
/*-------------------------------------------------------------------------
* Function: generate_name
*
* Purpose: Generates a SWMR testing dataset name given a level and
* count.
* The name is in the format <name>-<level> (%u-%04u).
*
* Parameters: char *name_buf
* Buffer for the created name. Must be pre-allocated.
* Since the name is formulaic, this isn't considered an issue.
*
* size_t name_buf_length
* The length in bytes of the name_buf buffer
*
* unsigned level
* The dataset's level
*
* unsigned count
* The dataset's count
*
* Return: Success: 0
*
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
int
generate_name(char *name_buf, size_t name_buf_length, unsigned level, unsigned count)
{
assert(name_buf);
snprintf(name_buf, name_buf_length, "%u-%04u", level, count);
return 0;
} /* end generate_name() */
/*-------------------------------------------------------------------------
* Function: generate_symbols
*
* Purpose: Initializes the global dataset information arrays.
*
* Parameters: N/A
*
* Return: Success: 0
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
int
generate_symbols(void)
{
unsigned u, v; /* Local index variables */
for (u = 0; u < NLEVELS; u++) {
symbol_info[u] = malloc(symbol_count[u] * sizeof(symbol_info_t));
for (v = 0; v < symbol_count[u]; v++) {
char name_buf[64];
generate_name(name_buf, sizeof(name_buf), u, v);
symbol_info[u][v].name = strdup(name_buf);
symbol_info[u][v].dsid = -1;
symbol_info[u][v].nrecords = 0;
} /* end for */
} /* end for */
return 0;
} /* end generate_symbols() */
/*-------------------------------------------------------------------------
* Function: shutdown_symbols
*
* Purpose: Cleans up the global dataset information arrays.
*
* Parameters: N/A
*
* Return: Success: 0
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
int
shutdown_symbols(void)
{
unsigned u, v; /* Local index variables */
/* Clean up the symbols */
for (u = 0; u < NLEVELS; u++) {
for (v = 0; v < symbol_count[u]; v++)
free(symbol_info[u][v].name);
free(symbol_info[u]);
} /* end for */
return 0;
} /* end shutdown_symbols() */
/*-------------------------------------------------------------------------
* Function: print_metadata_retries_info
*
* Purpose: To retrieve and print the collection of metadata retries for the file.
*
* Parameters: fid: the currently opened file identifier
*
* Return: Success: 0
* Failure: negative
*
*-------------------------------------------------------------------------
*/
int
print_metadata_retries_info(hid_t fid)
{
H5F_retry_info_t info;
unsigned i;
/* Retrieve the collection of retries */
if (H5Fget_metadata_read_retry_info(fid, &info) < 0)
return (-1);
/* Print information for each non-NULL retries[i] */
for (i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++) {
unsigned power;
unsigned j;
if (NULL == info.retries[i])
continue;
fprintf(stderr, "Metadata read retries for item %u:\n", i);
power = 1;
for (j = 0; j < info.nbins; j++) {
if (info.retries[i][j])
fprintf(stderr, "\t# of retries for %u - %u retries: %u\n", power, (power * 10) - 1,
info.retries[i][j]);
power *= 10;
} /* end for */
} /* end for */
/* Free memory for each non-NULL retries[i] */
for (i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
if (info.retries[i] != NULL)
H5free_memory(info.retries[i]);
return 0;
} /* print_metadata_retries_info() */
|