diff --git a/ft/ft-ops.cc b/ft/ft-ops.cc index 9d7f61c2acabf72f5fc4f4ad333e0442dfb0e8b4..56d1b8e3a02ce96ea2cd0efbc27740f973f9d06d 100644 --- a/ft/ft-ops.cc +++ b/ft/ft-ops.cc @@ -3534,10 +3534,13 @@ static int ft_create_file(FT_HANDLE UU(brt), const char *fname, int *fdp) { } r = toku_fsync_directory(fname); - resource_assert_zero(r); - - *fdp = fd; - return 0; + if (r == 0) { + *fdp = fd; + } else { + int rr = close(fd); + assert_zero(rr); + } + return r; } // open a file for use by the brt. if the file does not exist, error @@ -3687,7 +3690,7 @@ ft_handle_open(FT_HANDLE ft_h, const char *fname_in_env, int is_create, int only txn_created = (bool)(txn!=NULL); toku_logger_log_fcreate(txn, fname_in_env, reserved_filenum, mode, ft_h->options.flags, ft_h->options.nodesize, ft_h->options.basementnodesize, ft_h->options.compression_method); r = ft_create_file(ft_h, fname_in_cwd, &fd); - assert_zero(r); + if (r) { goto exit; } } if (r) { goto exit; } r=toku_cachetable_openfd_with_filenum(&cf, cachetable, fd, fname_in_env, reserved_filenum); diff --git a/ft/roll.cc b/ft/roll.cc index d19b2e93802b9151f3a28596488c53abf5d6c4e3..037ffc1b476ed8828bd58bc26f142ff21fcdc18d 100644 --- a/ft/roll.cc +++ b/ft/roll.cc @@ -194,7 +194,6 @@ toku_rollback_fcreate (FILENUM filenum, // is not an error, but a missing file outside of recovery is. r = toku_cachefile_of_filenum(ct, filenum, &cf); if (r == ENOENT) { - assert(txn->for_recovery); r = 0; goto done; } diff --git a/portability/portability.cc b/portability/portability.cc index 701c96b3bd87e251759615e1fe8559e5174f5321..13e5060d238dcc15856642f1f9006c2fc854c815 100644 --- a/portability/portability.cc +++ b/portability/portability.cc @@ -133,6 +133,10 @@ PATENT RIGHTS GRANT: int toku_portability_init(void) { int r = toku_memory_startup(); + if (r == 0) { + uint64_t hz; + r = toku_os_get_processor_frequency(&hz); + } return r; } @@ -368,30 +372,37 @@ toku_get_processor_frequency_sysctl(const char * const cmd, uint64_t *hzret) { if (!fp) { r = EINVAL; // popen doesn't return anything useful in errno, // gotta pick something - goto exit; - } - r = fscanf(fp, "%" SCNu64, hzret); - if (r != 1) { - r = get_maybe_error_errno(); } else { - r = 0; + r = fscanf(fp, "%" SCNu64, hzret); + if (r != 1) { + r = get_maybe_error_errno(); + } else { + r = 0; + } + pclose(fp); } - pclose(fp); - -exit: return r; } -int +static uint64_t toku_cached_hz; // cache the value of hz so that we avoid opening files to compute it later + +int toku_os_get_processor_frequency(uint64_t *hzret) { int r; - r = toku_get_processor_frequency_sys(hzret); - if (r != 0) - r = toku_get_processor_frequency_cpuinfo(hzret); - if (r != 0) - r = toku_get_processor_frequency_sysctl("sysctl -n hw.cpufrequency", hzret); - if (r != 0) - r = toku_get_processor_frequency_sysctl("sysctl -n machdep.tsc_freq", hzret); + if (toku_cached_hz) { + *hzret = toku_cached_hz; + r = 0; + } else { + r = toku_get_processor_frequency_sys(hzret); + if (r != 0) + r = toku_get_processor_frequency_cpuinfo(hzret); + if (r != 0) + r = toku_get_processor_frequency_sysctl("sysctl -n hw.cpufrequency", hzret); + if (r != 0) + r = toku_get_processor_frequency_sysctl("sysctl -n machdep.tsc_freq", hzret); + if (r == 0) + toku_cached_hz = *hzret; + } return r; } @@ -439,3 +450,10 @@ double tokutime_to_seconds(tokutime_t t) { } return t*seconds_per_clock; } + +#include <toku_race_tools.h> +void __attribute__((constructor)) toku_portability_helgrind_ignore(void); +void +toku_portability_helgrind_ignore(void) { + TOKU_VALGRIND_HG_DISABLE_CHECKING(&toku_cached_hz, sizeof toku_cached_hz); +}