简体   繁体   English

ntfs 但不是 ext3 的数据完整性问题

[英]data integrity issue with ntfs but not ext3

In my application I am continually writing data to file1 and flushing it to the device.在我的应用程序中,我不断将数据写入file1并将其刷新到设备。 In another thread, I am reading data from file1 and writing it to file2 .在另一个线程中,我正在从file1读取数据并将其写入file2

Every time I do the fwrite + fflush on file1, I signal to the other thread to start reading from it.每次我在 file1 上执行fwrite + fflush时,我都会向另一个线程发出信号以开始从中读取。 The other thread reads data from file1 and dumps it into file2.另一个线程从file1 中读取数据并将其转储到file2 中。 Pretty simple logic.很简单的逻辑。 Additionally, after every few minutes, I seek back to start of file1 and start overwriting old data.此外,每隔几分钟,我就会回到 file1 的开头并开始覆盖旧数据。

Now my problem is that once I start overwriting data in file1 , the data read into file2 is sometimes the old data (ie data written in the previous iteration) even though writer thread has signaled that it wrote the new data (and flushed it).现在我的问题是,一旦我开始覆盖file1中的数据,读入 file2 的数据有时是旧数据(即在前一次迭代中写入的数据),即使写入器线程已经发出信号表示它写入了新数据(并刷新了它)。

I am writing to and reading from a solid state drive (128 GB SAMSUNG 470 Series, if that helps) on [C + linux + arm platfrom].我正在 [C + linux + ZF926B3E222D7AFEE57071B256839701] 上的固态 state 驱动器(128 GB SAMSUNG 470 系列,如果有帮助的话)写入和读取。 I feel that there is an issue with the processor cache.我觉得处理器缓存有问题。 Perhaps the write goes into the cache and the read by the reader thread comes from the flash, and hence the stale data.也许写入进入缓存,读取线程的读取来自 flash,因此是陈旧数据。

The catch here is that this problem occurs if the SSD is formatted with NTFS.这里的问题是,如果 SSD 使用 NTFS 格式化,则会出现此问题。 If I format it with ext3, the problem goes away.如果我用 ext3 格式化它,问题就消失了。 Unfortunately, NTFS is a hard requirement.不幸的是,NTFS 是一项硬性要求。 Another interesting observation is that if I have two reader threads, both get stale data at different instants.另一个有趣的观察是,如果我有两个阅读器线程,它们都会在不同的时刻获得陈旧的数据。

Event after disabling the SSD write cache (with hdparm -W0 /dev/sda1 ), I get the same problem with NTFS.禁用 SSD 写入缓存(使用hdparm -W0 /dev/sda1 )后的事件,我遇到了与 NTFS 相同的问题。 I am badly stuck up with this since more than a week.一个多星期以来,我一直坚持这一点。

Any idea what is happening, and why is it happening that way?知道发生了什么,为什么会这样?

Any help will be worth its weight in gold...任何帮助都将物超所值……

EDIT Turns out that the NTFS driver does not like me overwriting a file by rewinding the file pointer.编辑原来NTFS驱动程序不喜欢我通过倒回文件指针来覆盖文件。 Is this a known thing?这是众所周知的事情吗?

Ok, so I found the issue myself (and how rarely does that happen.!!).好的,所以我自己发现了这个问题(而且这种情况很少发生。!!)。

I found that there was a problem with the C library buffering (fread/fwrite).我发现 C 库缓冲(fread/fwrite)存在问题。 So I do fflush() before every fread().所以我在每个 fread() 之前做 fflush()。 This solves my problem (I don't know what exactly went wrong with the driver but I am assuming that there is some issue with the "read" buffering of the C library I/O functions, when reading from the same location of the file second time around).这解决了我的问题(我不知道驱动程序到底出了什么问题,但我假设从文件的相同位置读取时 C 库 I/O 函数的“读取”缓冲存在一些问题第二次)。

Thanks @Asad Rasheed and @jrtipton for your inputs:)感谢@Asad Rasheed 和@jrtipton 的投入:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM