-
We are on x86_64 linux.
-
Consider the following API:
pub struct Record(Vec<u8>)
pub struct SafeFileReader {}
pub struct SafeFileWriter {}
impl SafeFileWriter {
pub fn new(s: &str) -> SafeFileWriter {}
pub fn write(&mut self, r: &Record) {}
}
impl SafeFileReader {
pub fn new(s: &str) -> SafeFileReader {}
pub fn read_all(&mut self) -> Vec<Record> {}
}
- We want the following requirement. For any record r_0, r_1, .., r_k, r_{k+1} and any crash style C, we want the following guarantee:
-
the calls on
write(r_0), write(r_1), ... write(r_k)
return -
during the call on
write(r_{k+1})
, the system crashes due to C -
then, when we do a read on the file, we want it return either
[r_0, r_1, ..., r_k]
or[r_0, r_1, ..., r_k, r_{k+1}]
===
By writing out record r = Vec<u8>
as (r.len(), checksum(r), r)
we can easily detect partially written records (and ignore them.) That is not my concern.
My concern is as follows: when writing record r_{k+1}
, and the machine crashes, what is it that guarantees us that the data written in r_0, ..., r_k
are not corrupted.
We can assume that our program is the only program editing the file. My main concern here is what promises kernel / filesystem makes to us regarding writing records to files.