From 5da9da71c44f27ba48fdad08ef263bf70e43e689 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 12 May 2008 20:02:02 +0000 Subject: 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. --- src/backend/commands/trigger.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/commands/trigger.c') diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 1ec24812d71..7685906aeb0 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -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); } -- cgit v1.2.3