This is a blog for those unlucky many of you that, like me, had to solve the file integration problem. Two processes are integrating over a directory, one writes (W), one reads (R). Now the reader picks up a file while the writer is still writing to it. BOOM, R caughs and dies. Sounds familiar? Then read on.
I know I promised a blog on a deadline free utopia, but while I'm chewing over that one I need to jot down this thought. That's what blogs are for right to capture the excess of an overflowing mind? So back to R and W that can't seem to get their processes synced. How do you prevent R reading that file that W is still writing? Locking will work, but it's clunky and tricky. Looking at the timestamp might work in most of the cases, but it is not guaranteed to work under high load. Can you say heisenbug? So, what can we do.
Well in fact the solution is too simple to spend more than a few sentences on. It is old, battered and scarred, and it will be around for a while in the future. Just Copy the file to a temporary name and then Rename it to its final destination. Maybe I'll include an image later, but you should get the point, right?
No comments:
Post a Comment