Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the data in a memory-mapped file guaranteed to flush sequentially?

I'm trying to implement a file storage mechanism which holds a number of variably-sized records in a single file with the guarantee that the set of records will always be recoverable into a consistent state, even if the system failed at a hardware level.

So far, every scheme I've come up with pivots on writing data sequentially. Some piece of data would be appended to the end of each record which confirms that the write succeeded. However, if the data is not necessarily written to the disk sequentially when flushed then it would be possible for the confirmation data to be written before the content data.

There are two obvious ways around this, but both are undesirable:

  1. Flush the content, then write the confirmation and flush it. Adding the extra flush may degrade performance.
  2. Include a checksum in the confirmation (would require reading the content to confirm that it is valid).

I'm using C# on Windows (32 and 64-bit) and .Net 4.0's memory mapped file implementation

like image 803
Kennet Belenky Avatar asked Nov 15 '22 08:11

Kennet Belenky


1 Answers

This is too low level and OS specific for C#. try using Windows APIs from C, and read very carefully the API specifiations.

like image 121
ruslik Avatar answered Dec 15 '22 23:12

ruslik