diff options
Diffstat (limited to 'src/conn')
-rw-r--r-- | src/conn/conn_api.c | 101 | ||||
-rw-r--r-- | src/conn/conn_stat.c | 20 |
2 files changed, 57 insertions, 64 deletions
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c index b8c3e9e4b1f..179f1cbb29f 100644 --- a/src/conn/conn_api.c +++ b/src/conn/conn_api.c @@ -969,7 +969,6 @@ static int __conn_config_file(WT_SESSION_IMPL *session, const char *filename, int is_user, const char **cfg, WT_ITEM *cbuf) { - WT_CONNECTION_IMPL *conn; WT_DECL_RET; WT_FH *fh; size_t len; @@ -977,7 +976,6 @@ __conn_config_file(WT_SESSION_IMPL *session, int exist, quoted; char *p, *t; - conn = S2C(session); fh = NULL; /* Configuration files are always optional. */ @@ -985,14 +983,6 @@ __conn_config_file(WT_SESSION_IMPL *session, if (!exist) return (0); - /* - * The base configuration should not exist if we are creating this - * database. - */ - if (!is_user && conn->is_new) - WT_RET_MSG(session, EINVAL, - "%s exists before database creation", filename); - /* Open the configuration file. */ WT_RET(__wt_open(session, filename, 0, 0, 0, &fh)); WT_ERR(__wt_filesize(session, fh, &size)); @@ -1466,45 +1456,45 @@ __wt_verbose_config(WT_SESSION_IMPL *session, const char *cfg[]) } /* - * __conn_write_config -- - * Save the configuration used to create a database. + * __conn_write_base_config -- + * Save the base configuration used to create a database. */ static int -__conn_write_config( - WT_SESSION_IMPL *session, const char *filename, const char *cfg[]) +__conn_write_base_config(WT_SESSION_IMPL *session, const char *cfg[]) { FILE *fp; WT_CONFIG parser; - WT_CONFIG_ITEM k, v; + WT_CONFIG_ITEM cval, k, v; WT_DECL_RET; - char *path; + int exist; + + fp = NULL; /* - * We were passed an array of configuration strings where slot 0 is all - * possible values and the second and subsequent slots are changes - * specified by the application during open (using the wiredtiger_open - * configuration string, an environment variable, or user-configuration - * file). The base configuration file contains all changes to default - * settings made at create, and we include the user-configuration file - * in that list, even though we don't expect it to change. Of course, - * an application could leave that file as it is right now and not - * remove a configuration we need, but applications can also guarantee - * all database users specify consistent environment variables and - * wiredtiger_open configuration arguments, and if we protect against - * those problems, might as well include the application's configuration - * file as well. - * - * If there is no configuration, don't bother creating an empty file. + * Discard any base configuration setup file left-over from previous + * runs. This doesn't matter for correctness, it's just cleaning up + * random files. */ - if (cfg[1] == NULL) + WT_RET(__wt_remove_if_exists(session, WT_BASECONFIG_SET)); + + /* The base configuration file is optional, check the configuration. */ + WT_RET(__wt_config_gets(session, cfg, "config_base", &cval)); + if (!cval.val) + return (0); + + /* + * We don't test separately if we're creating the database in this run + * as we might have crashed between creating the "WiredTiger" file and + * creating the base configuration file. If configured, there's always + * a base configuration file, and we rename it into place, so it can + * only NOT exist if we crashed before it was created; in other words, + * if the base configuration file exists, we're done. + */ + WT_RET(__wt_exist(session, WT_BASECONFIG, &exist)); + if (exist) return (0); - WT_RET(__wt_filename(session, filename, &path)); - if ((fp = fopen(path, "w")) == NULL) - ret = __wt_errno(); - __wt_free(session, path); - if (fp == NULL) - return (ret); + WT_RET(__wt_fopen(session, WT_BASECONFIG_SET, "w", 0, &fp)); fprintf(fp, "%s\n\n", "# Do not modify this file.\n" @@ -1518,6 +1508,20 @@ __conn_write_config( WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR); /* + * We were passed an array of configuration strings where slot 0 is all + * possible values and the second and subsequent slots are changes + * specified by the application during open (using the wiredtiger_open + * configuration string, an environment variable, or user-configuration + * file). The base configuration file contains all changes to default + * settings made at create, and we include the user-configuration file + * in that list, even though we don't expect it to change. Of course, + * an application could leave that file as it is right now and not + * remove a configuration we need, but applications can also guarantee + * all database users specify consistent environment variables and + * wiredtiger_open configuration arguments, and if we protect against + * those problems, might as well include the application's configuration + * file as well. + * * We want the list of defaults that have been changed, that is, if the * application didn't somehow configure a setting, we don't write out a * default value, so future releases may silently migrate to new default @@ -1542,11 +1546,13 @@ __conn_write_config( WT_ERR_NOTFOUND_OK(ret); } -err: WT_TRET(fclose(fp)); + /* Flush the handle and rename the file into place. */ + return (__wt_sync_and_rename_fp( + session, &fp, WT_BASECONFIG_SET, WT_BASECONFIG)); - /* Don't leave a damaged file in place. */ - if (ret != 0) - (void)__wt_remove(session, filename); + /* Close any file handle left open, remove any temporary file. */ +err: WT_TRET(__wt_fclose(session, &fp, 1)); + WT_TRET(__wt_remove_if_exists(session, WT_BASECONFIG_SET)); return (ret); } @@ -1775,15 +1781,10 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler, WT_ERR(__conn_load_extensions(session, cfg)); /* - * We've completed configuration, write the base configuration file if - * we're creating the database. + * Configuration completed; optionally write the base configuration file + * if it doesn't already exist. */ - if (conn->is_new) { - WT_ERR(__wt_config_gets(session, cfg, "config_base", &cval)); - if (cval.val) - WT_ERR( - __conn_write_config(session, WT_BASECONFIG, cfg)); - } + WT_ERR(__conn_write_base_config(session, cfg)); /* * Start the worker threads last. diff --git a/src/conn/conn_stat.c b/src/conn/conn_stat.c index 9dc05909d0a..7d8c35a2358 100644 --- a/src/conn/conn_stat.c +++ b/src/conn/conn_stat.c @@ -166,10 +166,10 @@ __statlog_dump(WT_SESSION_IMPL *session, const char *name, int conn_stats) sizeof(WT_DSRC_STATS) / sizeof(WT_STATS); for (i = 0, stats = WT_CURSOR_STATS(cursor); i < max; ++i, ++stats) - WT_ERR_TEST((fprintf(conn->stat_fp, + WT_ERR(__wt_fprintf(session, conn->stat_fp, "%s %" PRIu64 " %s %s\n", conn->stat_stamp, - stats->v, name, stats->desc) < 0), __wt_errno()); + stats->v, name, stats->desc)); WT_ERR(cursor->close(cursor)); break; case EBUSY: @@ -300,13 +300,10 @@ __statlog_log_one(WT_SESSION_IMPL *session, WT_ITEM *path, WT_ITEM *tmp) if ((log_file = conn->stat_fp) == NULL || path == NULL || strcmp(tmp->mem, path->mem) != 0) { conn->stat_fp = NULL; - if (log_file != NULL) - WT_RET(fclose(log_file) == 0 ? 0 : __wt_errno()); - + WT_RET(__wt_fclose(session, &log_file, 1)); if (path != NULL) (void)strcpy(path->mem, tmp->mem); - WT_RET_TEST((log_file = - fopen(tmp->mem, "a")) == NULL, __wt_errno()); + WT_RET(__wt_fopen(session, tmp->mem, "a", 0, &log_file)); } conn->stat_fp = log_file; @@ -346,9 +343,7 @@ __statlog_log_one(WT_SESSION_IMPL *session, WT_ITEM *path, WT_ITEM *tmp) WT_RET(__statlog_lsm_apply(session)); /* Flush. */ - WT_RET(fflush(conn->stat_fp) == 0 ? 0 : __wt_errno()); - - return (0); + return (__wt_fflush(session, conn->stat_fp)); } /* @@ -533,10 +528,7 @@ __wt_statlog_destroy(WT_SESSION_IMPL *session, int is_close) conn->stat_session = NULL; conn->stat_tid_set = 0; conn->stat_format = NULL; - if (conn->stat_fp != NULL) { - WT_TRET(fclose(conn->stat_fp) == 0 ? 0 : __wt_errno()); - conn->stat_fp = NULL; - } + WT_TRET(__wt_fclose(session, &conn->stat_fp, 1)); conn->stat_path = NULL; conn->stat_sources = NULL; conn->stat_stamp = NULL; |