1
0
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:
Alvaro Herrera
2008-05-12 20:02:02 +00:00
parent aa82790fca
commit 5da9da71c4
27 changed files with 995 additions and 551 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.551 2008/05/12 00:00:50 alvherre Exp $
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.552 2008/05/12 20:02:01 alvherre Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -732,49 +732,37 @@ List *
pg_plan_queries(List *querytrees, int cursorOptions, ParamListInfo boundParams,
bool needSnapshot)
{
List * volatile stmt_list = NIL;
Snapshot saveActiveSnapshot = ActiveSnapshot;
List *stmt_list = NIL;
ListCell *query_list;
bool snapshot_set = false;
/* PG_TRY to ensure previous ActiveSnapshot is restored on error */
PG_TRY();
foreach(query_list, querytrees)
{
Snapshot mySnapshot = NULL;
ListCell *query_list;
Query *query = (Query *) lfirst(query_list);
Node *stmt;
foreach(query_list, querytrees)
if (query->commandType == CMD_UTILITY)
{
Query *query = (Query *) lfirst(query_list);
Node *stmt;
if (query->commandType == CMD_UTILITY)
/* Utility commands have no plans. */
stmt = query->utilityStmt;
}
else
{
if (needSnapshot && !snapshot_set)
{
/* Utility commands have no plans. */
stmt = query->utilityStmt;
}
else
{
if (needSnapshot && mySnapshot == NULL)
{
mySnapshot = CopySnapshot(GetTransactionSnapshot());
ActiveSnapshot = mySnapshot;
}
stmt = (Node *) pg_plan_query(query, cursorOptions,
boundParams);
PushActiveSnapshot(GetTransactionSnapshot());
snapshot_set = true;
}
stmt_list = lappend(stmt_list, stmt);
stmt = (Node *) pg_plan_query(query, cursorOptions,
boundParams);
}
if (mySnapshot)
FreeSnapshot(mySnapshot);
stmt_list = lappend(stmt_list, stmt);
}
PG_CATCH();
{
ActiveSnapshot = saveActiveSnapshot;
PG_RE_THROW();
}
PG_END_TRY();
ActiveSnapshot = saveActiveSnapshot;
if (snapshot_set)
PopActiveSnapshot();
return stmt_list;
}