Repository navigation
Fail the run on write errors to HDR, --client-stats and --failed-keys-file - #760
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through all of it, and it closes the #744 gap cleanly. HDR,
I checked the moved None of these block it as far as I can see. It looks good to me. |
ab05b77 to
171e6ec
Compare
Review of #760: the open failure was detected before the run, but memtier still ran the whole benchmark (possibly --test-time 3600) only to exit 1 at the end. Now an --failed-keys-file that cannot be opened, or whose CSV header cannot be written, prints "error: cannot open --failed-keys-file PATH: REASON" (or "failed writing") and exits 1 before connecting, as --out-file does. The open moves after option validation and the data import, next to the --out-file open, so a later validation error no longer leaves a newly created log behind. A record that fails during the run still disables logging and fails the run at the end. HDR and --client-stats files are only created when a run ends, so they keep the end-of-run rule; the README says so. A --client-stats failure now names only the first file of a run, then "error: N more --client-stats files could not be written", instead of one line per client. Also reset errno before the record fprintf() so a stale value is not reported, and restore the saved maxmemory in the tests. Tests: missing directories for --hdr-file-prefix, --client-stats (one line plus the count with 3 clients) and --failed-keys-file (rc 1, no "Preparing benchmark client"); a record write error via RLIMIT_FSIZE (EFBIG) on a log that already holds its header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. Point by point, as of 171e6ec:
|
171e6ec to
ff1f450
Compare
Review of #760: the open failure was detected before the run, but memtier still ran the whole benchmark (possibly --test-time 3600) only to exit 1 at the end. Now an --failed-keys-file that cannot be opened, or whose CSV header cannot be written, prints "error: cannot open --failed-keys-file PATH: REASON" (or "failed writing") and exits 1 before connecting, as --out-file does. The open moves after option validation and the data import, next to the --out-file open, so a later validation error no longer leaves a newly created log behind. A record that fails during the run still disables logging and fails the run at the end. HDR and --client-stats files are only created when a run ends, so they keep the end-of-run rule; the README says so. A --client-stats failure now names only the first file of a run, then "error: N more --client-stats files could not be written", instead of one line per client. Also reset errno before the record fprintf() so a stale value is not reported, and restore the saved maxmemory in the tests. Tests: missing directories for --hdr-file-prefix, --client-stats (one line plus the count with 3 clients) and --failed-keys-file (rc 1, no "Preparing benchmark client"); a record write error via RLIMIT_FSIZE (EFBIG) on a log that already holds its header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…DR writer Review of #760: - --help and the man page still said "The benchmark continues if the file is unwritable." under --failed-keys-file. They now say that memtier exits 1 at startup if the file cannot be opened, and that a later write error stops logging and makes the run exit 1. - The failed-keys logger singleton is now heap-allocated and never destroyed. main() closes it explicitly. Its static destructor destroyed the mutex and freed m_path while a worker thread could still log after another thread called exit(); TSan reported use of an invalid mutex. - write_client_stats() returns void and save_csv() takes report_error without a default, as both were unused. Tests: one test per HDR writer (full run, SET, GET, --command) in which exactly one file fails, the .txt or the .hgrm, so a writer that drops one result, or a caller that ignores a writer, no longer goes unnoticed. A 4-thread / 4-client variant of the failed-keys record write error. The RLIMIT_FSIZE tests skip when the hard limit is below 1 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Follow-up on the second pass, as of ff1f450:
|
Review of #760: the open failure was detected before the run, but memtier still ran the whole benchmark (possibly --test-time 3600) only to exit 1 at the end. Now an --failed-keys-file that cannot be opened, or whose CSV header cannot be written, prints "error: cannot open --failed-keys-file PATH: REASON" (or "failed writing") and exits 1 before connecting, as --out-file does. The open moves after option validation and the data import, next to the --out-file open, so a later validation error no longer leaves a newly created log behind. A record that fails during the run still disables logging and fails the run at the end. HDR and --client-stats files are only created when a run ends, so they keep the end-of-run rule; the README says so. A --client-stats failure now names only the first file of a run, then "error: N more --client-stats files could not be written", instead of one line per client. Also reset errno before the record fprintf() so a stale value is not reported, and restore the saved maxmemory in the tests. Tests: missing directories for --hdr-file-prefix, --client-stats (one line plus the count with 3 clients) and --failed-keys-file (rc 1, no "Preparing benchmark client"); a record write error via RLIMIT_FSIZE (EFBIG) on a log that already holds its header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ff1f450 to
c04e7a5
Compare
…DR writer Review of #760: - --help and the man page still said "The benchmark continues if the file is unwritable." under --failed-keys-file. They now say that memtier exits 1 at startup if the file cannot be opened, and that a later write error stops logging and makes the run exit 1. - The failed-keys logger singleton is now heap-allocated and never destroyed. main() closes it explicitly. Its static destructor destroyed the mutex and freed m_path while a worker thread could still log after another thread called exit(); TSan reported use of an invalid mutex. - write_client_stats() returns void and save_csv() takes report_error without a default, as both were unused. Tests: one test per HDR writer (full run, SET, GET, --command) in which exactly one file fails, the .txt or the .hgrm, so a writer that drops one result, or a caller that ignores a writer, no longer goes unnoticed. A 4-thread / 4-client variant of the failed-keys record write error. The RLIMIT_FSIZE tests skip when the hard limit is below 1 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #760: these files are only created when a run ends, so a mistyped directory used to cost a whole run (e.g. --test-time 3600) before memtier exited 1. Now memtier checks at startup, after option validation and before connecting, that the directory of each prefix exists and is writable, using access(dir, W_OK | X_OK) and creating no file. If the check fails, it prints "error: cannot write --hdr-file-prefix directory DIR: REASON" (or --client-stats) and exits 1. A full disk is still only seen when the run ends. The logger comments now say which paths skip the join: the early exit() / exit(failure_exit_code()) paths, from main() or from a worker thread. On the normal path main() joins the workers and then closes the logger. Tests: the missing-directory tests now expect the startup exit, with no "Preparing benchmark client" line. The end-of-run open failures (one HDR file, and three --client-stats CSVs reported once plus a count) use a directory in the file's place (EISDIR). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Answers to the edited review, as of c04e7a5:
|
…-file The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were written without checking for errors: the HDR writers and save_csv() ignored fclose(), and the failed-keys logger checked fprintf() (which only fills the stdio buffer) but not the fflush() that does the write. On a full disk, quota or I/O error the files ended up empty or truncated, nothing was printed and memtier exited 0. A file that could not be opened was reported but also exited 0. These files now follow the rule #729 set for --out-file and --json-out-file. They are flushed and checked with ferror() through finish_output_file(), and a failure prints "error: failed writing --hdr-file-prefix file PATH: REASON" (or --client-stats file, or --failed-keys-file PATH) or "error: cannot open ...". The other files are still written, and memtier exits 1 (a connection-stage abort keeps exit code 2). g_output_failed replaces main()'s local output_failed so run_benchmark() can set it for the CSVs. --failed-keys-file is fatal too, open failure included: it is an output that was asked for, and a lost log with exit 0 is what #719 fixed for the other outputs. The run is not cut short: as before, logging stops and the benchmark goes on; the exit code reports it. stdout_reader_gone() moves to file_io.cpp so a --failed-keys-file on stdout whose reader went away (/dev/stdout and `| head`) gets the same exemption as the results on stdout. Release notes: such runs now exit 1 instead of 0, including an HDR or --client-stats path in a missing directory and a --failed-keys-file that cannot be opened. That message is now "error: cannot open --failed-keys-file PATH: REASON; logging disabled." instead of a warning. Tests: /dev/full symlinks for the full-run and per-command .txt and .hgrm files and for a --client-stats CSV, --failed-keys-file /dev/full with SETs that fail with -OOM, and a --failed-keys-file on a closed stdout pipe. Fixes #744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #760: the open failure was detected before the run, but memtier still ran the whole benchmark (possibly --test-time 3600) only to exit 1 at the end. Now an --failed-keys-file that cannot be opened, or whose CSV header cannot be written, prints "error: cannot open --failed-keys-file PATH: REASON" (or "failed writing") and exits 1 before connecting, as --out-file does. The open moves after option validation and the data import, next to the --out-file open, so a later validation error no longer leaves a newly created log behind. A record that fails during the run still disables logging and fails the run at the end. HDR and --client-stats files are only created when a run ends, so they keep the end-of-run rule; the README says so. A --client-stats failure now names only the first file of a run, then "error: N more --client-stats files could not be written", instead of one line per client. Also reset errno before the record fprintf() so a stale value is not reported, and restore the saved maxmemory in the tests. Tests: missing directories for --hdr-file-prefix, --client-stats (one line plus the count with 3 clients) and --failed-keys-file (rc 1, no "Preparing benchmark client"); a record write error via RLIMIT_FSIZE (EFBIG) on a log that already holds its header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…DR writer Review of #760: - --help and the man page still said "The benchmark continues if the file is unwritable." under --failed-keys-file. They now say that memtier exits 1 at startup if the file cannot be opened, and that a later write error stops logging and makes the run exit 1. - The failed-keys logger singleton is now heap-allocated and never destroyed. main() closes it explicitly. Its static destructor destroyed the mutex and freed m_path while a worker thread could still log after another thread called exit(); TSan reported use of an invalid mutex. - write_client_stats() returns void and save_csv() takes report_error without a default, as both were unused. Tests: one test per HDR writer (full run, SET, GET, --command) in which exactly one file fails, the .txt or the .hgrm, so a writer that drops one result, or a caller that ignores a writer, no longer goes unnoticed. A 4-thread / 4-client variant of the failed-keys record write error. The RLIMIT_FSIZE tests skip when the hard limit is below 1 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #760: these files are only created when a run ends, so a mistyped directory used to cost a whole run (e.g. --test-time 3600) before memtier exited 1. Now memtier checks at startup, after option validation and before connecting, that the directory of each prefix exists and is writable, using access(dir, W_OK | X_OK) and creating no file. If the check fails, it prints "error: cannot write --hdr-file-prefix directory DIR: REASON" (or --client-stats) and exits 1. A full disk is still only seen when the run ends. The logger comments now say which paths skip the join: the early exit() / exit(failure_exit_code()) paths, from main() or from a worker thread. On the normal path main() joins the workers and then closes the logger. Tests: the missing-directory tests now expect the startup exit, with no "Preparing benchmark client" line. The end-of-run open failures (one HDR file, and three --client-stats CSVs reported once plus a count) use a directory in the file's place (EISDIR). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fy-only Review of #760: - check_output_prefix_dir() now stat()s the directory and reports ENOTDIR when a regular file sits where it should be ("... directory X: Not a directory"). Before, such a file with the execute bit passed access() and only failed when the run ended, and one without the execute bit was reported as "Permission denied". - --verify-only writes no HDR or --client-stats files, so their directories are no longer checked in that mode. - The README and the code comment now say the check is best-effort: access() uses the real UID, so when running as root or on an NFS root_squash mount an unwritable directory can still only be caught when the run ends. Tests: a regular file as the prefix directory, with and without the execute bit, for both options. A --verify-only run with missing prefix directories gets past the check (standalone only, since --data-import does not support cluster mode). Co-Authored-By: Claude Opus 5.5 <[email protected]>
c04e7a5 to
4e6c36d
Compare
|
On the re-edited review, as of 4e6c36d:
|
|
Confirmed the remaining small points in the latest review: reporting the first client-stats failure plus a count is deliberate, to avoid one diagnostic per client; it can hide distinct later errno values. The prefix-directory check is best-effort, while the failed-keys file is checked by actually opening it. The singleton lifetime rationale remains at its allocation site; the destructor stays available for ordinary class instances. No code change is needed for these non-blocking points. |
Problem
The
--hdr-file-prefixfiles, the--client-statsCSVs and--failed-keys-filewere written without checking for errors. On a full disk (or a quota or I/O error) the files ended up empty or truncated, nothing was printed and memtier exited 0. This is the part of #719 that #729 left out. #736 listed it in the README as a known gap.Root cause
save_hdr_percentiles_print_format()andsave_hdr_log_format()calledfclose()without checking it orferror(), andmain()ignored their return values anyway.--client-stats:save_csv()ignoredfclose(), so thefailed to write client statsmessage only fired whenfopen()failed.--failed-keys-file:log_failure()checkedfprintf(), but that only fills the stdio buffer. Thefflush()that does the write (per record, and for the header inopen()) was not checked, and neither wasfclose().Fix
These files now follow the rule from #729 and #717:
finish_output_file(). The other files are still written, and memtier exits 1.--failed-keys-filefails at startup when it cannot be opened, or when its CSV header cannot be written. It printserror: cannot open --failed-keys-file PATH: REASON(orerror: failed writing ...) and exits 1 before connecting, like--out-file(Fail at startup on an unwritable --out-file; open output files only after option validation #717).--out-fileopen. That way a later validation error leaves no new log behind.--out-fileis not truncated yet at that point, and--json-out-fileis not opened yet. A later--json-out-fileopen failure can still leave a new failed-keys file that holds only its header. The file is opened in append mode, so this is harmless.error: failed writing --failed-keys-file PATH: REASON; logging disabled.. The benchmark goes on without the log, and memtier exits 1 at the end.--client-statsfiles are only created when a run ends.stat()+S_ISDIR, thenaccess(dir, W_OK | X_OK), and creates no file. A regular file in the directory's place is reported asNot a directory. On failure it printserror: cannot write --hdr-file-prefix directory DIR: REASON(or--client-stats) and exits 1, so a mistyped directory does not cost a whole--test-time 3600run.--verify-onlywrites neither kind of file, so it skips the check.access()uses the real UID, so when running as root or on an NFSroot_squashmount, an unwritable directory can still pass and is then only caught when the run ends.error: cannot open --hdr-file-prefix file PATH: REASON,error: failed writing --client-stats file PATH: REASON, and so on.--client-stats, only the first failing file of a run is named. It is followed byerror: N more --client-stats files could not be written, instead of one line per client (200 lines at the default-t 4 -c 50).g_output_failedreplaces the localoutput_failedinmain(), so thatrun_benchmark()can set it for the CSVs.stdout_reader_gone()moves tofile_io.cpp. A newclose_output_file()applies it, so a--failed-keys-fileon stdout whose reader went away (/dev/stdoutand| head) only stops logging. This is the same exemption the results on stdout get.main()closes it explicitly. Before, its static destructor destroyed the mutex and freedm_pathwhile a worker could still log after another thread calledexit(). TSan reported use of an invalid mutex. This bug already existed before this PR. The paths that skip the join are the earlyexit()/exit(failure_exit_code())ones, e.g. a thread that fails to prepare or a fatal error in a worker thread. On the normal pathmain()joins the workers and then closes the logger.--helpandmemtier_benchmark.1no longer say "The benchmark continues if the file is unwritable." under--failed-keys-file. They now say: "Exits 1 at startup if the file cannot be opened; a later write error stops logging and the run exits 1."The README "Output write errors" section now describes all of this. The #744 known-gap bullet in "Closed stdin, stdout or stderr" points to that section instead.
Release notes:
--client-statsprefix whose directory does not exist or is not writable; this now exits at startup;--failed-keys-filerecord that cannot be written during the run. A lost log is a lost output (Write errors on --out-file and --json-out-file are ignored: a run whose results could not be written exits 0 #719/Fail the run on write errors to --out-file, --json-out-file or stdout #729): the file is the evidence of which keys failed, so a script that relies on it must not see success when it is incomplete.--failed-keys-filethat cannot be opened now exits 1 at startup instead of running with a warning. Its message changes fromwarning: failed-keys-file '...' could not be opened (...); logging disabled.toerror: cannot open --failed-keys-file PATH: REASON.warning: failed-keys-file '...' write failed (...)toerror: failed writing --failed-keys-file PATH: REASON; logging disabled..--client-statsopen failures used to print inperror()format (PATH: REASON). They now printerror: cannot open --hdr-file-prefix file PATH: REASONorerror: cannot open --client-stats file PATH: REASON.error: PATH: failed to write client stats.is gone..txtHDR file on a full disk can reportInput/output errorinstead of ENOSPC. The hdr_histogram library writes it through manyfprintf()calls, and stdio drops the real errno, asfinish_output_file()documents.Tests
New in
tests/tests_oss_simple_flow.py:test_hdr_file_write_error:/dev/fullsymlinks forh_FULL_RUN_1.txt,h_FULL_RUN_1.hgrm,h_SET_command_run_1.txtandh_GET_command_run_1.hgrm. Expects rc 1, an error for each of the four files, and the other HDR files still written.test_hdr_full_run_file_write_error,test_hdr_set_command_file_write_error,test_hdr_get_command_file_write_errorandtest_hdr_arbitrary_command_file_write_error(--command): exactly one file fails at a time, the.txtor the.hgrm. Each case expects rc 1 and one error. These kill the mutants below, which survived the tests that fail several files at once:g_output_failedfor one writer;ok =instead ofok &=;ok =in the--commandloop.test_client_stats_write_error: a/dev/fullsymlink forcs-1-0-0.csv.test_hdr_file_prefix_missing_directoryandtest_client_stats_missing_directory: expect rc 1 at startup, with thecannot write ... directorymessage and noPreparing benchmark clientline.test_output_prefix_dir_is_a_file: a regular file sits in the directory's place, with and without the execute bit, for both options. ExpectsNot a directoryat startup.test_verify_only_skips_output_prefix_dir_check: a--verify-onlyrun with missing prefix directories gets past the check. It runs standalone only, because--data-importdoes not support cluster mode.test_hdr_file_open_errorandtest_client_stats_open_error_reported_once: a directory sits in the file's place (EISDIR), so the open fails when the run ends. With 3 clients the CSV error is printed once, followed by2 more.test_failed_keys_file_missing_directory: expects rc 1 at startup, with noPreparing benchmark clientline.test_failed_keys_file_write_error:/dev/full. The header write fails, so memtier exits 1 at startup.test_failed_keys_file_record_write_error: the log already holds its header and sits exactly atRLIMIT_FSIZE(with SIGXFSZ ignored). Every SET fails with-OOM, so every record fails with EFBIG. Expects the error once, the run going on, and rc 1.test_failed_keys_file_record_write_error_threadsrepeats this with-t 4 -c 4, so 16 connections log through the shared lock. Both tests skip if the hardRLIMIT_FSIZEis below 1 MiB.test_failed_keys_file_stdout_reader_gone: a guard./dev/stdouton a closed stdout pipe gives rc 0 and no error.test_failed_keys_file_written: a guard. The same-OOMrun with a regular file writes the header and 10 records, with rc 0.Results (local, redis 8.6.0; full suite re-run at 4e6c36d on 82119ef):
--verify-onlyskip;S_ISDIRcheck.test_cluster_failed_keys.pyon a 3-shardoss-cluster: 25/25, with the--verify-onlytest skipped;tests_oss_simple_flow.py: 77/77;test_closed_std_fds.py,test_hdr_histogram.py,test_retry_on_error.pyandtest_json_output_integrity.py: 82/82.Fixes #744
Affected versions
1.0.0 (
--client-stats) / 1.4.0 (--hdr-file-prefix) / 2.4.0 (--failed-keys-file) through 2.5.2 (latest) and master.--client-stats: 833a8df "First memtier_benchmark version." (uncheckedfclose(f)insave_csv()), first in 1.0.0.--hdr-file-prefix: fdf704b "[add] Enable full percentile spectrum analysis on latency", first in 1.4.0.--failed-keys-file: 08cfc24 (feat(retry): --retry-on-error with bytes-snapshot resend + failed-keys log #381), first in 2.4.0.🤖 Generated with Claude Code
Note
Medium Risk
Changes exit behavior (0→1) for scripts relying on success when optional outputs fail, and touches shared output I/O paths used at shutdown; benchmark workload logic is largely unchanged.
Overview
Output write failures for
--hdr-file-prefix,--client-stats, and--failed-keys-filenow fail the benchmark (exit 1), aligning them with the existing rules for--out-file/--json-out-file(#719/#729).--failed-keys-fileopens after validation (like--out-file): open or CSV header write errors exit 1 at startup; a mid-run write error disables logging but still exits 1 at the end. Stdout pipe readers that disconnect (| head) only stop logging, via sharedstdout_reader_gone()/close_output_file()moved intofile_io.cpp.HDR and
--client-statsget a startup directory writability check (skipped for--verify-only); end-of-run open/write failures are reported throughopen_option_file/close_option_file, with remaining files still written.--client-statsreports only the first failing CSV plus a count of additional failures.A global
g_output_failedflag drives exit 1 after connection-stage abort precedence (2). Docs,--help, and man page are updated; integration tests cover full disk, missing dirs, and related edge cases (#744).Reviewed by Cursor Bugbot for commit 4e6c36d. Bugbot is set up for automated code reviews on this repo. Configure here.