The following test flashes snapshot leak warning and subsequently dumps core. Though this looks very similar to other bug report, this is a different issue.
postgres=# BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE ; BEGIN postgres=# SAVEPOINT A; SAVEPOINT postgres=# SELECT count(*) from pg_class; count ------- 227 (1 row) postgres=# RELEASE SAVEPOINT A; WARNING: Snapshot reference leak: Snapshot 0x9e3e4d4 still referenced RELEASE postgres=# SELECT count(*) from pg_class; server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed. !> I looked at this briefly and ISTM that there are couple of issues here: 1. Since "SAVEPOINT A" is the first statement in the transaction, a subtransaction is started and CurrentResourceOwner is set to the resource owner of the subtransaction. Later when serializable snapshot is taken, its recorded in the subtransaction resource owner. Obviously, when the subtransaction commits, it complains about the snapshot leak because the serializable snapshot is not yet unregistered. So I tried to ensure that the serializable snapshot is always recorded in the TopTransactionResourceOwner. It solved the above issue, but there is still a core dump when the top transaction is committed. That leads to the second issue. 2. In CommitTransaction(), I think we should call AtEOXact_Snapshot *before* releasing the resource owners. Otherwise, ResourceOwnerReleaseInternal complains about snapshot leak and then forcefully unregisters the snapshot. Later when AtEOXact_Snapshot is called, it again tries to unregister the serializable snapshot and assertion fails. The attached patch fixes these issues. Thanks, Pavan -- Pavan Deolasee EnterpriseDB http://www.enterprisedb.com
Index: src/backend/access/transam/xact.c =================================================================== RCS file: /repositories/postgreshome/cvs/pgsql/src/backend/access/transam/xact.c,v retrieving revision 1.269 diff -c -p -r1.269 xact.c *** src/backend/access/transam/xact.c 19 Nov 2008 10:34:50 -0000 1.269 --- src/backend/access/transam/xact.c 3 Dec 2008 12:47:35 -0000 *************** CommitTransaction(void) *** 1685,1690 **** --- 1685,1691 ---- smgrDoPendingDeletes(true); AtEOXact_MultiXact(); + AtEOXact_Snapshot(true); ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_LOCKS, *************** CommitTransaction(void) *** 1706,1712 **** AtEOXact_ComboCid(); AtEOXact_HashTables(true); AtEOXact_PgStat(true); - AtEOXact_Snapshot(true); pgstat_report_xact_timestamp(0); CurrentResourceOwner = NULL; --- 1707,1712 ---- Index: src/backend/utils/time/snapmgr.c =================================================================== RCS file: /repositories/postgreshome/cvs/pgsql/src/backend/utils/time/snapmgr.c,v retrieving revision 1.7 diff -c -p -r1.7 snapmgr.c *** src/backend/utils/time/snapmgr.c 25 Nov 2008 20:28:29 -0000 1.7 --- src/backend/utils/time/snapmgr.c 3 Dec 2008 12:47:36 -0000 *************** GetTransactionSnapshot(void) *** 136,142 **** --- 136,145 ---- */ if (IsXactIsoLevelSerializable) { + ResourceOwner oldowner = CurrentResourceOwner; + CurrentResourceOwner = TopTransactionResourceOwner; CurrentSnapshot = RegisterSnapshot(CurrentSnapshot); + CurrentResourceOwner = oldowner; registered_serializable = true; } *************** AtEOXact_Snapshot(bool isCommit) *** 480,486 **** --- 483,494 ---- * refcount to the serializable snapshot. */ if (registered_serializable) + { + ResourceOwner oldowner = CurrentResourceOwner; + CurrentResourceOwner = TopTransactionResourceOwner; UnregisterSnapshot(CurrentSnapshot); + CurrentResourceOwner = oldowner; + } if (RegisteredSnapshots != 0) elog(WARNING, "%d registered snapshots seem to remain after cleanup",
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers