pgsql: Fix two race conditions between the pending unlink mechanism that

From: heikki(at)postgresql(dot)org (Heikki Linnakangas)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix two race conditions between the pending unlink mechanism that
Date: 2008-04-18 06:48:38
Message-ID: 20080418064838.E56897559CC@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
Fix two race conditions between the pending unlink mechanism that was put in
place to prevent reusing relation OIDs before next checkpoint, and DROP
DATABASE. First, if a database was dropped, bgwriter would still try to unlink
the files that the rmtree() call by the DROP DATABASE command has already
deleted, or is just about to delete. Second, if a database is dropped, and
another database is created with the same OID, bgwriter would in the worst
case delete a relation in the new database that happened to get the same OID
as a dropped relation in the old database.

To fix these race conditions:
- make rmtree() ignore ENOENT errors. This fixes the 1st race condition.
- make ForgetDatabaseFsyncRequests forget unlink requests as well.
- force checkpoint on in dropdb on all platforms

Since ForgetDatabaseFsyncRequests() is asynchronous, the 2nd change isn't
enough on its own to fix the problem of dropping and creating a database with
same OID, but forcing a checkpoint on DROP DATABASE makes it sufficient.

Per Tom Lane's bug report and proposal. Backpatch to 8.3.

Modified Files:
--------------
pgsql/src/backend/commands:
dbcommands.c (r1.206 -> r1.207)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/dbcommands.c?r1=1.206&r2=1.207)
pgsql/src/backend/storage/smgr:
md.c (r1.136 -> r1.137)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/storage/smgr/md.c?r1=1.136&r2=1.137)
pgsql/src/port:
dirmod.c (r1.53 -> r1.54)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/port/dirmod.c?r1=1.53&r2=1.54)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2008-04-18 06:48:51 pgsql: Fix two race conditions between the pending unlink mechanism that
Previous Message Tom Lane 2008-04-18 01:42:17 pgsql: Cause EXPLAIN's VERBOSE option to print the target list (output