List:Internals« Previous MessageNext Message »
From:Jeremy Zawodny Date:October 20 2002 6:12pm
Subject:Re: [PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.
View as plain text  
On Sun, Oct 20, 2002 at 09:00:01PM +0300, Michael Widenius wrote:
> 
> Hi!
> 
> Jeremy> Hi Monty & others,
> 
> Jeremy> We've *finally* tracked down a mysterious MySQL problem that has been
> Jeremy> affecting some of our FreeBSD/MySQL/LinuxThreads servers.  It turns
> Jeremy> out that FreeBSD's realpath() isn't thread-safe.  The result is that
> Jeremy> you can have two processes both changing the current working directory
> Jeremy> (realpath() does a a chdir() behind the scenes) on a shared file
> Jeremy> descriptor and tries to restore it later and leaving the file
> Jeremy> descriptor in an improper state.  It's a simple race condition.
> 
> This is the same thing as we have seen on BSD and Mac OS X.

Ah!  I had heard about problems with realpath() on OS X but never paid
much attention, since I don't run MySQL on my OS X machine (yet?).

> Jeremy> This doesn't *seem* to affect MySQL using FreeBSD's native threads,
> Jeremy> because they are not pre-emptive or SMP aware.  In order to use SMP,
> Jeremy> we often build MySQL with LinuxThreads.  The performance is excellent
> Jeremy> this way.
> 
> It's actually a bit worse than that.
> 
> MySQL opens all files relative to the current directory.  If one
> thread opens a file while another thread is doing realpath() then
> the open may fail.

That explains it.  Since patching it, I've still been seeing
intermittent "Unknown database" and similar problems.  Hmm.

> A better option than protecting realpath with a mutex is to compile
> MySQL with the -DHAVE_BROKEN_REALPATH option.
> 
> In effect this means that one MySQL will forgot symlinks to a table if
> you do a REPAIR or ALTER TABLE and you can't symlink two databases to
> the same database directory.
> 
> Jeremy, is the above restrictions a problem for you ?

The only symlinks we use currently are to put MySQL's data directory
on one RAID volume and the logs (replication/relay) on a different
one.  For example, we'll install MySQL in /home/mysql and then make
/home/mysq/var a symlink to somewhere else.  We don't use symlinks to
point individual databases or tables to other directories.

I'll rebuild our binary with -DHAVE_BROKEN_REALPATH and see if it
breaks anything.

> Lenz, can you please add the above the freebds options and add a note
> about this to the manual for all OS we compile with
> -DHAVE_BROKEN_REALPATH.

Thanks,

Jeremy
-- 
Jeremy D. Zawodny     |  Perl, Web, MySQL, Linux Magazine, Yahoo!
<Jeremy@stripped>  |  http://jeremy.zawodny.com/

MySQL 3.23.51: up 75 days, processed 1,582,177,340 queries (242/sec. avg)
Thread
[PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Jeremy Zawodny18 Oct
  • [PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Michael Widenius20 Oct
    • Re: [PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Jeremy Zawodny20 Oct