Bug 965317 - Add way to patch File class so all files have sync enabled.

After some tests and examining the C code, it appears as though the following happens:

File.open(...) do |file|
  file.write(...)
end

Has a chance of the string passed to write being duplicated in io.c.  There's even some code and a comment in io.c pertaining to the issue.


Setting File::SYNC on open doesn't help.  Nor does calling sync, or fsync after the write.

Surprisingly, File::SYNC does not appear to toggle sync on the IO object though it does cause the underlying system open to use O_SYNC.

File.open("foo",  File::RDWR|File::CREAT|File::TRUNC|File::SYNC) do |f| 
  puts "#{f.sync.inspect}"
end

...returns "false".

Setting f.sync=true does appear to help.

This has been observed to affect the following file operations:
1. Creating gear variables.
2. Writing Apache databases in FrontendHttpServer
3. NodeLogger

It is suspected that the problem has also happened during ERB file processing.

I believe that this problem potentially affects any file write orchestrated by the node code that happens with high concurrency or under a load.

This includes:
1. Anything done through mcollective
2. oo-admin-ctl-gears

Because of the pervasive nature of the problem, it is proposed that a module be created to monkey patch File to set sync=true on the resulting IO object in open and new.