]> granicus.if.org Git - postgresql/commitdiff
Use just one database connection in the "tablespace" test.
authorNoah Misch <noah@leadboat.com>
Wed, 12 Nov 2014 12:33:17 +0000 (07:33 -0500)
committerNoah Misch <noah@leadboat.com>
Wed, 12 Nov 2014 12:34:07 +0000 (07:34 -0500)
On Windows, DROP TABLESPACE has a race condition when run concurrently
with other processes having opened files in the tablespace.  This led to
a rare failure on buildfarm member frogmouth.  Back-patch to 9.4, where
the reconnection was introduced.

src/backend/commands/tablespace.c
src/test/regress/input/tablespace.source
src/test/regress/output/tablespace.source

index 28e69a55510aabe246d71a41251927ce5cec55d6..096d01aaf0b1c7a2754ccc63deb8b955efef299b 100644 (file)
@@ -491,6 +491,13 @@ DropTableSpace(DropTableSpaceStmt *stmt)
                 * but we can't tell them apart from important data files that we
                 * mustn't delete.  So instead, we force a checkpoint which will clean
                 * out any lingering files, and try again.
+                *
+                * XXX On Windows, an unlinked file persists in the directory listing
+                * until no process retains an open handle for the file.  The DDL
+                * commands that schedule files for unlink send invalidation messages
+                * directing other PostgreSQL processes to close the files.  DROP
+                * TABLESPACE should not give up on the tablespace becoming empty
+                * until all relevant invalidation processing is complete.
                 */
                RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
                if (!destroy_tablespace_directories(tablespaceoid, false))
index e259254b02cb6bda9bf443ed6b8f0c2c7a5a91c4..75ec689498f883eb6afabeefa6ab063d4a7f8bf5 100644 (file)
@@ -71,8 +71,7 @@ ALTER TABLESPACE testspace OWNER TO tablespace_testuser1;
 
 SET SESSION ROLE tablespace_testuser2;
 CREATE TABLE tablespace_table (i int) TABLESPACE testspace; -- fail
-
-\c -
+RESET ROLE;
 
 ALTER TABLESPACE testspace RENAME TO testspace_renamed;
 
index a30651087b9d59c144a287c8d5a837295a406b86..ca606508f81fbc2d81caccc277866fe4c70d80f0 100644 (file)
@@ -91,7 +91,7 @@ ALTER TABLESPACE testspace OWNER TO tablespace_testuser1;
 SET SESSION ROLE tablespace_testuser2;
 CREATE TABLE tablespace_table (i int) TABLESPACE testspace; -- fail
 ERROR:  permission denied for tablespace testspace
-\c -
+RESET ROLE;
 ALTER TABLESPACE testspace RENAME TO testspace_renamed;
 ALTER TABLE ALL IN TABLESPACE testspace_renamed SET TABLESPACE pg_default;
 ALTER INDEX ALL IN TABLESPACE testspace_renamed SET TABLESPACE pg_default;