|
how to handle potential file contention
I need to change how a posting procedure currently works in order to improve load balancing but I am hitting a potential file contention problem that I was wondering if someone here could assist me with...
In a directory called FilePool I would have a bunch of files that are constantly coming in as follows:
File0001.GO
File0001.GOA
File0001.GOB
File0001.GOC
File0002.GO
File0002.GOA
File0002.GOB
File0002.GOC
The *.GO file for each batch of files is only written after the entire batch has been written, so the problem isn't that what is pulling these batches may conflict with what is writing them, but rather:
There are four processes that are each looking for the presence of a *.GO file in the FilePool directory. If one of these processes finds one, it takes the entire batch and moves it into that process' directory to process the batch.
These processes work quickly and it could be that two processes try to grab File0001.GO at the same time. Is there a way to
1 - have the first process lock File0001.GO if it isn't already locked and then move the whole batch
2 - have the process check if there is any other pid attached to that file first and then move it if there is none
3 - any other way that you would ensure that the file contention in this situation is handled?
Thank you for any assistance you can provide.
|