~ubuntu-branches/ubuntu/trusty/postgresql-8.4/trusty

« back to all changes in this revision

Viewing changes to src/backend/utils/time/snapmgr.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
 * (tracked by separate refcounts on each snapshot), its memory can be freed.
9
9
 *
10
10
 * These arrangements let us reset MyProc->xmin when there are no snapshots
11
 
 * referenced by this transaction.  (One possible improvement would be to be
 
11
 * referenced by this transaction.      (One possible improvement would be to be
12
12
 * able to advance Xmin when the snapshot with the earliest Xmin is no longer
13
 
 * referenced.  That's a bit harder though, it requires more locking, and
 
13
 * referenced.  That's a bit harder though, it requires more locking, and
14
14
 * anyway it should be rather uncommon to keep snapshots referenced for too
15
15
 * long.)
16
16
 *
19
19
 * Portions Copyright (c) 1994, Regents of the University of California
20
20
 *
21
21
 * IDENTIFICATION
22
 
 *        $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.9 2009/01/01 17:23:53 momjian Exp $
 
22
 *        $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.10 2009/06/11 14:49:06 momjian Exp $
23
23
 *
24
24
 *-------------------------------------------------------------------------
25
25
 */
50
50
static SnapshotData SecondarySnapshotData = {HeapTupleSatisfiesMVCC};
51
51
 
52
52
/* Pointers to valid snapshots */
53
 
static Snapshot CurrentSnapshot = NULL;
54
 
static Snapshot SecondarySnapshot = NULL;
 
53
static Snapshot CurrentSnapshot = NULL;
 
54
static Snapshot SecondarySnapshot = NULL;
55
55
 
56
56
/*
57
57
 * These are updated by GetSnapshotData.  We initialize them this way
59
59
 * mode, we don't want it to say that BootstrapTransactionId is in progress.
60
60
 *
61
61
 * RecentGlobalXmin is initialized to InvalidTransactionId, to ensure that no
62
 
 * one tries to use a stale value.  Readers should ensure that it has been set
 
62
 * one tries to use a stale value.      Readers should ensure that it has been set
63
63
 * to something else before using it.
64
64
 */
65
65
TransactionId TransactionXmin = FirstNormalTransactionId;
82
82
} ActiveSnapshotElt;
83
83
 
84
84
/* Top of the stack of active snapshots */
85
 
static ActiveSnapshotElt        *ActiveSnapshot = NULL;
 
85
static ActiveSnapshotElt *ActiveSnapshot = NULL;
86
86
 
87
87
/*
88
88
 * How many snapshots is resowner.c tracking for us?
91
91
 * smarter about advancing our MyProc->xmin we will need to be more
92
92
 * sophisticated about this, perhaps keeping our own list of snapshots.
93
93
 */
94
 
static int                              RegisteredSnapshots = 0;
 
94
static int      RegisteredSnapshots = 0;
95
95
 
96
96
/* first GetTransactionSnapshot call in a transaction? */
97
 
bool                                    FirstSnapshotSet = false;
 
97
bool            FirstSnapshotSet = false;
98
98
 
99
99
/*
100
100
 * Remembers whether this transaction registered a serializable snapshot at
101
101
 * start.  We cannot trust FirstSnapshotSet in combination with
102
102
 * IsXactIsoLevelSerializable, because GUC may be reset before us.
103
103
 */
104
 
static bool                             registered_serializable = false;
 
104
static bool registered_serializable = false;
105
105
 
106
106
 
107
107
static Snapshot CopySnapshot(Snapshot snapshot);
108
108
static void FreeSnapshot(Snapshot snapshot);
109
 
static void     SnapshotResetXmin(void);
 
109
static void SnapshotResetXmin(void);
110
110
 
111
111
 
112
112
/*
130
130
                FirstSnapshotSet = true;
131
131
 
132
132
                /*
133
 
                 * In serializable mode, the first snapshot must live until end of xact
134
 
                 * regardless of what the caller does with it, so we must register it
135
 
                 * internally here and unregister it at end of xact.
 
133
                 * In serializable mode, the first snapshot must live until end of
 
134
                 * xact regardless of what the caller does with it, so we must
 
135
                 * register it internally here and unregister it at end of xact.
136
136
                 */
137
137
                if (IsXactIsoLevelSerializable)
138
138
                {
139
139
                        CurrentSnapshot = RegisterSnapshotOnOwner(CurrentSnapshot,
140
 
                                                                                                          TopTransactionResourceOwner);
 
140
                                                                                                TopTransactionResourceOwner);
141
141
                        registered_serializable = true;
142
142
                }
143
143
 
171
171
 
172
172
/*
173
173
 * SnapshotSetCommandId
174
 
 *              Propagate CommandCounterIncrement into the static snapshots, if set
 
174
 *              Propagate CommandCounterIncrement into the static snapshots, if set
175
175
 */
176
176
void
177
177
SnapshotSetCommandId(CommandId curcid)
253
253
 
