Async writer, how do writes and fsync interleve

Yet another how to async question :slight_smile:

I’m trying to write a relatively low latency write ahead log. I had it running in Lwt but after seeing how high performance the rpc library was I am porting it over to Async.

My question is whether Async.Writer.fdatasync flushes previous writes to disk before calling fdatasync? I’d expect so but I can’t see anything confirming that, and I haven’t found the code yet either.

The code is right here: https://github.com/janestreet/async_unix/blob/master/src/writer0.ml#L1486

And it’s pretty clear, I think: first flush all the data, then call fdatasync.

let fdatasync t =
  ensure_can_write t;
  let%bind () = flushed t in
  Unix.fdatasync t.fd
;;

That said, it’s embarrasingly undocumented. A PR with clearer docs would be warmly accepted!

Brilliant thanks! Seems like the phrase “code is the best documentation” strikes again :slight_smile:

Thanks for pointing me to the repo, I have had some issues finding the ‘raw code’ for various jane street libraries, but am slowly finding my way around, the async_unix library was one of the big ones.