Skip to content

Fail the run on write errors to HDR, --client-stats and --failed-keys-file - #760

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix/744-output-write-errors
Oct 17, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix/744-output-write-errors

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were 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

  • HDR: save_hdr_percentiles_print_format() and save_hdr_log_format() called fclose() without checking it or ferror(), and main() ignored their return values anyway.
  • --client-stats: save_csv() ignored fclose(), so the failed to write client stats message only fired when fopen() failed.
  • --failed-keys-file: log_failure() checked fprintf(), but that only fills the stdio buffer. The fflush() that does the write (per record, and for the header in open()) was not checked, and neither was fclose().
  • When any of these files could not be opened, the error was printed but memtier still exited 0.

Fix

These files now follow the rule from #729 and #717:

  • Each file is flushed and checked through finish_output_file(). The other files are still written, and memtier exits 1.
  • --failed-keys-file fails at startup when it cannot be opened, or when its CSV header cannot be written. It prints error: cannot open --failed-keys-file PATH: REASON (or error: 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).
  • HDR and --client-stats files are only created when a run ends.
    • At startup, before connecting, memtier checks that the directory of each prefix is a writable directory. It uses stat() + S_ISDIR, then access(dir, W_OK | X_OK), and creates no file. A regular file in the directory's place is reported as Not a directory. On failure it prints error: 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 3600 run. --verify-only writes neither kind of file, so it skips the check.
    • 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 pass and is then only caught when the run ends.
    • A full disk, or a file that cannot be opened when the run ends, is reported then: error: cannot open --hdr-file-prefix file PATH: REASON, error: failed writing --client-stats file PATH: REASON, and so on.
    • For --client-stats, only the first failing file of a run is named. It is followed by error: N more --client-stats files could not be written, instead of one line per client (200 lines at the default -t 4 -c 50).
  • Exit-code precedence is unchanged: a connection-stage abort still exits 2, then a worker failure exits 1, then an output failure exits 1. g_output_failed replaces the local output_failed in main(), so that run_benchmark() can set it for the CSVs.
  • stdout_reader_gone() moves to file_io.cpp. A new close_output_file() applies it, so a --failed-keys-file on stdout whose reader went away (/dev/stdout and | head) only stops logging. This is the same exemption the results on stdout get.
  • The failed-keys logger singleton is now heap-allocated and never destroyed, and main() closes it explicitly. Before, its static destructor destroyed the mutex and freed m_path while a worker could still log after another thread called exit(). TSan reported use of an invalid mutex. This bug already existed before this PR. The paths that skip the join are the early exit() / exit(failure_exit_code()) ones, e.g. a thread that fails to prepare or a fatal error in a worker thread. On the normal path main() joins the workers and then closes the logger.
  • --help and memtier_benchmark.1 no 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:

  • These runs now exit 1 instead of 0:
  • A --failed-keys-file that cannot be opened now exits 1 at startup instead of running with a warning. Its message changes from warning: failed-keys-file '...' could not be opened (...); logging disabled. to error: cannot open --failed-keys-file PATH: REASON.
  • The record write message changes from warning: failed-keys-file '...' write failed (...) to error: failed writing --failed-keys-file PATH: REASON; logging disabled..
  • HDR and --client-stats open failures used to print in perror() format (PATH: REASON). They now print error: cannot open --hdr-file-prefix file PATH: REASON or error: cannot open --client-stats file PATH: REASON.
  • error: PATH: failed to write client stats. is gone.
  • A full-run .txt HDR file on a full disk can report Input/output error instead of ENOSPC. The hdr_histogram library writes it through many fprintf() calls, and stdio drops the real errno, as finish_output_file() documents.

Tests

