Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30963fc

Browse files
committed
Perform transaction cleanup operations in a less ad-hoc, more
principled order; in particular ensure that all shared resourcesare released before we release transaction locks. The code usedto release locks before buffer pins, which might explain an ancientnote I have about a bufmgr assertion failure I'd seen once severalyears ago, and been unable to reproduce since. (Theory: someonetrying to drop a relation might be able to reach FlushRelationBuffersbefore the last user of the relation had gotten around to droppinghis buffer pins.)
1 parent68c8bce commit30963fc

File tree

1 file changed

+26
-14
lines changed
  • src/backend/access/transam

1 file changed

+26
-14
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.134 2002/10/21 22:06:18 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.135 2002/10/22 22:44:36 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -1005,9 +1005,20 @@ CommitTransaction(void)
10051005
* This is all post-commit cleanup. Note that if an error is raised
10061006
* here, it's too late to abort the transaction. This should be just
10071007
* noncritical resource releasing.
1008+
*
1009+
* The ordering of operations is not entirely random. The idea is:
1010+
* release resources visible to other backends (eg, files, buffer pins);
1011+
* then release locks; then release backend-local resources. We want
1012+
* to release locks at the point where any backend waiting for us will
1013+
* see our transaction as being fully cleaned up.
10081014
*/
10091015

10101016
smgrDoPendingDeletes(true);
1017+
AtCommit_Cache();
1018+
AtEOXact_Buffers(true);
1019+
/* smgrcommit already done */
1020+
1021+
AtCommit_Locks();
10111022

10121023
AtEOXact_GUC(true);
10131024
AtEOXact_SPI();
@@ -1016,15 +1027,10 @@ CommitTransaction(void)
10161027
AtEOXact_nbtree();
10171028
AtEOXact_rtree();
10181029
AtEOXact_Namespace(true);
1019-
AtCommit_Cache();
1020-
AtCommit_Locks();
10211030
AtEOXact_CatCache(true);
1022-
AtCommit_Memory();
1023-
AtEOXact_Buffers(true);
10241031
AtEOXact_Files();
1025-
1026-
/* Count transaction commit in statistics collector */
10271032
pgstat_count_xact_commit();
1033+
AtCommit_Memory();
10281034

10291035
/*
10301036
* done with commit processing, set current transaction state back to
@@ -1078,6 +1084,9 @@ AbortTransaction(void)
10781084
*/
10791085
s->state=TRANS_ABORT;
10801086

1087+
/* Make sure we are in a valid memory context */
1088+
AtAbort_Memory();
1089+
10811090
/*
10821091
* Reset user id which might have been changed transiently
10831092
*/
@@ -1109,7 +1118,17 @@ AbortTransaction(void)
11091118
LWLockRelease(SInvalLock);
11101119
}
11111120

1121+
/*
1122+
* Post-abort cleanup. See notes in CommitTransaction() concerning
1123+
* ordering.
1124+
*/
1125+
11121126
smgrDoPendingDeletes(false);
1127+
AtAbort_Cache();
1128+
AtEOXact_Buffers(false);
1129+
smgrabort();
1130+
1131+
AtAbort_Locks();
11131132

11141133
AtEOXact_GUC(false);
11151134
AtEOXact_SPI();
@@ -1118,15 +1137,8 @@ AbortTransaction(void)
11181137
AtEOXact_nbtree();
11191138
AtEOXact_rtree();
11201139
AtEOXact_Namespace(false);
1121-
AtAbort_Cache();
11221140
AtEOXact_CatCache(false);
1123-
AtAbort_Memory();
1124-
AtEOXact_Buffers(false);
1125-
smgrabort();
11261141
AtEOXact_Files();
1127-
AtAbort_Locks();
1128-
1129-
/* Count transaction abort in statistics collector */
11301142
pgstat_count_xact_rollback();
11311143

11321144
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp