0

I was doing some research on how databases prevents dataloss from writing to page cache using mmap. I don't understand how the memory mapped not lost upon crashing. Could anyone tell me how it really works?

10
  • Upon what crashing? The database program? Some hardware component? The whole machine? Commented Dec 19, 2018 at 21:09
  • @JohnBollinger I'm sorry. I mean the database program crashes (like "kill -9"), not crashes of hardware or the whole machine. Commented Dec 19, 2018 at 21:13
  • Duplicate of stackoverflow.com/questions/5877797/how-does-mmap-work ? Maybe? Commented Dec 19, 2018 at 21:26
  • 2
    Re. msync: Without use of this call, there is no guarantee that changes are written back before munmap(2) is called. But, munmap is [implicitly/effectively] called when the program is terminated. msync is only if you wish to force the flush early. As to partial data, that is different. If you write byte 0 to page A but get killed before writing byte 1 to page B (or page A for that matter), only the first byte will be flushed Commented Dec 19, 2018 at 22:31
  • 2
    Loosely, in general, to prevent data loss, databases write out things in a precise order, do a sync, then do more data. (e.g.) they write a journal record, force a sync to disk, then rewrite the actual data to a block. The data is written to a different block [so the original data is still in the old block], and then the block mapping is changed and written to disk. So, the database stays whole. It either sees the old state or the new state but not a partial mixing. And, recovery is possible because of the journal. This is mostly for system crashes Commented Dec 19, 2018 at 22:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.