mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Improve snapshot manager by keeping explicit track of snapshots.
There are two ways to track a snapshot: there's the "registered" list, which is used for arbitrary long-lived snapshots; and there's the "active stack", which is used for the snapshot that is considered "active" at any time. This also allows users of snapshots to stop worrying about snapshot memory allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot assignment. This is all done automatically now. As a consequence, this allows us to reset MyProc->xmin when there are no more snapshots registered in the current backend, reducing the impact that long-running transactions have on VACUUM.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.232 2008/05/12 00:00:48 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.233 2008/05/12 20:01:59 alvherre Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -2976,6 +2976,7 @@ void
|
||||
AfterTriggerFireDeferred(void)
|
||||
{
|
||||
AfterTriggerEventList *events;
|
||||
bool snap_pushed = false;
|
||||
|
||||
/* Must be inside a transaction */
|
||||
Assert(afterTriggers != NULL);
|
||||
@ -2990,7 +2991,10 @@ AfterTriggerFireDeferred(void)
|
||||
*/
|
||||
events = &afterTriggers->events;
|
||||
if (events->head != NULL)
|
||||
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
|
||||
{
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
snap_pushed = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Run all the remaining triggers. Loop until they are all gone, in case
|
||||
@ -3003,6 +3007,9 @@ AfterTriggerFireDeferred(void)
|
||||
afterTriggerInvokeEvents(events, firing_id, NULL, true);
|
||||
}
|
||||
|
||||
if (snap_pushed)
|
||||
PopActiveSnapshot();
|
||||
|
||||
Assert(events->head == NULL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user