New in tests/tests_oss_simple_flow.py:

  • test_hdr_file_write_error: /dev/full symlinks for h_FULL_RUN_1.txt, h_FULL_RUN_1.hgrm, h_SET_command_run_1.txt and h_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_error and test_hdr_arbitrary_command_file_write_error (--command): exactly one file fails at a time, the .txt or 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:
    • dropping g_output_failed for one writer;
    • ok = instead of ok &=;
    • ignoring one close result;
    • ok = in the --command loop.
  • test_client_stats_write_error: a /dev/full symlink for cs-1-0-0.csv.
  • test_hdr_file_prefix_missing_directory and test_client_stats_missing_directory: expect rc 1 at startup, with the cannot write ... directory message and no Preparing benchmark client line.
  • 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. Expects Not a directory at startup.
  • test_verify_only_skips_output_prefix_dir_check: a --verify-only run with missing prefix directories gets past the check. It runs standalone only, because --data-import does not support cluster mode.
  • test_hdr_file_open_error and test_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 by 2 more.
  • test_failed_keys_file_missing_directory: expects rc 1 at startup, with no Preparing benchmark client line.
  • 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 at RLIMIT_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_threads repeats this with -t 4 -c 4, so 16 connections log through the shared lock. Both tests skip if the hard RLIMIT_FSIZE is below 1 MiB.
  • test_failed_keys_file_stdout_reader_gone: a guard. /dev/stdout on a closed stdout pipe gives rc 0 and no error.
  • test_failed_keys_file_written: a guard. The same -OOM run 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):

  • On master: the regression tests fail, and the 2 guard tests pass. I checked this at 6a8099c.
  • Mutation checks, where every mutant fails at least one test:
    • the per-writer HDR mutants listed above;
    • dropping the --verify-only skip;
    • dropping the S_ISDIR check.
  • With the fix:
    • the 18 new tests: 5 runs out of 5 pass (standalone);
    • the new tests plus test_cluster_failed_keys.py on a 3-shard oss-cluster: 25/25, with the --verify-only test skipped;
    • full tests_oss_simple_flow.py: 77/77;
    • test_closed_std_fds.py, test_hdr_histogram.py, test_retry_on_error.py and test_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.

