int load_state(long sf, long procs, long step) { FILE *ufp; int i; char fname[256]; char line[1024]; if (sf == 0 || step == 0) return(0); seed_name(line, sf, procs, step); sprintf(fname, "%s%c%s", env_config(SEED_TAG, SEED_DFLT), PATH_SEP, line); ufp = fopen(fname, "r"); OPEN_CHECK(ufp, fname); for (i=0; i <= MAX_STREAM; i++ ) if (fscanf(ufp, "%ld\n", Seed + i) != 1) return(MAX_STREAM); fclose(ufp); return(0); }
FILE * print_prep(int table, int update) { char upath[128]; FILE *res; if (updates) { if (update > 0) /* updates */ if ( insert_segments ) { int this_segment; if(strcmp(tdefs[table].name,"orders.tbl")) this_segment=++insert_orders_segment; else this_segment=++insert_lineitem_segment; sprintf(upath, "%s%c%s.u%d.%d", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, tdefs[table].name, update%10000,this_segment); } else { sprintf(upath, "%s%c%s.u%d", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, tdefs[table].name, update); } else /* deletes */ if ( delete_segments ) { ++delete_segment; sprintf(upath, "%s%cdelete.u%d.%d", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, -update%10000, delete_segment); } else { sprintf(upath, "%s%cdelete.%d", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, -update); } return(fopen(upath, "w")); } res = tbl_open(table, "w"); OPEN_CHECK(res, tdefs[table].name); return(res); }
FILE * tbl_open(int tbl, char *mode) { char prompt[256]; char fullpath[256]; FILE *f; struct stat fstats; int retcode; if (*tdefs[tbl].name == PATH_SEP) strcpy(fullpath, tdefs[tbl].name); else sprintf(fullpath, "%s%c%s", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, tdefs[tbl].name); retcode = stat(fullpath, &fstats); if (retcode && (errno != ENOENT)) { fprintf(stderr, "stat(%s) failed.\n", fullpath); exit(-1); } if (S_ISREG(fstats.st_mode) && !force && *mode != 'r' ) { sprintf(prompt, "Do you want to overwrite %s ?", fullpath); if (!yes_no(prompt)) exit(0); } if (S_ISFIFO(fstats.st_mode)) { retcode = open(fullpath, ((*mode == 'r')?O_RDONLY:O_WRONLY)|O_CREAT); f = fdopen(retcode, mode); } else{ #ifdef LINUX /* allow large files on Linux */ /*use open to first to get the in fd and apply regular fdopen*/ /*cheng: Betty mentioned about write mode problem here, added 066*/ retcode = open(fullpath, ((*mode == 'r')?O_RDONLY:O_WRONLY)|O_CREAT|O_LARGEFILE,0644); f = fdopen(retcode, mode); #else f = fopen(fullpath, mode); #endif } OPEN_CHECK(f, fullpath); if (header && columnar && tdefs[tbl].header != NULL) tdefs[tbl].header(f); return (f); }
FILE * tbl_open(int tbl, char *mode) { char prompt[256]; char fullpath[256]; #ifdef MYRIAD_NO_OUTPUT strcpy(fullpath, "/dev/null"); #endif /* MYRIAD_NO_OUTPUT */ FILE *f; struct stat fstats; int retcode; // DO NOT CREATE FILES FOR THE TABLES #ifndef MYRIAD_NO_OUTPUT if (*tdefs[tbl].name == PATH_SEP) strcpy(fullpath, tdefs[tbl].name); else sprintf(fullpath, "%s%c%s", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, tdefs[tbl].name); #endif /* MYRIAD_NO_OUTPUT */ retcode = stat(fullpath, &fstats); if (retcode) { if (errno != ENOENT) { fprintf(stderr, "stat(%s) failed.\n", fullpath); exit(-1); } else f = fopen(fullpath, mode); // create and open the file } else { /* note this code asumes we are writing but tests if mode == r -jrg */ if (S_ISREG(fstats.st_mode) && !force && *mode != 'r' ) { sprintf(prompt, "Do you want to overwrite %s ?", fullpath); if (!yes_no(prompt)) exit(0); f = fopen(fullpath, mode); } else if (S_ISFIFO(fstats.st_mode)) { retcode = open(fullpath, ((*mode == 'r')?O_RDONLY:O_WRONLY)|O_CREAT, 0664); f = fdopen(retcode, mode); } else f = fopen(fullpath, mode); } OPEN_CHECK(f, fullpath); return (f); }
FILE * tbl_open(int tbl, char *mode) { /* char prompt[256]; */ char fullpath[256]; FILE *f; struct stat fstats; int retcode; if (*tdefs[tbl].name == PATH_SEP) strcpy(fullpath, tdefs[tbl].name); else sprintf(fullpath, "%s%c%s", env_config(PATH_TAG, PATH_DFLT), PATH_SEP, tdefs[tbl].name); retcode = stat(fullpath, &fstats); if (retcode && (errno != ENOENT)) { fprintf(stderr, "stat(%s) failed.\n", fullpath); exit(-1); } /*if (S_ISREG(fstats.st_mode) && !force && *mode != 'r' ) { sprintf(prompt, "Do you want to overwrite %s ?", fullpath); if (!yes_no(prompt)) exit(0); } */ if (S_ISFIFO(fstats.st_mode)) { f = fopen(fullpath, mode); } else { retcode = open(fullpath, ((*mode == 'r')?O_RDONLY:O_WRONLY)|O_CREAT, 0664); f = fdopen(retcode, mode); } OPEN_CHECK(f, fullpath); if (header && columnar && tdefs[tbl].header != NULL) tdefs[tbl].header(f); return (f); }
/* * store_state() -- store the data set configuration details so that * appropriate update sets can be generated */ int store_state(long sf, long procs, long step) { FILE *ufp; int i; char fname[256], seed[9]; seed_name(seed, sf, procs, step); sprintf(fname, "%s%c%s", env_config(SEED_TAG, SEED_DFLT), PATH_SEP, seed); ufp = fopen(fname, "w"); OPEN_CHECK(ufp, fname); for (i=0; i <= MAX_STREAM; i++) if (fprintf(ufp, "%ld\n ", Seed[i]) == EOF) return(1); fclose(ufp); return(0); }
/* * load a distribution from a flat file into the target structure; * should be rewritten to allow multiple dists in a file */ void read_dist(char *path, char *name, distribution *target) { FILE *fp; char line[256], token[256], *c; long weight, count = 0, name_set = 0; if (d_path == NULL) { sprintf(line, "%s%c%s", env_config(CONFIG_TAG, CONFIG_DFLT), PATH_SEP, path); fp = fopen(line, "r"); OPEN_CHECK(fp, line); } else { fp = fopen(d_path, "r"); OPEN_CHECK(fp, d_path); } while (fgets(line, sizeof(line), fp) != NULL) { if ((c = strchr(line, '\n')) != NULL) *c = '\0'; if ((c = strchr(line, '#')) != NULL) *c = '\0'; if (*line == '\0') continue; if (!name_set) { if (dsscasecmp(strtok(line, "\n\t "), "BEGIN")) continue; if (dsscasecmp(strtok(NULL, "\n\t "), name)) continue; name_set = 1; continue; } else { if (!dssncasecmp(line, "END", 3)) { fclose(fp); return; } } if (sscanf(line, "%[^|]|%ld", token, &weight) != 2) continue; if (!dsscasecmp(token, "count")) { target->count = weight; target->list = (set_member *) malloc((size_t)(weight * sizeof(set_member))); MALLOC_CHECK(target->list); target->max = 0; continue; } target->list[count].text = (char *) malloc((size_t)(strlen(token) + 1)); MALLOC_CHECK(target->list[count].text); strcpy(target->list[count].text, token); target->max += weight; target->list[count].weight = target->max; count += 1; } /* while fgets() */ if (count != target->count) { fprintf(stderr, "Read error on dist '%s'\n", name); fclose(fp); exit(1); } target->permute = (long *)NULL; fclose(fp); return; }
/* * read the distributions needed in the benchamrk */ void load_dists (void) { read_dist (env_config (DIST_TAG, DIST_DFLT), "p_cntr", &p_cntr_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "colors", &colors); read_dist (env_config (DIST_TAG, DIST_DFLT), "p_types", &p_types_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "nations", &nations); read_dist (env_config (DIST_TAG, DIST_DFLT), "regions", ®ions); read_dist (env_config (DIST_TAG, DIST_DFLT), "o_oprio", &o_priority_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "instruct", &l_instruct_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "smode", &l_smode_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "category", &l_category_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "rflag", &l_rflag_set); read_dist (env_config (DIST_TAG, DIST_DFLT), "msegmnt", &c_mseg_set); /* load the distributions that contain text generation */ read_dist (env_config (DIST_TAG, DIST_DFLT), "nouns", &nouns); read_dist (env_config (DIST_TAG, DIST_DFLT), "verbs", &verbs); read_dist (env_config (DIST_TAG, DIST_DFLT), "adjectives", &adjectives); read_dist (env_config (DIST_TAG, DIST_DFLT), "adverbs", &adverbs); read_dist (env_config (DIST_TAG, DIST_DFLT), "auxillaries", &auxillaries); read_dist (env_config (DIST_TAG, DIST_DFLT), "terminators", &terminators); read_dist (env_config (DIST_TAG, DIST_DFLT), "articles", &articles); read_dist (env_config (DIST_TAG, DIST_DFLT), "prepositions", &prepositions); read_dist (env_config (DIST_TAG, DIST_DFLT), "grammar", &grammar); read_dist (env_config (DIST_TAG, DIST_DFLT), "np", &np); read_dist (env_config (DIST_TAG, DIST_DFLT), "vp", &vp); }
int setup(void) { asc_date = mk_ascdate(); read_dist(env_config(DIST_TAG, DIST_DFLT), "p_cntr", &p_cntr_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "colors", &colors); read_dist(env_config(DIST_TAG, DIST_DFLT), "p_types", &p_types_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "nations", &nations); read_dist(env_config(DIST_TAG, DIST_DFLT), "nations2", &nations2); read_dist(env_config(DIST_TAG, DIST_DFLT), "regions", ®ions); read_dist(env_config(DIST_TAG, DIST_DFLT), "o_oprio", &o_priority_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "instruct", &l_instruct_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "smode", &l_smode_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "category", &l_category_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "rflag", &l_rflag_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "msegmnt", &c_mseg_set); read_dist(env_config(DIST_TAG, DIST_DFLT), "Q13a", &q13a); read_dist(env_config(DIST_TAG, DIST_DFLT), "Q13b", &q13b); return(0); }
/* * FUNCTION qsub(char *qtag, int flags) * * based on the settings of flags, and the template file $QDIR/qtag.sql * make the following substitutions to turn a query template into EQT * * String Converted to Based on * ====== ============ =========== * first line database <db_name>; -n from command line * second line set explain on; -x from command line * :<number> parameter <number> * :k set number * :o output to outpath/qnum.snum * -o from command line, SET_OUTPUT * :s stream number * :b BEGIN WORK; -a from command line, START_TRAN * :e COMMIT WORK; -a from command line, END_TRAN * :q query number * :n<number> sets rowcount to be returned */ void qsub(char *qtag, int flags) { static char *line = NULL, *qpath = NULL; FILE *qfp; char *cptr, *mark, *qroot = NULL; qnum = atoi(qtag); if (line == NULL) { line = malloc(BUFSIZ); qpath = malloc(BUFSIZ); MALLOC_CHECK(line); MALLOC_CHECK(qpath); } qroot = env_config(QDIR_TAG, QDIR_DFLT); sprintf(qpath, "%s%c%s.sql", qroot, PATH_SEP, qtag); qfp = fopen(qpath, "r"); OPEN_CHECK(qfp, qpath); rowcnt = rowcnt_dflt[qnum]; varsub(qnum, 0, flags); /* set the variables */ if (flags & DFLT_NUM) fprintf(ofp, SET_ROWCOUNT, rowcnt); while (fgets(line, BUFSIZ, qfp) != NULL) { if (!(flags & COMMENT)) strip_comments(line); mark = line; while ((cptr = strchr(mark, VTAG)) != NULL) { *cptr = '\0'; cptr++; fprintf(ofp,"%s", mark); switch(*cptr) { case 'b': case 'B': if (!(flags & ANSI)) fprintf(ofp,"%s\n", START_TRAN); cptr++; break; case 'c': case 'C': if (flags & DBASE) fprintf(ofp, SET_DBASE, db_name); cptr++; break; case 'e': case 'E': if (!(flags & ANSI)) fprintf(ofp,"%s\n", END_TRAN); cptr++; break; case 'n': case 'N': if (!(flags & DFLT_NUM)) { rowcnt=atoi(++cptr); while (isdigit(*cptr) || *cptr == ' ') cptr++; fprintf(ofp, SET_ROWCOUNT, rowcnt); } continue; case 'o': case 'O': if (flags & OUTPUT) fprintf(ofp,"%s '%s/%s.%d'", SET_OUTPUT, osuff, qtag, (snum < 0)?0:snum); cptr++; break; case 'q': case 'Q': fprintf(ofp,"%s", qtag); cptr++; break; case 's': case 'S': fprintf(ofp,"%d", (snum < 0)?0:snum); cptr++; break; case 'X': case 'x': if (flags & EXPLAIN) fprintf(ofp, "%s\n", GEN_QUERY_PLAN); cptr++; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': varsub(qnum, atoi(cptr), flags & DFLT); while (isdigit(*++cptr)); break; default: fprintf(stderr, "-- unknown flag '%c%c' ignored\n", VTAG, *cptr); cptr++; break; } mark=cptr; } fprintf(ofp,"%s", mark); } fclose(qfp); fflush(stdout); return; }