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

« back to all changes in this revision

Viewing changes to src/backend/access/transam/xact.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:
10
10
 *
11
11
 *
12
12
 * IDENTIFICATION
13
 
 *        $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.273 2009/05/13 20:27:17 tgl Exp $
 
13
 *        $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.274 2009/06/11 14:48:54 momjian Exp $
14
14
 *
15
15
 *-------------------------------------------------------------------------
16
16
 */
456
456
 *
457
457
 * "used" must be TRUE if the caller intends to use the command ID to mark
458
458
 * inserted/updated/deleted tuples.  FALSE means the ID is being fetched
459
 
 * for read-only purposes (ie, as a snapshot validity cutoff).  See
 
459
 * for read-only purposes (ie, as a snapshot validity cutoff).  See
460
460
 * CommandCounterIncrement() for discussion.
461
461
 */
462
462
CommandId
566
566
         */
567
567
        for (s = CurrentTransactionState; s != NULL; s = s->parent)
568
568
        {
569
 
                int low, high;
 
569
                int                     low,
 
570
                                        high;
570
571
 
571
572
                if (s->state == TRANS_ABORT)
572
573
                        continue;
579
580
                high = s->nChildXids - 1;
580
581
                while (low <= high)
581
582
                {
582
 
                        int                             middle;
583
 
                        TransactionId   probe;
 
583
                        int                     middle;
 
584
                        TransactionId probe;
584
585
 
585
586
                        middle = low + (high - low) / 2;
586
587
                        probe = s->childXids[middle];
604
605
CommandCounterIncrement(void)
605
606
{
606
607
        /*
607
 
         * If the current value of the command counter hasn't been "used" to
608
 
         * mark tuples, we need not increment it, since there's no need to
609
 
         * distinguish a read-only command from others.  This helps postpone
610
 
         * command counter overflow, and keeps no-op CommandCounterIncrement
611
 
         * operations cheap.
 
608
         * If the current value of the command counter hasn't been "used" to mark
 
609
         * tuples, we need not increment it, since there's no need to distinguish
 
610
         * a read-only command from others.  This helps postpone command counter
 
611
         * overflow, and keeps no-op CommandCounterIncrement operations cheap.
612
612
         */
613
613
        if (currentCommandIdUsed)
614
614
        {
615
615
                currentCommandId += 1;
616
 
                if (currentCommandId == FirstCommandId) /* check for overflow */
 
616
                if (currentCommandId == FirstCommandId) /* check for overflow */
617
617
                {
618
618
                        currentCommandId -= 1;
619
619
                        ereport(ERROR,
620
620
                                        (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
621
 
                  errmsg("cannot have more than 2^32-1 commands in a transaction")));
 
621
                                         errmsg("cannot have more than 2^32-1 commands in a transaction")));
622
622
                }
623
623
                currentCommandIdUsed = false;
624
624
 
625
625
                /* Propagate new command ID into static snapshots */
626
626
                SnapshotSetCommandId(currentCommandId);
627
 
                
 
627
 
628
628
                /*
629
 
                 * Make any catalog changes done by the just-completed command
630
 
                 * visible in the local syscache.  We obviously don't need to do
631
 
                 * this after a read-only command.  (But see hacks in inval.c
632
 
                 * to make real sure we don't think a command that queued inval
633
 
                 * messages was read-only.)
 
629
                 * Make any catalog changes done by the just-completed command visible
 
630
                 * in the local syscache.  We obviously don't need to do this after a
 
631
                 * read-only command.  (But see hacks in inval.c to make real sure we
 
632
                 * don't think a command that queued inval messages was read-only.)
634
633
                 */
635
634
                AtCommit_LocalCache();
636
635
        }
638
637
        /*
639
638
         * Make any other backends' catalog changes visible to me.
640
639
         *
641
 
         * XXX this is probably in the wrong place: CommandCounterIncrement
642
 
         * should be purely a local operation, most likely.  However fooling
643
 
         * with this will affect asynchronous cross-backend interactions,
644
 
         * which doesn't seem like a wise thing to do in late beta, so save
645
 
         * improving this for another day - tgl 2007-11-30
 
640
         * XXX this is probably in the wrong place: CommandCounterIncrement should
 
641
         * be purely a local operation, most likely.  However fooling with this
 
642
         * will affect asynchronous cross-backend interactions, which doesn't seem
 
643
         * like a wise thing to do in late beta, so save improving this for
 
644
         * another day - tgl 2007-11-30
646
645
         */
647
646
        AtStart_Cache();
648
647
}
1086
1085
        /* Allocate or enlarge the parent array if necessary */
