分析断电时文件操作flush不能写入硬盘数据丢失问题

一般写文件时,为了确保程序退出时也能把文件写到硬盘,都要在程序中加flush强制把内存缓存写到硬盘中,但这个flush只对内存缓存起作用,当遇到突然断电,还是不能保证已经写到物理硬盘上了。

现象:比如写一个文本文件a.txt,程序调用了flush,用notepad直接打开文件a.txt,可以看到flush的内容已经写到a.txt了,然后关掉notepad切断电源,然后再同上电源开机打开a.txt,可能会发现flush的内容又没有了,但这种情况不是每次都出现,跟flush和断电的时间间隔有关系。

原因:flush只是强制把内存缓存写到硬盘中,不能保证真正写入物理硬盘,一般物理硬盘内部都有一定的磁盘缓存,当看到a.txt的flush内容时可能只是磁盘缓存。

解决办法:应该说没有完美的解决办法,如果把磁盘缓存关闭,会大大降低整个系统包括操作系统的运行效率。一般大型服务器使用磁盘阵列等存储设备时磁盘缓存会更大,根本不能关闭,所以他们是通过UPS等备用电源来保障不出现断电问题,即使真的完全断电,他们也没有办法,只能丢失增量部分数据;另外,对于普通客户端系统,可以考虑备份机制,最好用追加的方式写文件,不要对整个文件改写,这样即使断电也只丢失增量部分数据。

116人评论了“分析断电时文件操作flush不能写入硬盘数据丢失问题”

  1. I would like to point out my respect for your generosity giving support to those people that really need assistance with this particular niche. Your real dedication to getting the solution around has been certainly functional and have consistently helped professionals much like me to realize their ambitions. Your amazing warm and helpful help entails a great deal a person like me and still more to my colleagues. Thanks a ton; from everyone of us.

  2. Thanks a lot for providing individuals with an extraordinarily nice opportunity to read from this blog. It really is very useful and stuffed with fun for me and my office co-workers to search your web site at a minimum thrice weekly to read through the latest issues you have. And indeed, I’m also certainly pleased with your brilliant creative concepts you serve. Selected 3 tips in this article are unquestionably the most impressive I have had.

  3. I simply desired to thank you very much once again. I do not know the things I might have gone through without the entire information discussed by you about such situation. It had been a real frightening difficulty in my view, nevertheless observing the very professional technique you handled that took me to cry for gladness. I am happy for the advice and even believe you recognize what a powerful job you are doing teaching the others through the use of your webpage. I am certain you have never come across any of us.

  4. I am glad for commenting to let you be aware of what a fantastic discovery my wife’s child undergone visiting your web site. She came to understand such a lot of things, which included how it is like to have a marvelous giving style to get folks clearly learn selected very confusing subject matter. You actually exceeded our own expectations. I appreciate you for giving those powerful, trustworthy, edifying and even cool tips about your topic to Gloria.

  5. I simply desired to appreciate you once more. I am not sure the things that I would’ve accomplished in the absence of those concepts documented by you relating to such field. This was a very intimidating concern in my circumstances, nevertheless discovering the specialized mode you processed the issue took me to leap with joy. Extremely thankful for your guidance and as well , pray you find out what a great job you happen to be undertaking teaching the others via your blog. More than likely you have never got to know all of us.

  6. A lot of thanks for your entire hard work on this web site. My aunt really loves setting aside time for research and it’s really easy to see why. A lot of people know all about the compelling method you make great tips and tricks via this blog and as well as inspire contribution from the others on that subject matter plus our favorite child is without a doubt studying a lot. Enjoy the remaining portion of the year. Your performing a powerful job.

  7. I precisely desired to appreciate you once more. I’m not certain the things I would have implemented without those tactics shared by you regarding my field. It was before the frightful issue in my position, but being able to see a skilled technique you handled that took me to leap with joy. I’m just happier for this assistance as well as hope that you are aware of a great job you are putting in training the rest all through your web blog. More than likely you haven’t encountered all of us.

  8. I as well as my buddies have already been reviewing the excellent techniques on your site while the sudden I got a horrible feeling I never thanked you for those secrets. All the boys had been so stimulated to read all of them and have really been taking pleasure in them. Appreciation for genuinely well accommodating and for picking this sort of important topics most people are really eager to learn about. Our own honest apologies for not expressing appreciation to you earlier.

  9. I precisely desired to appreciate you yet again. I’m not certain the things that I would have undertaken without the actual basics provided by you over such a problem. It had been a very frustrating scenario in my opinion, nevertheless viewing the specialized strategy you dealt with that took me to weep over contentment. Now i’m grateful for this work and then pray you are aware of a great job that you’re undertaking training the others via your web blog. I know that you have never got to know all of us.

  10. I truly wanted to write down a simple comment to say thanks to you for all of the remarkable ways you are writing at this website. My prolonged internet look up has at the end of the day been paid with extremely good facts to go over with my company. I ‘d repeat that we readers actually are undoubtedly blessed to be in a remarkable place with many special individuals with useful concepts. I feel really fortunate to have seen your entire website page and look forward to so many more pleasurable times reading here. Thanks again for all the details.

  11. I am only writing to let you understand of the fantastic discovery my wife’s child obtained studying your web page. She picked up a lot of details, not to mention what it is like to possess a marvelous coaching style to have the others completely know selected complex things. You truly did more than readers’ expectations. Many thanks for presenting these warm and friendly, trustworthy, revealing not to mention fun tips about the topic to Janet.

  12. Thank you for all your effort on this website. My mom really loves doing investigation and it is easy to see why. My spouse and i learn all about the lively medium you create both interesting and useful steps by means of this blog and even welcome response from some other people on that matter so our princess is truly being taught a whole lot. Have fun with the rest of the new year. Your doing a terrific job.

  13. I would like to show appreciation to you just for rescuing me from this type of predicament. Right after searching through the the net and finding methods which are not helpful, I assumed my life was well over. Living without the answers to the difficulties you’ve solved as a result of your good posting is a critical case, as well as those which may have in a negative way affected my career if I hadn’t noticed your web site. Your expertise and kindness in maneuvering every part was tremendous. I don’t know what I would’ve done if I had not come upon such a step like this. I am able to at this point look forward to my future. Thank you so much for the impressive and amazing guide. I will not hesitate to suggest your blog post to anyone who desires care on this issue.

  14. Thanks a lot for giving everyone an extremely pleasant opportunity to read from here. It is often so nice and also jam-packed with a good time for me and my office friends to visit your blog really three times weekly to study the newest guidance you will have. And lastly, I am also usually astounded with your impressive tips and hints served by you. Some 2 ideas in this post are particularly the most efficient we have ever had.

  15. This website online can be a stroll-by way of for all of the info you wished about this and didn抰 know who to ask. Glimpse right here, and also you抣l undoubtedly uncover it.

发表评论

电子邮件地址不会被公开。 必填项已用*标注