Problem
If I create a file on an nfs-mounted filesystem on one machine, the file may not be immediately visible to another machine looking at the same nfs-mounted filesystem.
In our case this happened with a compute farm environment, where a job was dispatched to a remote machine to write some file, then when that job finished the dispatching machine tried immediately read that file. This would regularly fail and the immediate work-around was a
sleep(10) step in between the dispatched-job-finish and the subsequent read-the-created-file step.
Solution
$ man nfs
[...] lookupcache=type
This option dictates how directories and files should be cached when they are
accessed -- i.e. "looked up" -- on the server. A lookup can be either positive
(directory/file was found) or negative (directory/file was not found); both types
of lookups can be cached. By default, both positive and negative lookups are cached ( lookupcache=all ).
lookupcache=pos prevents negative lookups from being cached, while lookupcache=none
prevents all lookups from being cached. Note: lookupcache=none can adversely affect performance, but may be necessary if
shared files created or deleted on the server need to be immediately visible to any
applications running on NFS clients.
I added the option
lookupcache=pos to the automount options for this filesystem and the problem went away.
Availability
This appears to be added for the RedHat/CentOS
5.4 release cycle and should be available in those or later releases.