diff options
-rw-r--r-- | src/block/block_open.c | 6 | ||||
-rw-r--r-- | src/include/extern.h | 2 | ||||
-rw-r--r-- | src/lsm/lsm_tree.c | 5 | ||||
-rw-r--r-- | src/os_posix/os_filesize.c | 15 | ||||
-rw-r--r-- | src/os_win/os_filesize.c | 20 | ||||
-rw-r--r-- | src/schema/schema_stat.c | 14 |
6 files changed, 35 insertions, 27 deletions
diff --git a/src/block/block_open.c b/src/block/block_open.c index 8b7d4beeac8..5493d9a2a4c 100644 --- a/src/block/block_open.c +++ b/src/block/block_open.c @@ -424,13 +424,9 @@ int __wt_block_manager_size( WT_SESSION_IMPL *session, const char *filename, WT_DSRC_STATS *stats) { - WT_DECL_RET; wt_off_t filesize; - ret = __wt_filesize_name(session, filename, &filesize); - if (ret != 0) - WT_RET_MSG(session, ret, "%s: file size", filename); - + WT_RET(__wt_filesize_name(session, filename, false, &filesize)); WT_STAT_SET(stats, block_size, filesize); return (0); diff --git a/src/include/extern.h b/src/include/extern.h index 845102ca428..d30bb916e12 100644 --- a/src/include/extern.h +++ b/src/include/extern.h @@ -463,7 +463,7 @@ extern int __wt_exist(WT_SESSION_IMPL *session, const char *filename, bool *exis extern void __wt_fallocate_config(WT_SESSION_IMPL *session, WT_FH *fh); extern int __wt_fallocate( WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset, wt_off_t len); extern int __wt_filesize(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t *sizep); -extern int __wt_filesize_name( WT_SESSION_IMPL *session, const char *filename, wt_off_t *sizep); +extern int __wt_filesize_name(WT_SESSION_IMPL *session, const char *filename, bool silent, wt_off_t *sizep); extern int __wt_bytelock(WT_FH *fhp, wt_off_t byte, bool lock); extern int __wt_directory_sync_fh(WT_SESSION_IMPL *session, WT_FH *fh); extern int __wt_directory_sync(WT_SESSION_IMPL *session, char *path); diff --git a/src/lsm/lsm_tree.c b/src/lsm/lsm_tree.c index 5cff7ccfae3..4beb5f11f83 100644 --- a/src/lsm/lsm_tree.c +++ b/src/lsm/lsm_tree.c @@ -206,7 +206,6 @@ int __wt_lsm_tree_set_chunk_size( WT_SESSION_IMPL *session, WT_LSM_CHUNK *chunk) { - WT_DECL_RET; wt_off_t size; const char *filename; @@ -214,9 +213,7 @@ __wt_lsm_tree_set_chunk_size( if (!WT_PREFIX_SKIP(filename, "file:")) WT_RET_MSG(session, EINVAL, "Expected a 'file:' URI: %s", chunk->uri); - ret = __wt_filesize_name(session, filename, &size); - if (ret != 0) - WT_RET_MSG(session, ret, "%s: file size", filename); + WT_RET(__wt_filesize_name(session, filename, false, &size)); chunk->size = (uint64_t)size; diff --git a/src/os_posix/os_filesize.c b/src/os_posix/os_filesize.c index 09174ffcd90..c58f73b0665 100644 --- a/src/os_posix/os_filesize.c +++ b/src/os_posix/os_filesize.c @@ -34,8 +34,8 @@ __wt_filesize(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t *sizep) * Return the size of a file in bytes, given a file name. */ int -__wt_filesize_name( - WT_SESSION_IMPL *session, const char *filename, wt_off_t *sizep) +__wt_filesize_name(WT_SESSION_IMPL *session, + const char *filename, bool silent, wt_off_t *sizep) { struct stat sb; WT_DECL_RET; @@ -47,9 +47,16 @@ __wt_filesize_name( __wt_free(session, path); - if (ret == 0) + if (ret == 0) { *sizep = sb.st_size; + return (0); + } - /* Some callers expect failure, so don't log an error message. */ + /* + * Some callers of this function expect failure if the file doesn't + * exist, and don't want an error message logged. + */ + if (!silent) + WT_RET_MSG(session, ret, "%s: fstat", filename); return (ret); } diff --git a/src/os_win/os_filesize.c b/src/os_win/os_filesize.c index c51303d7215..7f231b5ba9a 100644 --- a/src/os_win/os_filesize.c +++ b/src/os_win/os_filesize.c @@ -15,8 +15,8 @@ int __wt_filesize(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t *sizep) { - WT_DECL_RET; LARGE_INTEGER size; + WT_DECL_RET; WT_RET(__wt_verbose( session, WT_VERB_FILEOPS, "%s: GetFileSizeEx", fh->name)); @@ -34,11 +34,11 @@ __wt_filesize(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t *sizep) * Return the size of a file in bytes, given a file name. */ int -__wt_filesize_name( - WT_SESSION_IMPL *session, const char *filename, wt_off_t *sizep) +__wt_filesize_name(WT_SESSION_IMPL *session, + const char *filename, bool silent, wt_off_t *sizep) { - WT_DECL_RET; WIN32_FILE_ATTRIBUTE_DATA data; + WT_DECL_RET; char *path; WT_RET(__wt_filename(session, filename, &path)); @@ -47,10 +47,18 @@ __wt_filesize_name( __wt_free(session, path); - if (ret != 0) + if (ret != 0) { *sizep = ((int64_t)data.nFileSizeHigh << 32) | data.nFileSizeLow; + return (0); + } - /* Some callers expect failure, so don't log an error message. */ + /* + * Some callers of this function expect failure if the file doesn't + * exist, and don't want an error message logged. + */ + ret = __wt_errno(); + if (!silent) + WT_RET_MSG(session, ret, "%s: GetFileAttributesEx", filename); return (ret); } diff --git a/src/schema/schema_stat.c b/src/schema/schema_stat.c index bd1f5299fe2..305aeb55c71 100644 --- a/src/schema/schema_stat.c +++ b/src/schema/schema_stat.c @@ -89,6 +89,7 @@ __curstat_size_only(WT_SESSION_IMPL *session, /* Build up the file name from the table URI. */ WT_ERR(__wt_buf_fmt( session, &namebuf, "%s.wt", uri + strlen("table:"))); + /* * Get the size of the underlying file. This will fail for anything * other than simple tables (LSM for example) and will fail if there @@ -96,13 +97,12 @@ __curstat_size_only(WT_SESSION_IMPL *session, * fine - failing here results in falling back to the slow path of * opening the handle. */ - if (__wt_filesize_name(session, namebuf.data, &filesize) == 0) { - /* Setup and populate the statistics structure */ - __wt_stat_init_dsrc_stats(&cst->u.dsrc_stats); - WT_STAT_SET(&cst->u.dsrc_stats, block_size, filesize); - __wt_curstat_dsrc_final(cst); - *was_fast = true; - } + WT_ERR(__wt_filesize_name(session, namebuf.data, true, &filesize)); + /* Setup and populate the statistics structure */ + __wt_stat_init_dsrc_stats(&cst->u.dsrc_stats); + WT_STAT_SET(&cst->u.dsrc_stats, block_size, filesize); + __wt_curstat_dsrc_final(cst); + *was_fast = true; err: __wt_free(session, tableconf); __wt_buf_free(session, &namebuf); |