Commit 23645f05 authored by Tom Lane's avatar Tom Lane

Fix incorrect ordering of smgr cleanup relative to buffer pin cleanup

during transaction abort.  Add a regression test case to catch related
mistakes in future.  Alvaro Herrera and Tom Lane.
parent eb917c1a
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.185 2004/08/30 19:00:03 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.186 2004/09/06 17:56:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1333,9 +1333,6 @@ CommitTransaction(void) ...@@ -1333,9 +1333,6 @@ CommitTransaction(void)
* backend-wide state. * backend-wide state.
*/ */
smgrDoPendingDeletes(true);
/* smgrcommit already done */
CallXactCallbacks(XACT_EVENT_COMMIT, InvalidTransactionId); CallXactCallbacks(XACT_EVENT_COMMIT, InvalidTransactionId);
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
...@@ -1352,6 +1349,14 @@ CommitTransaction(void) ...@@ -1352,6 +1349,14 @@ CommitTransaction(void)
*/ */
AtEOXact_Inval(true); AtEOXact_Inval(true);
/*
* Likewise, dropping of files deleted during the transaction is best done
* after releasing relcache and buffer pins. (This is not strictly
* necessary during commit, since such pins should have been released
* already, but this ordering is definitely critical during abort.)
*/
smgrDoPendingDeletes(true);
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
true, true); true, true);
...@@ -1363,6 +1368,7 @@ CommitTransaction(void) ...@@ -1363,6 +1368,7 @@ CommitTransaction(void)
AtEOXact_SPI(true); AtEOXact_SPI(true);
AtEOXact_on_commit_actions(true, s->transactionIdData); AtEOXact_on_commit_actions(true, s->transactionIdData);
AtEOXact_Namespace(true); AtEOXact_Namespace(true);
/* smgrcommit already done */
AtEOXact_Files(); AtEOXact_Files();
pgstat_count_xact_commit(); pgstat_count_xact_commit();
...@@ -1481,15 +1487,13 @@ AbortTransaction(void) ...@@ -1481,15 +1487,13 @@ AbortTransaction(void)
* ordering. * ordering.
*/ */
smgrDoPendingDeletes(false);
smgrabort();
CallXactCallbacks(XACT_EVENT_ABORT, InvalidTransactionId); CallXactCallbacks(XACT_EVENT_ABORT, InvalidTransactionId);
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS,
false, true); false, true);
AtEOXact_Inval(false); AtEOXact_Inval(false);
smgrDoPendingDeletes(false);
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
false, true); false, true);
...@@ -1501,6 +1505,7 @@ AbortTransaction(void) ...@@ -1501,6 +1505,7 @@ AbortTransaction(void)
AtEOXact_SPI(false); AtEOXact_SPI(false);
AtEOXact_on_commit_actions(false, s->transactionIdData); AtEOXact_on_commit_actions(false, s->transactionIdData);
AtEOXact_Namespace(false); AtEOXact_Namespace(false);
smgrabort();
AtEOXact_Files(); AtEOXact_Files();
pgstat_count_xact_rollback(); pgstat_count_xact_rollback();
...@@ -3014,7 +3019,6 @@ CommitSubTransaction(void) ...@@ -3014,7 +3019,6 @@ CommitSubTransaction(void)
AtSubCommit_Notify(); AtSubCommit_Notify();
AtEOSubXact_UpdatePasswordFile(true, s->transactionIdData, AtEOSubXact_UpdatePasswordFile(true, s->transactionIdData,
s->parent->transactionIdData); s->parent->transactionIdData);
AtSubCommit_smgr();
CallXactCallbacks(XACT_EVENT_COMMIT_SUB, s->parent->transactionIdData); CallXactCallbacks(XACT_EVENT_COMMIT_SUB, s->parent->transactionIdData);
...@@ -3024,6 +3028,7 @@ CommitSubTransaction(void) ...@@ -3024,6 +3028,7 @@ CommitSubTransaction(void)
AtEOSubXact_RelationCache(true, s->transactionIdData, AtEOSubXact_RelationCache(true, s->transactionIdData,
s->parent->transactionIdData); s->parent->transactionIdData);
AtEOSubXact_Inval(true); AtEOSubXact_Inval(true);
AtSubCommit_smgr();
ResourceOwnerRelease(s->curTransactionOwner, ResourceOwnerRelease(s->curTransactionOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
true, false); true, false);
...@@ -3109,8 +3114,6 @@ AbortSubTransaction(void) ...@@ -3109,8 +3114,6 @@ AbortSubTransaction(void)
RecordSubTransactionAbort(); RecordSubTransactionAbort();
/* Post-abort cleanup */ /* Post-abort cleanup */
AtSubAbort_smgr();
CallXactCallbacks(XACT_EVENT_ABORT_SUB, s->parent->transactionIdData); CallXactCallbacks(XACT_EVENT_ABORT_SUB, s->parent->transactionIdData);
ResourceOwnerRelease(s->curTransactionOwner, ResourceOwnerRelease(s->curTransactionOwner,
...@@ -3119,6 +3122,7 @@ AbortSubTransaction(void) ...@@ -3119,6 +3122,7 @@ AbortSubTransaction(void)
AtEOSubXact_RelationCache(false, s->transactionIdData, AtEOSubXact_RelationCache(false, s->transactionIdData,
s->parent->transactionIdData); s->parent->transactionIdData);
AtEOSubXact_Inval(false); AtEOSubXact_Inval(false);
AtSubAbort_smgr();
ResourceOwnerRelease(s->curTransactionOwner, ResourceOwnerRelease(s->curTransactionOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
false, false); false, false);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.81 2004/08/30 02:54:39 momjian Exp $ * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.82 2004/09/06 17:56:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -784,7 +784,7 @@ smgrcommit(void) ...@@ -784,7 +784,7 @@ smgrcommit(void)
} }
/* /*
* smgrabort() -- Abort changes made during the current transaction. * smgrabort() -- Clean up after transaction abort.
*/ */
void void
smgrabort(void) smgrabort(void)
......
...@@ -374,6 +374,21 @@ ERROR: portal "c" cannot be run ...@@ -374,6 +374,21 @@ ERROR: portal "c" cannot be run
FETCH 10 FROM c; FETCH 10 FROM c;
ERROR: portal "c" cannot be run ERROR: portal "c" cannot be run
COMMIT; COMMIT;
-- test case for problems with dropping an open relation during abort
BEGIN;
savepoint x;
CREATE TABLE koju (a INT UNIQUE);
NOTICE: CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
INSERT INTO koju VALUES (1);
INSERT INTO koju VALUES (1);
ERROR: duplicate key violates unique constraint "koju_a_key"
rollback to x;
CREATE TABLE koju (a INT UNIQUE);
NOTICE: CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
INSERT INTO koju VALUES (1);
INSERT INTO koju VALUES (1);
ERROR: duplicate key violates unique constraint "koju_a_key"
ROLLBACK;
DROP TABLE foo; DROP TABLE foo;
DROP TABLE baz; DROP TABLE baz;
DROP TABLE barbaz; DROP TABLE barbaz;
...@@ -231,6 +231,19 @@ BEGIN; ...@@ -231,6 +231,19 @@ BEGIN;
FETCH 10 FROM c; FETCH 10 FROM c;
COMMIT; COMMIT;
-- test case for problems with dropping an open relation during abort
BEGIN;
savepoint x;
CREATE TABLE koju (a INT UNIQUE);
INSERT INTO koju VALUES (1);
INSERT INTO koju VALUES (1);
rollback to x;
CREATE TABLE koju (a INT UNIQUE);
INSERT INTO koju VALUES (1);
INSERT INTO koju VALUES (1);
ROLLBACK;
DROP TABLE foo; DROP TABLE foo;
DROP TABLE baz; DROP TABLE baz;
DROP TABLE barbaz; DROP TABLE barbaz;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment