Commit 214baf1
committed
Fsync frame data in wallog before writing header
Currently in logger.rs we are not issuing any fsyncs at all.
We do `flush()` in `write_header()` but this is a no-op on Unix
because there are no userspace buffers to flush since `write_all_at()`
writes directly to kernel.
Not fsyncing can cause the following bug:
- We write X frames
- We write wallog header (containing frame count X)
- Kernel reorders writes so that header has been written out
but not all of the frame data
- Crash
- Sqld starts up, reads wallog header which claims X frames
exist in wallog, but only Y frames (Y < X) have been written
- short read in read_frame_byte_offset_mut() returns an error
and crashes the server
It's also important to sync after writing frames but before
writing the header so that there is no write reordering scenario
where the header is persistent before the frame data is.1 parent 2d50cd0 commit 214baf1
1 file changed
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| |||
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| 200 | + | |
196 | 201 | | |
197 | 202 | | |
198 | 203 | | |
| |||
387 | 392 | | |
388 | 393 | | |
389 | 394 | | |
390 | | - | |
| 395 | + | |
391 | 396 | | |
392 | 397 | | |
393 | 398 | | |
| |||
0 commit comments