diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-03 01:14:17 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-03 01:14:17 +0000 |
commit | 70a2b05a59c02464e36d8c9bf23d2eef8502eccd (patch) | |
tree | 367ea4f6b3285ec31e88868276f27524fc495674 /src/backend/storage/smgr/smgr.c | |
parent | ab7c49c98811f539db9294c8f2d1a15380e025f6 (diff) | |
download | postgresql-70a2b05a59c02464e36d8c9bf23d2eef8502eccd.tar.gz postgresql-70a2b05a59c02464e36d8c9bf23d2eef8502eccd.zip |
Assorted cleanups in preparation for using a map file to support altering
the relfilenode of currently-not-relocatable system catalogs.
1. Get rid of inval.c's dependency on relfilenode, by not having it emit
smgr invalidations as a result of relcache flushes. Instead, smgr sinval
messages are sent directly from smgr.c when an actual relation delete or
truncate is done. This makes considerably more structural sense and allows
elimination of a large number of useless smgr inval messages that were
formerly sent even in cases where nothing was changing at the
physical-relation level. Note that this reintroduces the concept of
nontransactional inval messages, but that's okay --- because the messages
are sent by smgr.c, they will be sent in Hot Standby slaves, just from a
lower logical level than before.
2. Move setNewRelfilenode out of catalog/index.c, where it never logically
belonged, into relcache.c; which is a somewhat debatable choice as well but
better than before. (I considered catalog/storage.c, but that seemed too
low level.) Rename to RelationSetNewRelfilenode.
3. Cosmetic cleanups of some other relfilenode manipulations.
Diffstat (limited to 'src/backend/storage/smgr/smgr.c')
-rw-r--r-- | src/backend/storage/smgr/smgr.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 5497d03cc5a..958be2433fb 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.118 2010/01/02 16:57:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.119 2010/02/03 01:14:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,6 +24,7 @@ #include "storage/ipc.h" #include "storage/smgr.h" #include "utils/hsearch.h" +#include "utils/inval.h" /* @@ -351,13 +352,21 @@ smgr_internal_unlink(RelFileNode rnode, ForkNumber forknum, */ /* - * And delete the physical files. + * Delete the physical file(s). * * Note: smgr_unlink must treat deletion failure as a WARNING, not an * ERROR, because we've already decided to commit or abort the current * xact. */ (*(smgrsw[which].smgr_unlink)) (rnode, forknum, isRedo); + + /* + * Lastly, send a shared-inval message to force other backends to close + * any dangling smgr references they may have for this rel. We do this + * last because the sinval will eventually come back to this backend, too, + * and thereby provide a backstop that we closed our own smgr rel. + */ + CacheInvalidateSmgr(rnode); } /* @@ -437,6 +446,8 @@ smgrnblocks(SMgrRelation reln, ForkNumber forknum) /* * smgrtruncate() -- Truncate supplied relation to the specified number * of blocks + * + * The truncation is done immediately, so this can't be rolled back. */ void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks, @@ -448,9 +459,21 @@ smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks, */ DropRelFileNodeBuffers(reln->smgr_rnode, forknum, isTemp, nblocks); - /* Do the truncation */ + /* + * Do the truncation. + */ (*(smgrsw[reln->smgr_which].smgr_truncate)) (reln, forknum, nblocks, isTemp); + + /* + * Send a shared-inval message to force other backends to close any smgr + * references they may have for this rel. This is useful because they + * might have open file pointers to segments that got removed. (The inval + * message will come back to our backend, too, causing a + * probably-unnecessary smgr flush. But we don't expect that this is + * a performance-critical path.) + */ + CacheInvalidateSmgr(reln->smgr_rnode); } /* |