summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2008-03-05 07:06:08 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2008-03-05 07:06:08 (GMT)
commit406252cb102ab575e8fac6297f7ae63b4f34baeb (patch)
treeeb60a2f13e6714f133f5eb6f9c77874aea9f2381
parente37c539a9356b9f226ee8bd8f0b407f42cbdc96c (diff)
downloadhdf5-406252cb102ab575e8fac6297f7ae63b4f34baeb.zip
hdf5-406252cb102ab575e8fac6297f7ae63b4f34baeb.tar.gz
hdf5-406252cb102ab575e8fac6297f7ae63b4f34baeb.tar.bz2
[svn-r14708] Added ability to create both the crashed datafile and the non-crashed control
file. Also, writer() can generated different datasets as directed now. Tested: kagiso.
-rw-r--r--tools/h5recover/trecover.h22
-rw-r--r--tools/h5recover/trecover_main.c108
-rw-r--r--tools/h5recover/trecover_writer.c84
3 files changed, 173 insertions, 41 deletions
diff --git a/tools/h5recover/trecover.h b/tools/h5recover/trecover.h
index 6e96545..3c74dd4 100644
--- a/tools/h5recover/trecover.h
+++ b/tools/h5recover/trecover.h
@@ -30,6 +30,23 @@
#define AsyncCrash 1
#define CRASH crasher(SyncCrash, 0)
+/* Dataset properties */
+#define DSContig 0x1 /* Contigous type */
+#define DSChunked 0x2 /* Chunked type */
+#define DSZip 0x4 /* Zlib compressed */
+#define DSSZip 0x8 /* SZlib compressed */
+#define DSAll ~0x0 /* All datasets */
+#define DSNone 0x0 /* No datasets */
+
+/* Dataset default dimensions. Intentional small for easier dumping of data. */
+#define RANK 2
+#define NX 800 /* dataset dimensions */
+#define NY 16
+#define ChunkX 8 /* Dataset chunk sizes */
+#define ChunkY 8
+#define H5FILE_NAME "trecover.h5"
+#define CTL_H5FILE_NAME "CTL"H5FILE_NAME /* control file name */
+
/* Data Structures */
typedef union CrasherParam_t {
float tinterval; /* time interval to schedule an Async Crash */
@@ -39,11 +56,14 @@ typedef union CrasherParam_t {
/* Global variables */
extern CrasherParam_t AsyncCrashParam;
extern int CrashMode;
+extern hid_t file, ctl_file; /* file id and control file id*/
/* protocol definitions */
void crasher(int crash_mode, CrasherParam_t *crash_param);
-void writer(void);
+void writer(hid_t file, int dstype, int rank, hsize_t *dims, hsize_t *dimschunk);
void wakeup(int signum);
void parser(int ac, char **av); /* command option parser */
void init(void); /* initialization */
void help(void); /* initialization */
+int create_files(char *filename, char *ctl_filename);
+int close_file(hid_t fid);
diff --git a/tools/h5recover/trecover_main.c b/tools/h5recover/trecover_main.c
index a0283da..d8a0f5b 100644
--- a/tools/h5recover/trecover_main.c
+++ b/tools/h5recover/trecover_main.c
@@ -13,18 +13,29 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * This example writes data to the HDF5 file.
- * It creates three datasets, first one as a regular dataset, second one
- * uses gzip compression if supported, and the third one use szip compression
- * if supported.
+ * This is the Main body of the HDF5 Test program for the h5recover tool.
+ * It creates two HDF5 files, one as the Data file, the other the Control file.
+ * The two files are intended to contain identical data. The Control file will
+ * be completed with no error but the Data file, though written with the same
+ * data, is intentional crashed without proper file flush or close.
+ *
+ * (The two files are then verified by processes outside of this program.)
+ * The crashed Data file is restored by the h5recover tool and compared with
+ * the Control file, expecting identical file content up to the last successful
+ * file flush or close of the Data file.
*
* Creator: Albert Cheng, Jan 28, 2008.
*/
#include "trecover.h"
+/* Global variables */
CrasherParam_t AsyncCrashParam;
int CrashMode = SyncCrash; /* default to synchronous crash */
+hid_t file, ctl_file; /* file id and control file id*/
+
+/* local variables */
+static int DSTypes=DSNone; /* set to none first. */
/* Command arguments parser.
* -a <seconds> Do Async crash with a floating value of seconds
@@ -37,29 +48,70 @@ parser(int ac, char **av)
if (av[0][0] == '-'){
switch (av[0][1]){
case 'a': /* -a async option */
- ac--; av++;
- AsyncCrashParam.tinterval = atof(*av);
+ if (--ac > 0){
+ av++;
+ AsyncCrashParam.tinterval = atof(*av);
+ }else{
+ fprintf(stderr, "Missing async time value\n");
+ help();
+ exit(1);
+ }
+ break;
+ case 'd': /* -d dataset type */
+ if (--ac > 0){
+ av++;
+ switch (**av){
+ case 'C':
+ DSTypes=DSTypes|DSContig;
+ break;
+ case 'K':
+ DSTypes=DSTypes|DSChunked;
+ break;
+ case 'G':
+ DSTypes=DSTypes|DSZip;
+ break;
+ case 'S':
+ DSTypes=DSTypes|DSSZip;
+ break;
+ case 'A':
+ DSTypes=DSTypes|DSAll;
+ break;
+ default:
+ fprintf(stderr, "Unknown Dataset type (%c)\n", **av);
+ help();
+ exit(1);
+ }
+ }else{
+ fprintf(stderr, "Missing async time value\n");
+ help();
+ exit(1);
+ }
break;
case 'h': /* -h help option */
help();
+ exit(0);
break;
default:
fprintf(stderr, "Unknown command option(%s)\n", *av);
help();
- return;
+ exit(1);
}
}else{
fprintf(stderr, "Unknown command option(%s)\n", *av);
help();
- return;
+ exit(1);
}
} /* end of while */
+ if (DSTypes==DSNone){
+ /* reset to default all datasets */
+ DSTypes=DSAll;
+ }
}
/* initialization */
void
-init()
+init(void)
{
AsyncCrashParam.tinterval = 0;
}
@@ -67,18 +119,50 @@ init()
/* show help pages */
void
-help()
+help(void)
{
- fprintf(stderr, "Usage: trecover [-a <seconds>]\n");
+ fprintf(stderr, "Usage: trecover [-a <seconds>] [-d <dataset-type>] [-h]\n"
+ "\t-a\tAsync crash seconds where <seconds> is a real number.\n"
+ "\t-d\tDataset to create. <dataset-type> can be:\n"
+ "\t\t A\tAll datasets\n"
+ "\t\t C\tContingous datasets\n"
+ "\t\t G\tGzip compressed datasets\n"
+ "\t\t K\tChunked datasets\n"
+ "\t\t S\tSzip compressed datasets\n"
+ "\t\tDefault is all datasets\n"
+ );
}
int
main (int ac, char **av)
{
+ hsize_t dims[RANK]={NX,NY}; /* dataset dimensions */
+ hsize_t dimschunk[RANK]={ChunkX,ChunkY}; /* dataset chunk dimensions */
+
init();
parser(ac, av);
+
+ /* create/open both files. */
+ create_files(H5FILE_NAME, CTL_H5FILE_NAME);
+
+ /* create datasets in Control file first. */
+ writer(ctl_file, DSTypes, RANK, dims, dimschunk);
+ close_file(ctl_file);
+
+ /* Schedule Async crash if requested. */
if (AsyncCrashParam.tinterval > 0)
crasher(AsyncCrash, &AsyncCrashParam);
- writer();
+
+ /* create datasets in data file. */
+ writer(file, DSTypes, RANK, dims, dimschunk);
+
+ /* Do a sync crash. */
+ if (AsyncCrashParam.tinterval == 0)
+ CRASH;
+
+ /* Close file only if Async crash is scheduled but has not occurred yet. */
+ close_file(file);
+
+ return(0);
}
diff --git a/tools/h5recover/trecover_writer.c b/tools/h5recover/trecover_writer.c
index 4154953..4ffca7c 100644
--- a/tools/h5recover/trecover_writer.c
+++ b/tools/h5recover/trecover_writer.c
@@ -20,24 +20,34 @@
#include "trecover.h"
-#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "IntArray"
+#define CHUNKDATASETNAME "IntArrayChunked"
#define ZDATASETNAME "IntArrayZCompressed"
#define SZDATASETNAME "IntArraySZCompressed"
-/* Dataset dimensions. Intentional small for easier dumping of data. */
-#define RANK 2
-#define NX 8000 /* dataset dimensions */
-#define NY 16
-#define ChunkX 8 /* Dataset chunk sizes */
-#define ChunkY 8
+
+int
+create_files(char *filename, char *ctl_filename)
+{
+ /*
+ * Create a new file and the control file using H5F_ACC_TRUNC access,
+ * default file creation properties, and default file
+ * access properties.
+ */
+ file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ ctl_file = H5Fcreate(ctl_filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+}
+
+int
+close_file(hid_t fid)
+{
+ H5Fclose(fid);
+}
void
-writer(void)
+writer(hid_t file, int dstype, int rank, hsize_t *dims, hsize_t *dimschunk)
{
- hid_t file, dataset; /* file and dataset handles */
+ hid_t dataset; /* dataset handle */
hid_t datatype, dataspace, plist; /* handles */
- hsize_t dims[RANK]={NX,NY}; /* dataset dimensions */
- hsize_t dimschunk[RANK]={ChunkX,ChunkY}; /* dataset chunk dimensions */
herr_t status;
int data[NX][NY]; /* data to write */
int i, j;
@@ -51,13 +61,6 @@ writer(void)
}
/*
- * Create a new file using H5F_ACC_TRUNC access,
- * default file creation properties, and default file
- * access properties.
- */
- file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
@@ -70,6 +73,7 @@ writer(void)
datatype = H5Tcopy(H5T_NATIVE_INT);
status = H5Tset_order(datatype, H5T_ORDER_LE);
+ if (dstype & DSContig) {
/* =============================================================
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
@@ -83,13 +87,37 @@ writer(void)
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
- CRASH;
/*
* Close/release resources.
*/
H5Dclose(dataset);
printf("%s created.\n", DATASETNAME);
+ }
+
+ if (dstype & DSChunked) {
+ /* =============================================================
+ * Create a new dataset within the file using defined dataspace and
+ * datatype and default dataset creation properties.
+ * =============================================================
+ */
+ plist = H5Pcreate(H5P_DATASET_CREATE);
+ H5Pset_chunk(plist, RANK, dimschunk);
+ dataset = H5Dcreate(file, CHUNKDATASETNAME, H5T_NATIVE_INT,
+ dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
+ /*
+ * Write the data to the dataset using default transfer properties.
+ */
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, data);
+ /*
+ * Close/release resources.
+ */
+ H5Pclose(plist);
+ H5Dclose(dataset);
+ printf("%s created.\n", CHUNKDATASETNAME);
+ }
+ if (dstype & DSZip){
#ifdef H5_HAVE_FILTER_DEFLATE
/* =============================================================
* Create similar dataset but using Zlib compression.
@@ -102,7 +130,7 @@ writer(void)
H5Pset_chunk(plist, RANK, dimschunk);
H5Pset_deflate( plist, 6);
dataset = H5Dcreate(file, ZDATASETNAME, H5T_NATIVE_INT,
- dataspace, plist, H5P_DEFAULT, H5P_DEFAULT);
+ dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
@@ -116,7 +144,9 @@ writer(void)
printf("%s is not created because of no GZIP (deflate) support.\n",
ZDATASETNAME);
#endif
+ }
+ if (dstype & DSSZip){
#ifdef H5_HAVE_FILTER_SZIP
/* =============================================================
* Create similar dataset but using SZLIB compression.
@@ -129,7 +159,7 @@ writer(void)
H5Pset_chunk(plist, RANK, dimschunk);
H5Pset_szip (plist, H5_SZIP_NN_OPTION_MASK, 8);
dataset = H5Dcreate(file, SZDATASETNAME, H5T_NATIVE_INT,
- dataspace, plist, H5P_DEFAULT, H5P_DEFAULT);
+ dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
@@ -143,17 +173,15 @@ writer(void)
printf("%s is not created because of no SZIP encode support.\n",
SZDATASETNAME);
#endif
+ }
- /*
- * Close/release resources.
+
+
+ /*
+ * All done, close/release resources.
*/
H5Sclose(dataspace);
H5Tclose(datatype);
- /* Close the file */
- H5Fclose(file);
-
- printf("HDF5 C Sample program ran successfully. File %s generated.\n", H5FILE_NAME);
-
return;
}