关于顺序写入的文件系统的一致性保证 [英] Consistency guarantee of file system regarding sequential write

查看:188
本文介绍了关于顺序写入的文件系统的一致性保证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序(只有1个进程和1个线程)使用普通的旧系统调用顺序将n个连续的数据块写入HDD(常规类型的HDD)上的文件。它就像是某种仅附加日志文件。

My program (only 1 process and 1 thread) sequentially write n consecutive chunks of data to a file on a HDD (regular kind of HDD) using plain old write system call. It's like some kind of append-only log file.

系统崩溃后(电源故障,而不是硬盘故障),我回过头来核实那些块[i]( 0< i< n)已完全写入磁盘(通过检查长度)。可能是块的内容不是校验和正确但仍然整个块[i]稳定地坐在磁盘的表面上。

After a system crash (power failure, not HDD failure), I read back and verified that chunks[i] (0 < i < n) had been entirely written down to disk (by checking length). May be the content of the chunk is not checksum correct but still the whole chunks[i] stably sit on the surface of the magnetic disk.

对我来说是否安全假设在chunks [i]完全写下来之前所有其他块?或者存在(或许多)块[j](0< j< i)部分(或根本不)写入磁盘?我知道可以重新排序随机写入以提高磁盘吞吐量,但也可以重新排序顺序写入吗?

Is it safe for me to assume all other chunks before chunks[i] are entirely written down too? Or there exists a (or many) chunks[j] (0 < j < i) that is partly (or isn't at all) written down to disk? I know that random writes could be reordered to improve disk throughput but could sequential writes be reordered too?

推荐答案

是的,写出来顺序(给你)可以在写入磁盘之前重新排序,主要是因为你的代码(甚至操作系统)看到的顺序可能不直接对应磁盘上的位置。

Yes, writes that appear sequential (to you) can be reordered before being written to disk, primarily because the order seen by your code (or even the OS) may not correspond directly to locations on the disk.

尽管IDE磁盘(一次)使用基于指定将保存一条数据的磁道,磁头和扇区的寻址,但它们很久以来转换为只有一些扇区的系统,并且由磁盘来排列那些有意义的顺序。它通常做得很好,但在某些情况下(特别是如果一个扇区变坏并被备用扇区取代),最不合理的是写扇区。

Although IDE disks did (at one time) use addressing based on specifying a track, head and sector that would hold a piece of data, they've long since converted to a system where you just have some number of sectors, and it's up to the disk to arrange those in an order that makes sense. It usually does a pretty good job, but in some cases (especially if a sector has gone bad and been replaced by a spare sector) it may make the most sense to write sectors out of order.

这篇关于关于顺序写入的文件系统的一致性保证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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