views:

44

answers:

1

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

A: 

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

ruslik