~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/backend/catalog/storage.c

  • Committer: Bazaar Package Importer
  • Author(s): Ubuntu Archive Backport
  • Date: 2009-11-09 13:46:16 UTC
  • mfrom: (5.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091109134616-ae14l9tr3g7p2t9y
Tags: 8.4.1-1~hardy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.5 2009/01/20 18:59:37 heikki Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.6 2009/06/11 14:48:55 momjian Exp $
12
12
 *
13
13
 * NOTES
14
14
 *        Some of this code used to be in storage/smgr/smgr.c, and the
109
109
        if (!istemp)
110
110
        {
111
111
                /*
112
 
                 * Make an XLOG entry showing the file creation.  If we abort, the file
113
 
                 * will be dropped at abort time.
 
112
                 * Make an XLOG entry showing the file creation.  If we abort, the
 
113
                 * file will be dropped at abort time.
114
114
                 */
115
115
                xlrec.rnode = rnode;
116
116
 
175
175
void
176
176
RelationTruncate(Relation rel, BlockNumber nblocks)
177
177
{
178
 
        bool fsm;
179
 
        bool vm;
 
178
        bool            fsm;
 
179
        bool            vm;
180
180
 
181
181
        /* Open it at the smgr level if not already done */
182
182
        RelationOpenSmgr(rel);
195
195
                visibilitymap_truncate(rel, nblocks);
196
196
 
197
197
        /*
198
 
         * We WAL-log the truncation before actually truncating, which
199
 
         * means trouble if the truncation fails. If we then crash, the WAL
200
 
         * replay likely isn't going to succeed in the truncation either, and
201
 
         * cause a PANIC. It's tempting to put a critical section here, but
202
 
         * that cure would be worse than the disease. It would turn a usually
203
 
         * harmless failure to truncate, that could spell trouble at WAL replay,
204
 
         * into a certain PANIC.
 
198
         * We WAL-log the truncation before actually truncating, which means
 
199
         * trouble if the truncation fails. If we then crash, the WAL replay
 
200
         * likely isn't going to succeed in the truncation either, and cause a
 
201
         * PANIC. It's tempting to put a critical section here, but that cure
 
202
         * would be worse than the disease. It would turn a usually harmless
 
203
         * failure to truncate, that could spell trouble at WAL replay, into a
 
204
         * certain PANIC.
205
205
         */
206
206
        if (!rel->rd_istemp)
207
207
        {
223
223
                lsn = XLogInsert(RM_SMGR_ID, XLOG_SMGR_TRUNCATE, &rdata);
224
224
 
225
225
                /*
226
 
                 * Flush, because otherwise the truncation of the main relation
227
 
                 * might hit the disk before the WAL record, and the truncation of
228
 
                 * the FSM or visibility map. If we crashed during that window, we'd
229
 
                 * be left with a truncated heap, but the FSM or visibility map would
230
 
                 * still contain entries for the non-existent heap pages.
 
226
                 * Flush, because otherwise the truncation of the main relation might
 
227
                 * hit the disk before the WAL record, and the truncation of the FSM
 
228
                 * or visibility map. If we crashed during that window, we'd be left
 
229
                 * with a truncated heap, but the FSM or visibility map would still
 
230
                 * contain entries for the non-existent heap pages.
231
231
                 */
232
232
                if (fsm || vm)
233
233
                        XLogFlush(lsn);
270
270
                        /* do deletion if called for */
271
271
                        if (pending->atCommit == isCommit)
272
272
                        {
273
 
                                int i;
 
273
                                int                     i;
274
274
 
275
275
                                /* schedule unlinking old files */
276
276
                                SMgrRelation srel;
431
431
 
432
432
                /* Also tell xlogutils.c about it */
433
433
                XLogTruncateRelation(xlrec->rnode, MAIN_FORKNUM, xlrec->blkno);
434
 
 
 
434
 
435
435
                /* Truncate FSM too */
436
436
                if (smgrexists(reln, FSM_FORKNUM))
437
437
                {
438
 
                        Relation rel = CreateFakeRelcacheEntry(xlrec->rnode);
 
438
                        Relation        rel = CreateFakeRelcacheEntry(xlrec->rnode);
 
439
 
439
440
                        FreeSpaceMapTruncateRel(rel, xlrec->blkno);
440
441
                        FreeFakeRelcacheEntry(rel);
441
442
                }
453
454
        if (info == XLOG_SMGR_CREATE)
454
455
        {
455
456
                xl_smgr_create *xlrec = (xl_smgr_create *) rec;
456
 
                char *path = relpath(xlrec->rnode, MAIN_FORKNUM);
 
457
                char       *path = relpath(xlrec->rnode, MAIN_FORKNUM);
457
458
 
458
459
                appendStringInfo(buf, "file create: %s", path);
459
460
                pfree(path);
461
462
        else if (info == XLOG_SMGR_TRUNCATE)
462
463
        {
463
464
                xl_smgr_truncate *xlrec = (xl_smgr_truncate *) rec;
464
 
                char *path = relpath(xlrec->rnode, MAIN_FORKNUM);
 
465
                char       *path = relpath(xlrec->rnode, MAIN_FORKNUM);
465
466
 
466
467
                appendStringInfo(buf, "file truncate: %s to %u blocks", path,
467
468
                                                 xlrec->blkno);