Are disk sector writes atomic?

前端 未结 9 1336
名媛妹妹
名媛妹妹 2020-12-22 20:31

Clarified Question:

When the OS sends the command to write a sector to disk is it atomic? i.e. Write of new data succeeds fully or old data is left intact should the

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 20:49

    No, they are not. Worse yet, disks may lie and say the data is written when it is in fact in the disk cache, under default settings. For performance reasons, this may be desirable (actual durability is up to an order of magnitude slower) but it means if you lose power and the disk cache is not physically written, your data is gone.

    Real durability is both hard and slow unfortunately, since you need to make at least one full rotation per write, or 2+ with journalling/undo. This limits you to a couple hundred DB transactions per second, and requires disabling write caching at a fairly low level.

    For practical purposes though, the difference is not that big of a deal in most cases.

    See:

    • How (not) to achieve durability.
    • FSync() may not flush to disk

提交回复
热议问题