~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/access/heap/visibilitymap.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/access/heap/visibilitymap.c,v 1.3 2009/01/01 17:23:35 momjian Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/access/heap/visibilitymap.c,v 1.5 2009/06/18 10:08:08 heikki Exp $
12
12
 *
13
13
 * INTERFACE ROUTINES
14
 
 *              visibilitymap_clear     - clear a bit in the visibility map
 
14
 *              visibilitymap_clear - clear a bit in the visibility map
15
15
 *              visibilitymap_pin       - pin a map page for setting a bit
16
16
 *              visibilitymap_set       - set a bit in a previously pinned page
17
17
 *              visibilitymap_test      - test if a bit is set
98
98
 
99
99
/*
100
100
 * Size of the bitmap on each visibility map page, in bytes. There's no
101
 
 * extra headers, so the whole page minus except for the standard page header
102
 
 * is used for the bitmap.
 
101
 * extra headers, so the whole page minus the standard page header is
 
102
 * used for the bitmap.
103
103
 */
104
104
#define MAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData))
105
105
 
144
144
 
145
145
        mapBuffer = vm_readbuf(rel, mapBlock, false);
146
146
        if (!BufferIsValid(mapBuffer))
147
 
                return; /* nothing to do */
 
147
                return;                                 /* nothing to do */
148
148
 
149
149
        LockBuffer(mapBuffer, BUFFER_LOCK_EXCLUSIVE);
150
150
        map = PageGetContents(BufferGetPage(mapBuffer));
295
295
visibilitymap_truncate(Relation rel, BlockNumber nheapblocks)
296
296
{
297
297
        BlockNumber newnblocks;
 
298
 
298
299
        /* last remaining block, byte, and bit */
299
300
        BlockNumber truncBlock = HEAPBLK_TO_MAPBLOCK(nheapblocks);
300
 
        uint32          truncByte  = HEAPBLK_TO_MAPBYTE(nheapblocks);
301
 
        uint8           truncBit   = HEAPBLK_TO_MAPBIT(nheapblocks);
 
301
        uint32          truncByte = HEAPBLK_TO_MAPBYTE(nheapblocks);
 
302
        uint8           truncBit = HEAPBLK_TO_MAPBIT(nheapblocks);
302
303
 
303
304
#ifdef TRACE_VISIBILITYMAP
304
305
        elog(DEBUG1, "vm_truncate %s %d", RelationGetRelationName(rel), nheapblocks);
315
316
         * Unless the new size is exactly at a visibility map page boundary, the
316
317
         * tail bits in the last remaining map page, representing truncated heap
317
318
         * blocks, need to be cleared. This is not only tidy, but also necessary
318
 
         * because we don't get a chance to clear the bits if the heap is
319
 
         * extended again.
 
319
         * because we don't get a chance to clear the bits if the heap is extended
 
320
         * again.
320
321
         */
321
322
        if (truncByte != 0 || truncBit != 0)
322
323
        {
323
 
                Buffer mapBuffer;
324
 
                Page page;
325
 
                char *map;
 
324
                Buffer          mapBuffer;
 
325
                Page            page;
 
326
                char       *map;
326
327
 
327
328
                newnblocks = truncBlock + 1;
328
329
 
344
345
                /*
345
346
                 * Mask out the unwanted bits of the last remaining byte.
346
347
                 *
347
 
                 * ((1 << 0) - 1) = 00000000
348
 
                 * ((1 << 1) - 1) = 00000001
349
 
                 * ...
350
 
                 * ((1 << 6) - 1) = 00111111
351
 
                 * ((1 << 7) - 1) = 01111111
 
348
                 * ((1 << 0) - 1) = 00000000 ((1 << 1) - 1) = 00000001 ... ((1 << 6) -
 
349
                 * 1) = 00111111 ((1 << 7) - 1) = 01111111
352
350
                 */
353
351
                map[truncByte] &= (1 << truncBit) - 1;
354
352
 
368
366
                                 rel->rd_istemp);
369
367
 
370
368
        /*
371
 
         * Need to invalidate the relcache entry, because rd_vm_nblocks
372
 
         * seen by other backends is no longer valid.
 
369
         * Need to invalidate the relcache entry, because rd_vm_nblocks seen by
 
370
         * other backends is no longer valid.
373
371
         */
374
372
        if (!InRecovery)
375
373
                CacheInvalidateRelcache(rel);
386
384
static Buffer
387
385
vm_readbuf(Relation rel, BlockNumber blkno, bool extend)
388
386
{
389
 
        Buffer buf;
 
387
        Buffer          buf;
390
388
 
391
389
        RelationOpenSmgr(rel);
392
390
 
433
431
vm_extend(Relation rel, BlockNumber vm_nblocks)
434
432
{
435
433
        BlockNumber vm_nblocks_now;
436
 
        Page pg;
 
434
        Page            pg;
437
435
 
438
436
        pg = (Page) palloc(BLCKSZ);
439
437
        PageInit(pg, BLCKSZ, 0);
440
438
 
441
439
        /*
442
 
         * We use the relation extension lock to lock out other backends trying
443
 
         * to extend the visibility map at the same time. It also locks out
444
 
         * extension of the main fork, unnecessarily, but extending the
445
 
         * visibility map happens seldom enough that it doesn't seem worthwhile to
446
 
         * have a separate lock tag type for it.
 
440
         * We use the relation extension lock to lock out other backends trying to
 
441
         * extend the visibility map at the same time. It also locks out extension
 
442
         * of the main fork, unnecessarily, but extending the visibility map
 
443
         * happens seldom enough that it doesn't seem worthwhile to have a
 
444
         * separate lock tag type for it.
447
445
         *
448
 
         * Note that another backend might have extended or created the
449
 
         * relation before we get the lock.
 
446
         * Note that another backend might have extended or created the relation
 
447
         * before we get the lock.
450
448
         */
451
449
        LockRelationForExtension(rel, ExclusiveLock);
452
450