Fix two race conditions between the pending unlink mechanism that was put in
authorHeikki Linnakangas <heikki@enterprisedb.com>
Fri, 18 Apr 2008 06:48:50 +0000 (06:48 +0000)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Fri, 18 Apr 2008 06:48:50 +0000 (06:48 +0000)
commitdb003b8f9ed38c0464857da07cba7dc65b2fa6ae
treeab1f7825162e83b9dcf7230966dc29e6d84dbe85
parentd43cbf36992dfc4254ded06170a2fcd87c67c107
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.
src/backend/commands/dbcommands.c
src/backend/storage/smgr/md.c
src/port/dirmod.c