- update-in-place should be considered dangerous by all programmers, as the following example will show.
Suppose we have the following hex data, and we wish to update a certain portion of it, highlighted in green:
If we assume this device writes in 32 byte blocks (a row in this table) then the update to byte(the first highlighted byte, ) might (due to block caches and fragmentation) separately to the three bytes of the write starting in the next 32 byte block, at onwards.
If the operating system crashes between these writes the data will readwhere is whatever was written before the crash, this is bad because neither the old or the new data exists!
Power cuts rarely considered (often an OS crash is seen as the only event involved in durability, and as such it becomes about atomic block operations) but power can cut out, drives have caches that wont survive this, nor will the block cache.
As such update-in-place should be considered dangerous by all programmers
It is desirable to have a situation where, in the event of a crash:
- if the write (or writes) didn't complete, the old data is considered "active" and used, and
- only if the write (or writes) completed do we see this new data.