Commit 6d660587 authored by Tom Lane's avatar Tom Lane

Revise bgwriter fsync-request mechanism to improve robustness when a table

is deleted.  A backend about to unlink a file now sends a "revoke fsync"
request to the bgwriter to make it clean out pending fsync requests.  There
is still a race condition where the bgwriter may try to fsync after the unlink
has happened, but we can resolve that by rechecking the fsync request queue
to see if a revoke request arrived meanwhile.  This eliminates the former
kluge of "just assuming" that an ENOENT failure is okay, and lets us handle
the fact that on Windows it might be EACCES too without introducing any
questionable assumptions.  After an idea of mine improved by Magnus.

The HEAD patch doesn't apply cleanly to 8.2, but I'll see about a back-port
later.  In the meantime this could do with some testing on Windows; I've been
able to force it through the code path via ENOENT, but that doesn't prove that
it actually fixes the Windows problem ...
parent 7f58ed1a
......@@ -2,7 +2,7 @@
*
* bgwriter.c
*
* The background writer (bgwriter) is new in Postgres 8.0. It attempts
* The background writer (bgwriter) is new as of Postgres 8.0. It attempts
* to keep regular backends from having to write out dirty shared buffers
* (which they would only do when needing to free a shared buffer to read in
* another page). In the best scenario all writes from shared buffers will
......@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.34 2007/01/05 22:19:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.35 2007/01/17 00:17:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -103,8 +103,8 @@
typedef struct
{
RelFileNode rnode;
BlockNumber segno;
/* might add a request-type field later */
BlockNumber segno; /* InvalidBlockNumber means "revoke" */
/* might add a real request-type field later; not needed yet */
} BgWriterRequest;
typedef struct
......@@ -695,6 +695,11 @@ RequestCheckpoint(bool waitforit, bool warnontime)
* ForwardFsyncRequest
* Forward a file-fsync request from a backend to the bgwriter
*
* segno specifies which segment (not block!) of the relation needs to be
* fsync'd. If segno == InvalidBlockNumber, the meaning is to revoke any
* pending fsync requests for the entire relation (this message is sent
* when the relation is about to be deleted).
*
* Whenever a backend is compelled to write directly to a relation
* (which should be seldom, if the bgwriter is getting its job done),
* the backend calls this routine to pass over knowledge that the relation
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment