简体   繁体   English

NFS-来自两个客户端的mv命令文件损坏?

[英]NFS - mv command from two clients file corruption?

I have a basic script that I want to do the following : 我有一个想要执行以下操作的基本脚本:

  1. if new/file.txt exists 如果new / file.txt存在
  2. mv new/file.txt current/file.txt mv new / file.txt当前/file.txt

Now - if 2 servers were to run this same script at the same exact time (having access to the same NFS file share) : 现在-如果2台服务器要在相同的确切时间运行相同的脚本(可以访问相同的NFS文件共享):

  • Server 1 - step 1. checks if file exists. 服务器1-步骤1。检查文件是否存在。 True 真正
  • Server 2 - step 1. checks if file exists. 服务器2-步骤1.检查文件是否存在。 True 真正
  • Server 1 - step 2. starts to perform the "mv" command 服务器1-步骤2。开始执行“ mv”命令
  • Server 2 - step 2. ???? 服务器2-步骤2。

From what I can find online, it looks like an error would just get thrown by Server 2 - but no file corruption or anything should be of concern : http://nfs.sourceforge.net/ 从我在网上可以找到的内容来看,服务器2似乎只会引发错误-但没有文件损坏或任何值得关注的问题: http : //nfs.sourceforge.net/

The file handle refers to a deleted file. 文件句柄是指已删除的文件。 After a file is deleted on the server, clients don't find out until they try to access the file with a file handle they had cached from a previous LOOKUP. 在服务器上删除文件后,客户端只有在尝试使用从上一个LOOKUP缓存的文件句柄来访问文件时,才会发现该文件。 Using rsync or mv to replace a file while it is in use on another client is a common scenario that results in an ESTALE error. 在另一个客户端上使用文件时,使用rsync或mv替换文件是一种常见的情况,会导致ESTALE错误。

I've tried simulating this to confirm but haven't been able to do so successfully - so I wanted to check here before implementing this strategy : 我尝试模拟这一点来进行确认,但未能成功完成-因此,我想在实施此策略之前在此处进行检查:

Question : Is my understanding accurate - or do I need to use a different strategy to ensure the file.txt doesn't get corrupted? 问题: 我的理解正确吗?还是需要使用其他策略来确保file.txt不会损坏?

Additional details : Amazon Linux OS. 其他详细信息:Amazon Linux OS。 The drive is mounted is nsf4 . 驱动器已安装为nsf4 The file could be as large as 100MB 该文件可能最大为100MB

The check-if-file-exists is a typical TOCTTOU problem. 检查文件是否存在是典型的TOCTTOU问题。

The simplest fix is to just not check, and try to mv . 最简单的解决方法是检查,然后尝试 mv If there is no file to be moved, the mv will fail (and not do anything). 如果没有要移动的文件,则mv将失败(并且不执行任何操作)。

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

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