🤖 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-file now fail the benchmark (exit 1), aligning them with the existing rules for --out-file / --json-out-file (#719/#729).

--failed-keys-file opens 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 shared stdout_reader_gone() / close_output_file() moved into file_io.cpp.

HDR and --client-stats get a startup directory writability check (skipped for --verify-only); end-of-run open/write failures are reported through open_option_file / close_option_file, with remaining files still written. --client-stats reports only the first failing CSV plus a count of additional failures.

A global g_output_failed flag 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.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 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, --client-stats and --failed-keys-file now follow the same rule #717/#729 set for --out-file. I don't think the exit-code change needs to be argued again. The failed-keys one (a mid-run record failure now exits 1 instead of warning) is reasoned out in the description and matches what #729 already settled. The startup directory check also means a mistyped prefix no longer costs a whole long run. The tests do what we'd want for this kind of fix: the description says each one fails on master, and the single-file-per-writer cases were checked against specific mutants (ok = vs ok &=, a dropped g_output_failed). A few small things:

  • --client-stats: only the first failure is printed, and the rest become "N more ... could not be written" with no reason. That's fine for the common case where they all fail the same way (missing dir, full disk). If they fail for different reasons, though, the user only sees the first errno. I guess that's an acceptable trade against 200 lines of noise, just checking it was a deliberate choice.
  • check_output_prefix_dir() is called for --hdr-file-prefix and --client-stats, but --failed-keys-file covers the same case by actually opening the file. I think that asymmetry is right, since the prefix files only exist at the end of a run. The access() real-UID caveat is already in the README, so nothing to add there.
  • Nitpicking: now that global_failed_keys_logger() heap-allocates the instance and never deletes it, I believe ~failed_keys_logger() can no longer run. Is it worth a one-line comment on the destructor saying so, or dropping it, so nobody later "fixes" the leak by going back to a static instance? Your comment in global_failed_keys_logger() explains why, but it's not where someone reading the class would look.

I checked the moved --failed-keys-file open against the --out-file open/truncate ordering in main(). The comment is accurate: --out-file is opened without O_TRUNC and only truncated after --json-out-file is open, so a failed-keys open failure leaves it untouched.

None of these block it as far as I can see. It looks good to me.

@fcostaoliveira
fcostaoliveira force-pushed the fix/744-output-write-errors branch from ab05b77 to 171e6ec Compare October 17, 2026 01:29
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Point by point, as of 171e6ec:

  • Open failures known before the run: agreed, changed. --failed-keys-file now fails at startup, like --out-file (Fail at startup on an unwritable --out-file; open output files only after option validation #717). If it cannot be opened, or its header cannot be written, memtier prints error: cannot open --failed-keys-file PATH: REASON and exits 1 before connecting. The open also moved after option validation and the data import, so a later validation error leaves no new file behind. The HDR and --client-stats file names are built when a run ends, so those keep the end-of-run rule, and the README now says so. I also added tests for a missing directory with each of the three options.
  • Compat: covered by the release notes in the PR description, which now also list the changed messages: the HDR/CSV perror() format, and the removed error: PATH: failed to write client stats..
  • Stale errno: fixed. errno = 0 is now set before the record fprintf().
  • close() during static teardown: this is intended, and harmless. Records are flushed one at a time, so close() prints only when the final flush or fclose() fails, which is a real lost write. On an exit() path it can print at most one line.
  • maxmemory: the tests now save and restore the original value.

@fcostaoliveira
fcostaoliveira force-pushed the fix/744-output-write-errors branch from 171e6ec to ff1f450 Compare October 17, 2026 02:31
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
…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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Follow-up on the second pass, as of ff1f450:

  • (c) preexec_fn / RLIMIT_FSIZE: the limit is 1 MiB, and only the child memtier gets it. The other files the run writes stay far below that, including the coverage .gcda files. The ASan and coverage jobs pass. The tests now also skip cleanly when the hard limit is already below 1 MiB, so the preexec_fn concern stays theoretical.
  • (d) the extra blank lines before _symlink_to_dev_full: fixed.
  • Teardown print: this is gone entirely. The logger singleton is never destroyed now, and main() closes it explicitly. This also removes a use of a destroyed mutex at exit().

fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/744-output-write-errors branch from ff1f450 to c04e7a5 Compare October 17, 2026 03:24
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
…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]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Answers to the edited review, as of c04e7a5:

  • Exit 1 on a mid-run --failed-keys-file write error: keeping it, on purpose. A lost log is a lost output, the same rule as 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 user asked for this file, and it is the evidence of which keys failed. A script that relies on it, for example to replay or audit the failed keys, must not see success when the file is incomplete. A loud error with exit 0 would hide exactly the silent loss Write errors on --hdr-file-prefix files, --client-stats CSVs and --failed-keys-file are ignored: a full disk leaves empty/truncated files and the run exits 0 #744 is about. This differs from PR#60/PR#212 because there the old behaviour was correct and the new one was stricter. Here the old behaviour lost data and still reported success. The reasoning is now in the release notes as well.
  • HDR / --client-stats startup check: added. After option validation and before connecting, memtier now checks access(dir, W_OK | X_OK) on the directory of each prefix, creating no file. On failure it prints error: cannot write --hdr-file-prefix directory DIR: REASON (or --client-stats) and exits 1. A full disk is still only seen at the end of the run. The missing-directory tests now expect the startup exit with no "Preparing benchmark client" line. The end-of-run open failures are tested with a directory in the file's place (EISDIR).
  • Which paths skip the join: both comments now say so. The early exit() / exit(failure_exit_code()) paths skip it, for example a thread that fails to prepare (in run_benchmark()) or a fatal error in a worker thread (shard_connection.cpp). On those paths other workers may still be logging while exit() runs the static destructors, which is why the singleton is never destroyed. On the normal path main() joins the workers and then closes the logger.
  • stdout_reader_gone() with rc < 0: confirmed, it is valid. A stream in the error state still owns its fd, because only fclose() releases it, and write_failed_locked() calls stdout_reader_gone() before its fclose(). So fileno() returns the open fd, and fstat()/poll() work on it as usual. The error flag only affects later stdio calls on the stream, not the fd. Fail the run on write errors to --out-file, --json-out-file or stdout #729 uses the same order for stdout: check first, then fclose().
  • Commit message: the squash message will be taken from the PR body, which matches the code. The open error has no "; logging disabled." suffix, and only the mid-run record error has it.

fcostaoliveira and others added 5 commits October 17, 2026 04:56
…-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]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/744-output-write-errors branch from c04e7a5 to 4e6c36d Compare October 17, 2026 03:56
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On the re-edited review, as of 4e6c36d:

  • (a) An unopenable --failed-keys-file is fatal at startup, which breaks the old documented promise that "the benchmark continues if the file is unwritable". I weighed the two options:

    The help text and the man page no longer make the old promise, and the release notes call out the change.

  • (b) root / access(): the README and the code now say the startup directory check is best-effort. access() uses the real UID, so as root or on an NFS root_squash mount an unwritable directory can still only be caught at the end of the run. The check now also rejects a non-directory with ENOTDIR (... directory X: Not a directory), and --verify-only skips it.

  • (c) Logger lifetime: this fix stays in this PR. The new close-and-check path in main() needs a logger that is never destroyed under a still-running worker in order to be TSan-clean.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

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.

@fcostaoliveira
fcostaoliveira merged commit 2beefd0 into master Oct 17, 2026
129 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant