不带fsync()的rename()是否安全? [英] Is rename() without fsync() safe?
本文介绍了不带fsync()的rename()是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在不先调用fsync(tmppath_fd)
的情况下调用rename(tmppath, path)
是否安全?
Is it safe to call rename(tmppath, path)
without calling fsync(tmppath_fd)
first?
我希望路径始终指向完整的文件. 我主要关心 Ext4 .是否可以在以后的所有Linux内核版本中都保证reset()是安全的?
I want the path to always point to a complete file. I care mainly about Ext4. Is the rename() promised to be safe in all future Linux kernel versions?
Python中的用法示例:
A usage example in Python:
def store_atomically(path, data):
tmppath = path + ".tmp"
output = open(tmppath, "wb")
output.write(data)
output.flush()
os.fsync(output.fileno()) # The needed fsync().
output.close()
os.rename(tmppath, path)
推荐答案
否.
查看libeatmydata,以及此演示文稿:
Look at libeatmydata, and this presentation:
http://www.oscon.com/oscon2008/public/schedule/detail/3172
来自MySql的Stewart Smith.
by Stewart Smith from MySql.
如果它离线/不再可用,我会保留一份副本:
In case it is offline/no longer available, I keep a copy of it:
- The video here
- The presentation slides (online version of slides)
这篇关于不带fsync()的rename()是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文