1087
1086
        if (s->parent->maxChildXids < new_nChildXids)
1088
1087
        {
1089
 
                int                             new_maxChildXids;
1090
 
                TransactionId  *new_childXids;
 
1088
                int                     new_maxChildXids;
 
1089
                TransactionId *new_childXids;
1091
1090
 
1092
1091
                /*
1093
1092
                 * Make it 2x what's needed right now, to avoid having to enlarge it
1094
 
                 * repeatedly. But we can't go above MaxAllocSize.  (The latter
1095
 
                 * limit is what ensures that we don't need to worry about integer
1096
 
                 * overflow here or in the calculation of new_nChildXids.)
 
1093
                 * repeatedly. But we can't go above MaxAllocSize.  (The latter limit
 
1094
                 * is what ensures that we don't need to worry about integer overflow
 
1095
                 * here or in the calculation of new_nChildXids.)
1097
1096
                 */
1098
1097
                new_maxChildXids = Min(new_nChildXids * 2,
1099
1098
                                                           (int) (MaxAllocSize / sizeof(TransactionId)));
1111
1110
                 */
1112
1111
                if (s->parent->childXids == NULL)
1113
1112
                        new_childXids =
1114
 
                                MemoryContextAlloc(TopTransactionContext, 
 
1113
                                MemoryContextAlloc(TopTransactionContext,
1115
1114
                                                                   new_maxChildXids * sizeof(TransactionId));
1116
1115
                else
1117
 
                        new_childXids = repalloc(s->parent->childXids, 
1118
 
                                                                         new_maxChildXids * sizeof(TransactionId));
 
1116
                        new_childXids = repalloc(s->parent->childXids,
 
1117
                                                                   new_maxChildXids * sizeof(TransactionId));
1119
1118
 
1120
 
                s->parent->childXids  = new_childXids;
 
1119
                s->parent->childXids = new_childXids;
1121
1120
                s->parent->maxChildXids = new_maxChildXids;
1122
1121
        }
1123
1122
 
1126
1125
         *
1127
1126
         * Note: We rely on the fact that the XID of a child always follows that
1128
1127
         * of its parent.  By copying the XID of this subtransaction before the
1129
 
         * XIDs of its children, we ensure that the array stays ordered.  Likewise,
1130
 
         * all XIDs already in the array belong to subtransactions started and
1131
 
         * subcommitted before us, so their XIDs must precede ours.
 
1128
         * XIDs of its children, we ensure that the array stays ordered.
 
1129
         * Likewise, all XIDs already in the array belong to subtransactions
 
1130
         * started and subcommitted before us, so their XIDs must precede ours.
1132
1131
         */
1133
1132
        s->parent->childXids[s->parent->nChildXids] = s->transactionId;
1134
1133
 
1801
1800
        /* NOTIFY and flatfiles will be handled below */
1802
1801
 
1803
1802
        /*
1804
 
         * Don't allow PREPARE TRANSACTION if we've accessed a temporary table
1805
 
         * in this transaction.  Having the prepared xact hold locks on another
 
1803
         * Don't allow PREPARE TRANSACTION if we've accessed a temporary table in
 
1804
         * this transaction.  Having the prepared xact hold locks on another
1806
1805
         * backend's temp table seems a bad idea --- for instance it would prevent
1807
 
         * the backend from exiting.  There are other problems too, such as how
1808
 
         * to clean up the source backend's local buffers and ON COMMIT state
1809
 
         * if the prepared xact includes a DROP of a temp table.
 
1806
         * the backend from exiting.  There are other problems too, such as how to
 
1807
         * clean up the source backend's local buffers and ON COMMIT state if the
 
1808
         * prepared xact includes a DROP of a temp table.
1810
1809
         *
1811
 
         * We must check this after executing any ON COMMIT actions, because
1812
 
         * they might still access a temp relation.
 
1810
         * We must check this after executing any ON COMMIT actions, because they
 
1811
         * might still access a temp relation.
1813
1812
         *
1814
1813
         * XXX In principle this could be relaxed to allow some useful special
1815
1814
         * cases, such as a temp table created and dropped all within the
2021
2020
        /*
2022
2021
         * Reset user ID which might have been changed transiently.  We need this
2023
2022
         * to clean up in case control escaped out of a SECURITY DEFINER function
2024
 
         * or other local change of CurrentUserId; therefore, the prior value
2025
 
         * of SecurityDefinerContext also needs to be restored.
 
2023
         * or other local change of CurrentUserId; therefore, the prior value of
 
2024
         * SecurityDefinerContext also needs to be restored.
2026
2025
         *
2027
2026
         * (Note: it is not necessary to restore session authorization or role
2028
2027
         * settings here because those can only be changed via GUC, and GUC will
3749
3748
        /* Must CCI to ensure commands of subtransaction are seen as done */
3750
3749
        CommandCounterIncrement();
3751
3750
 
3752
 
        /* 
3753
 
         * Prior to 8.4 we marked subcommit in clog at this point.  We now only
 
3751
        /*
 
3752
         * Prior to 8.4 we marked subcommit in clog at this point.      We now only
3754
3753
         * perform that step, if required, as part of the atomic update of the
3755
3754
         * whole transaction tree at top level commit or abort.
3756
3755
         */
3868
3867
        s->state = TRANS_ABORT;
3869
3868
 
3870
3869
        /*
3871
 
         * Reset user ID which might have been changed transiently.  (See notes
3872
 
         * in AbortTransaction.)
 
3870
         * Reset user ID which might have been changed transiently.  (See notes in
 
3871
         * AbortTransaction.)
3873
3872
         */
3874
3873
        SetUserIdAndContext(s->prevUser, s->prevSecDefCxt);
3875
3874
 
4089
4088
 
4090
4089
        if (s->nChildXids > 0)
4091
4090
        {
4092
 
                int i;
 
4091
                int                     i;
4093
4092
 
4094
4093
                appendStringInfo(&buf, "%u", s->childXids[0]);
4095
4094
                for (i = 1; i < s->nChildXids; i++)
4241
4240
        for (i = 0; i < xlrec->nrels; i++)
4242
4241
        {
4243
4242
                SMgrRelation srel = smgropen(xlrec->xnodes[i]);
4244
 
                ForkNumber fork;
 
4243
                ForkNumber      fork;
4245
4244
 
4246
4245
                for (fork = 0; fork <= MAX_FORKNUM; fork++)
4247
4246
                {
4284
4283
        for (i = 0; i < xlrec->nrels; i++)
4285
4284
        {
4286
4285
                SMgrRelation srel = smgropen(xlrec->xnodes[i]);
4287
 
                ForkNumber fork;
 
4286
                ForkNumber      fork;
4288
4287
 
4289
4288
                for (fork = 0; fork <= MAX_FORKNUM; fork++)
4290
4289
                {
4353
4352
                appendStringInfo(buf, "; rels:");
4354
4353
                for (i = 0; i < xlrec->nrels; i++)
4355
4354
                {
4356
 
                        char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
 
4355
                        char       *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
 
4356
 
4357
4357
                        appendStringInfo(buf, " %s", path);
4358
4358
                        pfree(path);
4359
4359
                }
4380
4380
                appendStringInfo(buf, "; rels:");
4381
4381
                for (i = 0; i < xlrec->nrels; i++)
4382
4382
                {
4383
 
                        char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
 
4383
                        char       *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
 
4384
 
4384
4385
                        appendStringInfo(buf, " %s", path);
4385
4386
                        pfree(path);
4386
4387
                }