Can I guarantee atomic addition in Ruby?

Based Is the append file atomic on UNIX? and other sources, it looks like modern Linux, I can open the file in add mode and write small fragments (< PIPE_BUF) to it from several processes, without worrying about the break.

Are these Ruby limits limited by syswrite? In particular, for this code:

f = File.new('...', 'a')
f.syswrite("short string\n")

Is it possible to expect that the record will not alternate with another process written the same way? Or is there some kind of buffering / potential splitting that I don't know about yet?

Assuming ruby> = 2.3

+4
source share
2 answers

. syswrite write POSIX, .

: POSIX 'read() write() Atom?

Tl; dr- concurrency , .

+1

, File appender Rackstash.

, , , , , , , . , .

(1) (2) , , .

:

  • . ( ) . , . # flock.
  • . , HFS, APFS, NTFS Linux, ext3, ext4, btrfs,..., . SMB - , . NFS FUSE .

, , . , .

( ), PIPE_SIZE. , , , , STDOUT .

, . ( SO) . ( ), .

, : , . , syswrite . , f.sync = true , , .

, Mutex ( ), ( append- , , ).

+1

Source: https://habr.com/ru/post/1694558/


All Articles