简体   繁体   中英

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
  2. mv new/file.txt current/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) :

  • Server 1 - step 1. checks if file exists. True
  • Server 2 - step 1. checks if file exists. True
  • Server 1 - step 2. starts to perform the "mv" command
  • Server 2 - step 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/

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. 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.

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?

Additional details : Amazon Linux OS. The drive is mounted is nsf4 . The file could be as large as 100MB

The check-if-file-exists is a typical TOCTTOU problem.

The simplest fix is to just not check, and try to mv . If there is no file to be moved, the mv will fail (and not do anything).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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