1

I'm seeing strange behavior and I'm wondering if it's a race condition.

The strange behavior is MySQL getting EEXIST when trying to create a temporary file. MySQL reuses temp file names by default, and because it chooses names in order from a pool of names, the name #sql_<pid>_0.<ext> is always chosen first if it is isn't already in use (the last 0 indicates the position of the name in the pool).

I know that NFS simulates unlink because of the requirement to preserve blocks on an open file. When you unlink a file on an NFS volume, the client instead renames the file, and then when processes on the client close it, finally do an unlink.

But what if I unlink the file, and then a second thread tries to recreate a file with the same name within a millisecond or so after the unlink?

Is it possible that the rename is asynchronous, and may be delayed enough that the second thread gets an EEXIST error even though my thread believes it has finished its unlink() call successfully?

Bill Karwin
  • 206
  • 1
  • 7
  • 1
    omg you're using nfs for mysql temp files? I usually try to stick tmpdir on an ssd... – Some Linux Nerd Nov 18 '14 at 01:46
  • isn't there an NFS option to force synchronous behaviour? Also looking quickly at man nfs, there's an ac/noac option to enable and disable client side caching of file attributes, that might also be worth fiddling with as a diagnostic step. – Some Linux Nerd Nov 18 '14 at 01:46
  • @SomeLinuxNerd, it isn't my server. :-) And yes, tmpdir should be local and low-latency. Ideally, using tmpfs when I can. – Bill Karwin Nov 18 '14 at 02:39
  • @SomeLinuxNerd, from what I've read, the ac/noac option is about caching metadata, not data. – Bill Karwin Nov 18 '14 at 02:43
  • Ya, I was thinking that cached fs data could potentially cause a false EEXIST, especially if things are happening really fast on a filesystem thats extremely slow. If it's not your server and you can't mess with the settings then you're really left in a pretty bad position. – Some Linux Nerd Nov 19 '14 at 03:32

0 Answers0