diff --git a/writer/FileWriter.cpp b/writer/FileWriter.cpp index a566cc01..6e55f9b5 100644 --- a/writer/FileWriter.cpp +++ b/writer/FileWriter.cpp @@ -222,37 +222,24 @@ void FileWriter::CheckOutputFilesAvailable(const StartMessage &msg, FileWriterFo if (msg.overwrite.value_or(false)) return; - // Checked by the single writer that owns the master file (write_master_file - index 0 in a - // multi-writer TCP/ZMQ setup), and it checks the whole run, its siblings' data files included. - // Data files are staggered across writers by file number, so letting each writer check its own - // would race the siblings already creating them; one writer can speak for all of them because - // the master links the data files by relative name, so they share a directory by construction. + // Only the master file is checked, and only by the single writer that owns it (write_master_file + // - index 0 in a multi-writer TCP/ZMQ setup). Enumerating the data files instead would make one + // writer stat every file of the run: thousands of lookups for a long run with a small + // images_per_file, which on a network filesystem overruns the pre-flight's ACK budget and refuses + // an output that was perfectly writable. Those conflicts are caught per-writer at finalize. if (!msg.write_master_file.value_or(false)) return; - auto refuse = [](const std::string &name) { - if (std::filesystem::exists(name)) - throw JFJochException(JFJochExceptionCategory::FileWriteError, - "Output file already exists and overwrite is off: " + name); - }; - const bool nxmx = format == FileWriterFormat::NXmxLegacy || format == FileWriterFormat::NXmxVDS || format == FileWriterFormat::NXmxIntegrated; - - if (nxmx) - refuse(HDF5Metadata::MasterFileName(msg)); - - // NXmxIntegrated puts the images in the master file, so there are no data files to check. - if (format == FileWriterFormat::NXmxIntegrated || format == FileWriterFormat::NoFile) + if (!nxmx) return; - const int64_t per_file = msg.images_per_file > 0 - ? msg.images_per_file - : static_cast(default_images_per_file); - const int64_t total_images = static_cast(msg.number_of_images); - for (int64_t file_number = 0; file_number * per_file < total_images; file_number++) - refuse(HDF5Metadata::DataFileName(msg, file_number)); + const std::string name = HDF5Metadata::MasterFileName(msg); + if (std::filesystem::exists(name)) + throw JFJochException(JFJochExceptionCategory::FileWriteError, + "Output file already exists and overwrite is off: " + name); } void FileWriter::Preflight(const StartMessage &request, bool trusted_path) {