Re: drop tablespace error: invalid argument - Mailing list pgsql-hackers

From Jan Otto
Subject Re: drop tablespace error: invalid argument
Date
Msg-id 5A2BBE87-8F76-4737-BE66-F83994777474@me.com
Whole thread Raw
In response to Re: drop tablespace error: invalid argument  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: drop tablespace error: invalid argument  (Jan Otto <asche@me.com>)
Re: drop tablespace error: invalid argument  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Aug 16, 2009, at 8:25 PM, Tom Lane wrote:
Jan Otto <asche@me.com> writes:
ERROR:  could not read directory "pg_tblspc/16464": Invalid argument
STATEMENT:  DROP TABLESPACE testspace;

Hmm ... can't reproduce this here, not even on OSX.  From the version
number I suspect you are using unreleased Snow Leopard.  I'd venture
it's a newly-introduced kernel bug and you need to talk to Apple about
it.

regards, tom lane

I have digged a bit around in the source code of postgresql to build a
self contained test-case for Apple and found that the implementation
of Apples readdir() is buggy. readdir() fails under some circumstances.
So i have build a patch against current pgsql's HEAD to work around
the issue. If the bug in readdir() goes into the final release  snow leopard
we have a solution. 

This patch basically frees dirdesc and rereads the tablespace location
in case a subdirectory was deleted from the tablespace. this is the place
where snow leopard fails to read the next entry with readdir().

regards, jan otto

diff -c -r1.61 tablespace.c
*** pgsql/src/backend/commands/tablespace.c     22 Jan 2009 20:16:02 -0000      1.61
--- pgsql/src/backend/commands/tablespace.c     17 Aug 2009 22:36:01 -0000
***************
*** 611,616 ****
--- 611,623 ----
                                         errmsg("could not remove directory \"%s\": %m",
                                                        subfile)));
  
+               /*
+                * The following two lines work around a bug in Mac OS X Snow Leopard (Build 10A432)
+                * readdir() implementation. We free dirdesc and reread location from start. 
+                */
+               FreeDir(dirdesc);
+               dirdesc = AllocateDir(location);
                pfree(subfile);
        }

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: explain root element for auto-explain
Next
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Add release notes for 8.5alpha1