磁盘扇区写入是否原子? [英] Are disk sector writes atomic?

查看:238
本文介绍了磁盘扇区写入是否原子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

澄清的问题:

当操作系统发送将扇区写入磁盘的命令是原子时即新数据的写入完全成功,或者如果电源在写入命令之后立即失败,则旧数据保持不变。我不关心在多个部门写入中会发生什么 - 撕裂的页面是可以接受的。

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 power fail immediately following the write command. I don't care about what happens in multiple sector writes - torn pages are acceptable.

旧问题:

假设您在磁盘上有旧数据X,您在其上写入新数据Y,并且在写入期间树将落在电源线上。没有华丽的UPS或电池支持的磁盘控制器,你可以最终有一个撕裂的页面,其中磁盘上的数据是X部分和Y部分。你可能会遇到磁盘上的数据是部分X,部分Y ,和一部分垃圾?

Say you have old data X on disk, you write new data Y over it, and a tree falls on the power line during that write. With no fancy UPS or battery backed disk controller, you can end up with a torn page, where the data on disk is part X and part Y. Can you ever end up with a situation where the data on disk is part X, part Y, and part garbage?

我一直在试图理解ACID系统的设计,像数据库,和我的天真的想法,它似乎firebird,不使用写入日志,是依赖于给定的写将不会破坏旧数据(X) - 只能无法完全写入新数据(Y)。这意味着如果X的一部分被覆盖,只有被覆盖的X的部分可以改变,而不是我们打算保留的X的那部分。

I've been trying to understand the design of ACID systems like databases, and to my naive thinking, it seems firebird, which does not use a write-ahead log, is relying that a given write will not destroy old data (X) - only fail to fully write new data (Y). That means that if part of X is being overwritten, only the part of X that is being overwritten can be changed, not the part of X we intend to keep.

To澄清,这意味着如果你有一个页面大小的缓冲区,比如4096字节,填充了一半Y,一半X,我们要保持 - 我们告诉操作系统写该缓冲区X,没有严重的磁盘故障

To clarify, this means if you have a page sized buffer, say 4096 bytes, filled with half Y, half X that we want to keep - and we tell the OS to write that buffer over X, there is no situation short of serious disk failure where the half X that we want to keep is corrupted during the write.

推荐答案

没有人似乎同意这个问题。所以我花了很多时间尝试不同的Google查询,直到我终于找到了答案。

Nobody seems to agree on this question. So I spent a lot of time trying different Google queries until I finally found an answer.

来自Dr. Stephen Tweedie,RedHat员工和linux内核文件系统和虚拟内存开发人员一个关于ext3的讲座(他开发了)这里的成绩。如果有人知道,那就是他。

from Dr. Stephen Tweedie, RedHat employee and linux kernel filesystem and virtual memory developer in a talk on ext3 (which he developed) transcript here. If anyone knows, it'd be him.

只是把这件事写到杂志上是不够的,因为在杂志上有一些标记:好,(这个日志记录实际上)这个日志记录是否真的表示一个完整的磁盘的一致性?你这样做的方式是通过一些原子操作标记事务在磁盘上完成[23m,14s]

"It's not sufficient just to write the thing to the journal, because there's got to be some mark in the journal which says: well, (has this journal record actually) does this journal record actually represent a complete consistency to the disk? And the way you do that is by having some atomic operation which marks that transaction as being complete on disk" [23m, 14s]

现在,磁盘这些天实际上提供了这些保证。如果你开始对磁盘的写操作,那么即使在该扇区写入的中间电源出现故障,磁盘有足够的可用功率,它实际上可以从主轴的旋转能量窃取电力;它有足够的电力来完成正在写入的扇区的写入。在所有情况下,磁盘做出了保证。 [23m,41s]

"Now, disks these days actually make these guarantees. If you start a write operation to a disk, then even if the power fails in the middle of that sector write, the disk has enough power available, and it can actually steal power from the rotational energy of the spindle; it has enough power to complete the write of the sector that's being written right now. In all cases, the disks make that guarantee." [23m, 41s]

这篇关于磁盘扇区写入是否原子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