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

Commit8934790

Browse files
committed
Add a mechanism to let dynamically loaded modules register post-commit/
post-abort cleanup hooks. I'm surprised that we have not needed thisalready, but I need it now to fix a plpgsql problem, and the usefulnessfor other dynamically loaded modules seems obvious.
1 parenta15207f commit8934790

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

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

Lines changed: 72 additions & 1 deletion
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.154 2003/09/25 06:57:57 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.155 2003/09/28 23:26:20 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -183,6 +183,7 @@ static void AtCommit_Memory(void);
183183
staticvoidAtStart_Cache(void);
184184
staticvoidAtStart_Locks(void);
185185
staticvoidAtStart_Memory(void);
186+
staticvoidCallEOXactCallbacks(boolisCommit);
186187
staticvoidCleanupTransaction(void);
187188
staticvoidCommitTransaction(void);
188189
staticvoidRecordTransactionAbort(void);
@@ -217,6 +218,18 @@ intCommitSiblings = 5; /* number of concurrent xacts needed to
217218
* sleep */
218219

219220

221+
/*
222+
* List of add-on end-of-xact callbacks
223+
*/
224+
typedefstructEOXactCallbackItem
225+
{
226+
structEOXactCallbackItem*next;
227+
EOXactCallbackcallback;
228+
void*arg;
229+
}EOXactCallbackItem;
230+
231+
staticEOXactCallbackItem*EOXact_callbacks=NULL;
232+
220233
staticvoid (*_RollbackFunc) (void*)=NULL;
221234
staticvoid*_RollbackData=NULL;
222235

@@ -964,6 +977,7 @@ CommitTransaction(void)
964977

965978
AtCommit_Locks();
966979

980+
CallEOXactCallbacks(true);
967981
AtEOXact_GUC(true);
968982
AtEOXact_SPI();
969983
AtEOXact_gist();
@@ -1073,6 +1087,7 @@ AbortTransaction(void)
10731087

10741088
AtAbort_Locks();
10751089

1090+
CallEOXactCallbacks(false);
10761091
AtEOXact_GUC(false);
10771092
AtEOXact_SPI();
10781093
AtEOXact_gist();
@@ -1430,6 +1445,62 @@ RequireTransactionChain(void *stmtNode, const char *stmtType)
14301445
}
14311446

14321447

1448+
/*
1449+
* Register or deregister callback functions for end-of-xact cleanup
1450+
*
1451+
* These functions are intended for use by dynamically loaded modules.
1452+
* For built-in modules we generally just hardwire the appropriate calls
1453+
* (mainly because it's easier to control the order that way, where needed).
1454+
*
1455+
* Note that the callback occurs post-commit or post-abort, so the callback
1456+
* functions can only do noncritical cleanup.
1457+
*/
1458+
void
1459+
RegisterEOXactCallback(EOXactCallbackcallback,void*arg)
1460+
{
1461+
EOXactCallbackItem*item;
1462+
1463+
item= (EOXactCallbackItem*)
1464+
MemoryContextAlloc(TopMemoryContext,sizeof(EOXactCallbackItem));
1465+
item->callback=callback;
1466+
item->arg=arg;
1467+
item->next=EOXact_callbacks;
1468+
EOXact_callbacks=item;
1469+
}
1470+
1471+
void
1472+
UnregisterEOXactCallback(EOXactCallbackcallback,void*arg)
1473+
{
1474+
EOXactCallbackItem*item;
1475+
EOXactCallbackItem*prev;
1476+
1477+
prev=NULL;
1478+
for (item=EOXact_callbacks;item;prev=item,item=item->next)
1479+
{
1480+
if (item->callback==callback&&item->arg==arg)
1481+
{
1482+
if (prev)
1483+
prev->next=item->next;
1484+
else
1485+
EOXact_callbacks=item->next;
1486+
pfree(item);
1487+
break;
1488+
}
1489+
}
1490+
}
1491+
1492+
staticvoid
1493+
CallEOXactCallbacks(boolisCommit)
1494+
{
1495+
EOXactCallbackItem*item;
1496+
1497+
for (item=EOXact_callbacks;item;item=item->next)
1498+
{
1499+
(*item->callback) (isCommit,item->arg);
1500+
}
1501+
}
1502+
1503+
14331504
/* ----------------------------------------------------------------
14341505
* transaction block support
14351506
* ----------------------------------------------------------------

‎src/include/access/xact.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: xact.h,v 1.55 2003/08/08 21:42:32 momjian Exp $
10+
* $Id: xact.h,v 1.56 2003/09/28 23:26:20 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -59,9 +59,13 @@ typedef enum TBlockState
5959
TBLOCK_ENDABORT
6060
}TBlockState;
6161

62-
/* ----------------
63-
*transaction state structure
64-
* ----------------
62+
/*
63+
*end-of-transaction cleanup callbacks for dynamically loaded modules
64+
*/
65+
typedefvoid (*EOXactCallback) (boolisCommit,void*arg);
66+
67+
/*
68+
*transaction state structure
6569
*/
6670
typedefstructTransactionStateData
6771
{
@@ -130,6 +134,8 @@ extern void UserAbortTransactionBlock(void);
130134
externvoidAbortOutOfAnyTransaction(void);
131135
externvoidPreventTransactionChain(void*stmtNode,constchar*stmtType);
132136
externvoidRequireTransactionChain(void*stmtNode,constchar*stmtType);
137+
externvoidRegisterEOXactCallback(EOXactCallbackcallback,void*arg);
138+
externvoidUnregisterEOXactCallback(EOXactCallbackcallback,void*arg);
133139

134140
externvoidRecordTransactionCommit(void);
135141

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp