mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +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:
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.132 2008/04/12 23:14:21 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.133 2008/05/12 20:02:00 alvherre Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -246,12 +246,8 @@ inv_open(Oid lobjId, int flags, MemoryContext mcxt)
|
||||
}
|
||||
else if (flags & INV_READ)
|
||||
{
|
||||
/* be sure to copy snap into mcxt */
|
||||
MemoryContext oldContext = MemoryContextSwitchTo(mcxt);
|
||||
|
||||
retval->snapshot = CopySnapshot(ActiveSnapshot);
|
||||
retval->snapshot = RegisterSnapshot(GetActiveSnapshot());
|
||||
retval->flags = IFS_RDLOCK;
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "invalid flags: %d", flags);
|
||||
@@ -274,7 +270,7 @@ inv_close(LargeObjectDesc *obj_desc)
|
||||
{
|
||||
Assert(PointerIsValid(obj_desc));
|
||||
if (obj_desc->snapshot != SnapshotNow)
|
||||
FreeSnapshot(obj_desc->snapshot);
|
||||
UnregisterSnapshot(obj_desc->snapshot);
|
||||
pfree(obj_desc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user