/* * config_setup -- * Initialize configuration for a run. */ void config_setup(void) { CONFIG *cp; /* Clear any temporary values. */ config_clear(); /* * Choose a data source type and a file type: they're interrelated (LSM * trees are only compatible with row-store) and other items depend on * them. */ if (!config_find_is_perm("data_source", strlen("data_source"))) switch (MMRAND(0, 2)) { case 0: config_single("data_source=file", 0); break; case 1: #if 0 config_single("data_source=lsm", 0); break; #endif case 2: config_single("data_source=table", 0); break; } if (!config_find_is_perm("file_type", strlen("file_type"))) { if (strcmp(g.c_data_source, "lsm") == 0) config_single("file_type=row", 0); else switch (MMRAND(0, 2)) { case 0: config_single("file_type=fix", 0); break; case 1: config_single("file_type=var", 0); break; case 2: config_single("file_type=row", 0); break; } } g.type = config_translate(g.c_file_type); /* * If data_source and file_type were both "permanent", we may still * have a mismatch. */ if (g.type != ROW && strcmp(g.c_data_source, "lsm") == 0) { fprintf(stderr, "%s: lsm data_source is only compatible with row file_type\n", g.progname); exit(EXIT_FAILURE); } /* Build the object name. */ if ((g.uri = malloc( strlen(g.c_data_source) + strlen(WT_NAME) + 2)) == NULL) syserr("malloc"); strcpy(g.uri, g.c_data_source); strcat(g.uri, ":"); strcat(g.uri, WT_NAME); /* Default single-threaded half of the time. */ cp = config_find("threads", strlen("threads")); if (!(cp->flags & C_PERM)) *cp->v = MMRAND(0, 1) ? 1: CONF_RAND(cp); /* Fill in random values for the rest of the run. */ for (cp = c; cp->name != NULL; ++cp) { if (cp->flags & (C_IGNORE | C_PERM | C_TEMP)) continue; /* * Boolean flags are 0 or 1, but only set N in 100 where the * variable's min value is N. Set the flag if we rolled >= * the min, 0 otherwise. */ if (cp->flags & C_BOOL) *cp->v = MMRAND(1, 100) <= cp->min ? 1 : 0; else *cp->v = CONF_RAND(cp); } config_compression(); /* Clear operations values if the whole run is read-only. */ if (g.c_ops == 0) for (cp = c; cp->name != NULL; ++cp) if (cp->flags & C_OPS) *cp->v = 0; /* Multi-threaded runs cannot be replayed. */ if (g.replay && !SINGLETHREADED) die(0, "-r is incompatible with threaded runs"); /* * Periodically, set the delete percentage to 0 so salvage gets run, * as long as the delete percentage isn't nailed down. */ if (!g.replay && g.run_cnt % 10 == 0) { cp = config_find("delete_pct", strlen("delete_pct")); if (cp->name != NULL && !(cp->flags & (C_IGNORE | C_PERM | C_TEMP))) g.c_delete_pct = 0; } /* Reset the key count. */ g.key_cnt = 0; }
/* * config_setup -- * Initialize configuration for a run. */ void config_setup(void) { CONFIG *cp; /* Clear any temporary values. */ config_clear(); /* * Choose a data source type and a file type: they're interrelated (LSM * trees are only compatible with row-store) and other items depend on * them. */ if (!config_find_is_perm("data_source", strlen("data_source"))) switch (MMRAND(1, 3)) { case 1: config_single("data_source=file", 0); break; case 2: config_single("data_source=lsm", 0); break; case 3: config_single("data_source=table", 0); break; } if (!config_find_is_perm("file_type", strlen("file_type"))) switch (DATASOURCE("lsm") ? 3 : MMRAND(1, 3)) { case 1: config_single("file_type=fix", 0); break; case 2: config_single("file_type=var", 0); break; case 3: config_single("file_type=row", 0); break; } config_map_file_type(g.c_file_type, &g.type); /* * If data_source and file_type were both "permanent", we may still * have a mismatch. */ if (DATASOURCE("lsm") && g.type != ROW) { fprintf(stderr, "%s: lsm data_source is only compatible with row file_type\n", g.progname); exit(EXIT_FAILURE); } /* * Build the top-level object name: we're overloading data_source in * our configuration, LSM or KVS devices are "tables", but files are * tested as well. */ if ((g.uri = malloc(256)) == NULL) syserr("malloc"); strcpy(g.uri, DATASOURCE("file") ? "file:" : "table:"); if (DATASOURCE("helium")) strcat(g.uri, "dev1/"); strcat(g.uri, WT_NAME); /* Default single-threaded 10% of the time. */ cp = config_find("threads", strlen("threads")); if (!(cp->flags & C_PERM)) *cp->v = MMRAND(1, 100) < 10 ? 1: CONF_RAND(cp); /* Fill in random values for the rest of the run. */ for (cp = c; cp->name != NULL; ++cp) { if (cp->flags & (C_IGNORE | C_PERM | C_TEMP)) continue; /* * Boolean flags are 0 or 1, but only set N in 100 where the * variable's min value is N. Set the flag if we rolled >= * the min, 0 otherwise. */ if (cp->flags & C_BOOL) *cp->v = MMRAND(1, 100) <= cp->min ? 1 : 0; else *cp->v = CONF_RAND(cp); } /* Required shared libraries. */ if (DATASOURCE("helium") && access(HELIUM_PATH, R_OK) != 0) die(errno, "Levyx/helium shared library: %s", HELIUM_PATH); if (DATASOURCE("kvsbdb") && access(KVS_BDB_PATH, R_OK) != 0) die(errno, "kvsbdb shared library: %s", KVS_BDB_PATH); /* Some data-sources don't support user-specified collations. */ if (DATASOURCE("helium") || DATASOURCE("kvsbdb")) g.c_reverse = 0; config_checksum(); config_compression(); /* Clear operations values if the whole run is read-only. */ if (g.c_ops == 0) for (cp = c; cp->name != NULL; ++cp) if (cp->flags & C_OPS) *cp->v = 0; /* * Periodically, set the delete percentage to 0 so salvage gets run, * as long as the delete percentage isn't nailed down. */ if (!g.replay && g.run_cnt % 10 == 0) { cp = config_find("delete_pct", strlen("delete_pct")); if (cp->name != NULL && !(cp->flags & (C_IGNORE | C_PERM | C_TEMP))) g.c_delete_pct = 0; } /* * If this is an LSM run, set the cache size and crank up the insert * percentage. */ if (DATASOURCE("lsm")) { cp = config_find("cache", strlen("cache")); if (!(cp->flags & C_PERM)) g.c_cache = 30 * g.c_chunk_size; cp = config_find("insert_pct", strlen("insert_pct")); if (cp->name != NULL && !(cp->flags & (C_IGNORE | C_PERM | C_TEMP))) g.c_insert_pct = MMRAND(50, 85); } /* * Key/value minimum/maximum are related, correct unless specified by * the configuration. */ cp = config_find("key_min", strlen("key_min")); if (!(cp->flags & C_PERM) && g.c_key_min > g.c_key_max) g.c_key_min = g.c_key_max; cp = config_find("key_max", strlen("key_max")); if (!(cp->flags & C_PERM) && g.c_key_max < g.c_key_min) g.c_key_max = g.c_key_min; if (g.c_key_min > g.c_key_max) die(EINVAL, "key_min may not be larger than key_max"); cp = config_find("value_min", strlen("value_min")); if (!(cp->flags & C_PERM) && g.c_value_min > g.c_value_max) g.c_value_min = g.c_value_max; cp = config_find("value_max", strlen("value_max")); if (!(cp->flags & C_PERM) && g.c_value_max < g.c_value_min) g.c_value_max = g.c_value_min; if (g.c_value_min > g.c_value_max) die(EINVAL, "value_min may not be larger than value_max"); /* Reset the key count. */ g.key_cnt = 0; }