254
254
/*
255
255
 * PushActiveSnapshot
256
 
 *              Set the given snapshot as the current active snapshot
 
256
 *              Set the given snapshot as the current active snapshot
257
257
 *
258
258
 * If this is the first use of this snapshot, create a new long-lived copy with
259
259
 * active refcount=1.  Otherwise, only increment the refcount.
261
261
void
262
262
PushActiveSnapshot(Snapshot snap)
263
263
{
264
 
        ActiveSnapshotElt       *newactive;
 
264
        ActiveSnapshotElt *newactive;
265
265
 
266
266
        Assert(snap != InvalidSnapshot);
267
267
 
278
278
 
279
279
/*
280
280
 * PushUpdatedSnapshot
281
 
 *              As above, except we set the snapshot's CID to the current CID.
 
281
 *              As above, except we set the snapshot's CID to the current CID.
282
282
 */
283
283
void
284
284
PushUpdatedSnapshot(Snapshot snapshot)
304
304
void
305
305
PopActiveSnapshot(void)
306
306
{
307
 
        ActiveSnapshotElt       *newstack;
 
307
        ActiveSnapshotElt *newstack;
308
308
 
309
309
        newstack = ActiveSnapshot->as_next;
310
310
 
324
324
 
325
325
/*
326
326
 * GetActiveSnapshot
327
 
 *              Return the topmost snapshot in the Active stack.
 
327
 *              Return the topmost snapshot in the Active stack.
328
328
 */
329
329
Snapshot
330
330
GetActiveSnapshot(void)
336
336
 
337
337
/*
338
338
 * ActiveSnapshotSet
339
 
 *              Return whether there is at least one snapshot in the Active stack
 
339
 *              Return whether there is at least one snapshot in the Active stack
340
340
 */
341
341
bool
342
342
ActiveSnapshotSet(void)
346
346
 
347
347
/*
348
348
 * RegisterSnapshot
349
 
 *              Register a snapshot as being in use by the current resource owner
 
349
 *              Register a snapshot as being in use by the current resource owner
350
350
 *
351
351
 * If InvalidSnapshot is passed, it is not registered.
352
352
 */
361
361
 
362
362
/*
363
363
 * RegisterSnapshotOnOwner
364
 
 *              As above, but use the specified resource owner
 
364
 *              As above, but use the specified resource owner
365
365
 */
366
366
Snapshot
367
367
RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
368
368
{
369
 
        Snapshot                snap;
 
369
        Snapshot        snap;
370
370
 
371
371
        if (snapshot == InvalidSnapshot)
372
372
                return InvalidSnapshot;
402
402
 
403
403
/*
404
404
 * UnregisterSnapshotFromOwner
405
 
 *              As above, but use the specified resource owner
 
405
 *              As above, but use the specified resource owner
406
406
 */
407
407
void
408
408
UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
442
442
void
443
443
AtSubCommit_Snapshot(int level)
444
444
{
445
 
        ActiveSnapshotElt       *active;
 
445
        ActiveSnapshotElt *active;
446
446
 
447
447
        /*
448
448
         * Relabel the active snapshots set in this subtransaction as though they
458
458
 
459
459
/*
460
460
 * AtSubAbort_Snapshot
461
 
 *              Clean up snapshots after a subtransaction abort
 
461
 *              Clean up snapshots after a subtransaction abort
462
462
 */
463
463
void
464
464
AtSubAbort_Snapshot(int level)
466
466
        /* Forget the active snapshots set by this subtransaction */
467
467
        while (ActiveSnapshot && ActiveSnapshot->as_level >= level)
468
468
        {
469
 
                ActiveSnapshotElt       *next;
 
469
                ActiveSnapshotElt *next;
470
470
 
471
471
                next = ActiveSnapshot->as_next;
472
472
 
500
500
AtEarlyCommit_Snapshot(void)
501
501
{
502
502
        /*
503
 
         * On a serializable transaction we must unregister our private refcount to
504
 
         * the serializable snapshot.
 
503
         * On a serializable transaction we must unregister our private refcount
 
504
         * to the serializable snapshot.
505
505
         */
506
506
        if (registered_serializable)
507
507
                UnregisterSnapshotFromOwner(CurrentSnapshot,
512
512
 
513
513
/*
514
514
 * AtEOXact_Snapshot
515
 
 *              Snapshot manager's cleanup function for end of transaction
 
515
 *              Snapshot manager's cleanup function for end of transaction
516
516
 */
517
517
void
518
518
AtEOXact_Snapshot(bool isCommit)
520
520
        /* On commit, complain about leftover snapshots */
521
521
        if (isCommit)
522
522
        {
523
 
                ActiveSnapshotElt       *active;
 
523
                ActiveSnapshotElt *active;
524
524
 
525
525
                if (RegisteredSnapshots != 0)
526
526
                        elog(WARNING, "%d registered snapshots seem to remain after cleanup",