2929
3030namespace {
3131// / Open a file using the specified path and return it
32- arrow::Result<std::shared_ptr<arrow::io::OutputStream>>
33- open_file_output_stream (std::string const & path, bool append, bool use_directio = true )
32+ arrow::Result<std::shared_ptr<arrow::io::OutputStream>> open_file_output_stream (
33+ std::string const & path,
34+ bool append,
35+ bool use_directio = true ,
36+ bool use_sync_io = false )
3437{
3538#ifdef __linux__
3639 auto flags = use_directio ? O_RDWR | O_DIRECT : O_RDWR;
3740
3841 flags |= (append == true ? O_APPEND : O_CREAT);
42+ if (use_sync_io) {
43+ flags |= O_SYNC;
44+ }
3945
4046 int fd = open (path.c_str (), flags, 0644 );
4147
@@ -55,11 +61,13 @@ open_file_output_stream(std::string const & path, bool append, bool use_directio
5561std::shared_ptr<arrow::io::OutputStream> make_async_stream (
5662 std::shared_ptr<arrow::io::OutputStream> const & io_stream,
5763 std::shared_ptr<pod5::ThreadPool> thread_pool,
58- bool use_directio = true )
64+ bool use_directio,
65+ std::size_t directio_chunk_size)
5966{
6067#ifdef __linux__
6168 if (use_directio) {
62- return std::make_shared<pod5::AsyncOutputStreamDirectIO>(io_stream, thread_pool);
69+ return std::make_shared<pod5::AsyncOutputStreamDirectIO>(
70+ io_stream, thread_pool, directio_chunk_size);
6371 } else {
6472 return std::make_shared<pod5::AsyncOutputStream>(io_stream, thread_pool);
6573 }
@@ -79,6 +87,8 @@ FileWriterOptions::FileWriterOptions()
7987, m_read_table_batch_size(DEFAULT_READ_TABLE_BATCH_SIZE)
8088, m_run_info_table_batch_size(DEFAULT_RUN_INFO_TABLE_BATCH_SIZE)
8189, m_use_directio{DEFAULT_USE_DIRECTIO}
90+ , m_directio_chunk_size(DEFAULT_DIRECTIO_CHUNK_SIZE)
91+ , m_use_sync_io(DEFAULT_USE_SYNC_IO)
8292{
8393}
8494
@@ -552,13 +562,14 @@ pod5::Result<std::unique_ptr<FileWriter>> create_file_writer(
552562 auto run_info_tmp_path = make_run_info_tmp_path (arrow_path, file_identifier);
553563
554564 bool const use_directio = options.use_directio ();
565+ bool const use_sync_io = options.use_sync_io ();
555566
556567 // Prepare the temporary reads file:
557568 ARROW_ASSIGN_OR_RAISE (
558569 auto read_table_file_stream,
559- ::open_file_output_stream (reads_tmp_path, false , use_directio));
560- auto read_table_file_async =
561- ::make_async_stream ( read_table_file_stream, thread_pool, use_directio);
570+ ::open_file_output_stream (reads_tmp_path, false , use_directio, use_sync_io ));
571+ auto read_table_file_async = :: make_async_stream (
572+ read_table_file_stream, thread_pool, use_directio, options. directio_chunk_size () );
562573 ARROW_ASSIGN_OR_RAISE (
563574 auto read_table_tmp_writer,
564575 make_read_table_writer (
@@ -573,9 +584,9 @@ pod5::Result<std::unique_ptr<FileWriter>> create_file_writer(
573584 // Prepare the temporary run_info file:
574585 ARROW_ASSIGN_OR_RAISE (
575586 auto run_info_table_file_stream,
576- ::open_file_output_stream (run_info_tmp_path, false , use_directio));
577- auto run_info_table_file_async =
578- ::make_async_stream ( run_info_table_file_stream, thread_pool, use_directio);
587+ ::open_file_output_stream (run_info_tmp_path, false , use_directio, use_sync_io ));
588+ auto run_info_table_file_async = :: make_async_stream (
589+ run_info_table_file_stream, thread_pool, use_directio, options. directio_chunk_size () );
579590
580591 ARROW_ASSIGN_OR_RAISE (
581592 auto run_info_table_tmp_writer,
@@ -587,8 +598,10 @@ pod5::Result<std::unique_ptr<FileWriter>> create_file_writer(
587598
588599 // Prepare the main file - and set up the signal table to write here:
589600 ARROW_ASSIGN_OR_RAISE (
590- auto signal_table_file_stream, ::open_file_output_stream (path, false , use_directio));
591- auto signal_file = ::make_async_stream (signal_table_file_stream, thread_pool, use_directio);
601+ auto signal_table_file_stream,
602+ ::open_file_output_stream (path, false , use_directio, use_sync_io));
603+ auto signal_file = ::make_async_stream (
604+ signal_table_file_stream, thread_pool, use_directio, options.directio_chunk_size ());
592605
593606 // Write the initial header to the combined file:
594607 ARROW_RETURN_NOT_OK (combined_file_utils::write_combined_header (signal_file, section_marker));
0 commit comments