On 10/22/2016 03:13 PM, bruce wrote:
I've thought of having a "pid" file on the nfs, where each clientApp would reset/lock/use the pidFile to then get/use/delete the file as required, but this seems tb slow.. but doable.
I would experiment with using the atomicity of the filesystem rename.
The process on client number N will do:
1) list files in directory 2) identify a filename not starting with "INPROGRESS-" (e.g. "abcd"); if file-not-found {sleep(something); goto 1} 3) rename "abcd" to "INPROGRESS-N-abcd"; if file-not-found goto 2 4) process INPROGRESS-N-abcd 5) delete INPROGRESS-N-abcd 6) goto 1
The rename is atomic, so if two processes try to grab the same file, only one wins the race; when a file has been renamed, nobody else can mess with it.
The good part is that you do not need anything running on the server.
Of course you have some tunables; sleep could be 0.01s or 1m, depending on your expectations; "INPROGRESS-" could be a smarter Unicode prefix, for example "⚒".
(alternatively, keep the name unchanged but rename the file away to a client-specific directory)
Just be sure that rename maintains the atomicity for the NFS implementation and version you are using.
Regards.