-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concurrency cache write guarantee #18
Comments
Hi. Did you experience this as a problem or did you bring it up from code inspection of R.cache? If from experience, I'm really keen to hear more details about it, because that should then definitely be considered a bug. What you're suggesting is what I often refer to as atomic writing emulated by the fact that a file rename / move is as atomic as we get on a random file system. I use this almost everywhere possible in all of my packages (e.g. I think I have had this on the to-do-list for R.cache as well (fail to find note from quick search). However, I think I would be fine with adding a layer of "atomic" writing to BTW, at first one might think you'll get better cache hits of one writes atomically, but I'm not sure about that. With atomic writing it's either there or not, whereas with current writing it's either there or corrupt; in both setups I think the chance for a cache hit is approximately the same. Finally, note that on some file systems such as shared NFS, there might be up to a 30-second delay from that one machine writes a file and another machine sees it. I've seen this many times in many different places. For some example pointers, see #7 (comment) Say hi to Tony from me. PS. <shameful self promotion>Off topic, but since you're saying you're using parallel for parallelization, you might be interesting in the future package which allows you do the same but scale it up to run on clusters etc without changing a single line of code.</shameful self promotion> |
Purely through code inspected. I checked for documentation and, failing that, checked the source code for explicit locking or defensive copies.
I'm not really that concerned about a cache miss on parellel operations - my concern was with removing the possibility of concurrent writes and corrupted read as I didn't want a job to fail due to caching issues.
I have ~ 11,000 jobs all sharing ~1,000 cache objects. I'll kick off a full run and see how it goes.
I currently have a helper script that does a whole lot of Thanks for the prompt response :) |
Would it be possible to guarantee that, for every cache file written, the contents of the file are correct? I'm using
parallel
was hoping that I could just assume that if I read a cached value, it would be correct. Unfortunately, saveCache.R appears to write directly to the cache file thus is inappropriate for parallel usage.Would you consider updating saveCache() to write to a temporary file in the destination directory then moving the file to the correct cache location once the write is complete? This would allow a common cache to be used by multiple R instances and would have the added benefit that R processes killed whilst writing an R.cache file do not result in cache corruption.
The text was updated successfully, but these errors were encountered: