NFS file locking

Sometimes you need file locking over NFS. In my case, I needed it for running MySQL tables via NFS. Even though you can tell MySQL to not do external locking, this setting is ignored when you use InnoDB. That's not a very well documented feature. So you need to make sure locking is available.

I did most of my debugging with a small perl script that I found on the HP forums. Simply edit the location and you're ready to go. My problem was that I had no trouble at all getting it to work in another setup, but I couldn't find at first what was different in the production setup. In the end it was very obvious (as it usually is): The network was way more complicated.

The setup I'm talking about is in a datacentre that houses several of our customers. They're all daughter-companies from one large one, so they're okay with sharing some infrastructure. But each company has it's own domain name and prefers of course to use that one. Now, we name our virtual machines (we do everything virtualised) after their specific function, so a database master would be called something like dbm1.customera.com. Another customer with another database master would call the machine dbm1.customerb.com. But when we're working in that network, it's annoying to use those full names, so we have an internal DNS that resolves things like dbm1.custa and dbm1.custb. Just for convenience.

But that convenience is what made NFS locking break. Since the machine would report it's hostname as being dbm1.customera.com, while it's DNS name would be dbm1.custa. Apparantly, NFS can't handle that very well.

Luckily, there's an easy solution: Add a specific hostname to the NFS stat daemon. In Debian, you do that by editing /etc/default/nfs-common (after you installed the nfs-common package) and adding the following line: STATDOPTS="-n dbm1"

That worked for me. Now, I have working InnoDB tables on an NFS share.

Comments

Comments powered by Disqus