mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Add more critical-section calls: all code sections that hold spinlocks
are now critical sections, so as to ensure die() won't interrupt us while we are munging shared-memory data structures. Avoid insecure intermediate states in some code that proc_exit will call, like palloc/pfree. Rename START/END_CRIT_CODE to START/END_CRIT_SECTION, since that seems to be what people tend to call them anyway, and make them be called with () like a function call, in hopes of not confusing pg_indent. I doubt that this is sufficient to make SIGTERM safe anywhere; there's just too much code that could get invoked during proc_exit().
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.106 2001/01/07 22:14:31 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.107 2001/01/12 21:53:54 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -1359,7 +1359,7 @@ heap_insert(Relation relation, HeapTuple tup)
|
||||
buffer = RelationGetBufferForTuple(relation, tup->t_len);
|
||||
|
||||
/* NO ELOG(ERROR) from here till changes are logged */
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
RelationPutHeapTuple(relation, buffer, tup);
|
||||
|
||||
/* XLOG stuff */
|
||||
@@ -1405,7 +1405,7 @@ heap_insert(Relation relation, HeapTuple tup)
|
||||
PageSetLSN(page, recptr);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
}
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
|
||||
WriteBuffer(buffer);
|
||||
@@ -1503,7 +1503,7 @@ l1:
|
||||
return result;
|
||||
}
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
/* store transaction information of xact deleting the tuple */
|
||||
TransactionIdStore(GetCurrentTransactionId(), &(tp.t_data->t_xmax));
|
||||
tp.t_data->t_cmax = GetCurrentCommandId();
|
||||
@@ -1532,7 +1532,7 @@ l1:
|
||||
PageSetLSN(dp, recptr);
|
||||
PageSetSUI(dp, ThisStartUpID);
|
||||
}
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
#ifdef TUPLE_TOASTER_ACTIVE
|
||||
/* ----------
|
||||
@@ -1702,7 +1702,7 @@ l2:
|
||||
}
|
||||
|
||||
/* NO ELOG(ERROR) from here till changes are logged */
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
RelationPutHeapTuple(relation, newbuf, newtup); /* insert new tuple */
|
||||
if (buffer == newbuf)
|
||||
@@ -1734,7 +1734,7 @@ l2:
|
||||
PageSetLSN(BufferGetPage(buffer), recptr);
|
||||
PageSetSUI(BufferGetPage(buffer), ThisStartUpID);
|
||||
}
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
if (newbuf != buffer)
|
||||
LockBuffer(newbuf, BUFFER_LOCK_UNLOCK);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.72 2000/12/29 20:47:16 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.73 2001/01/12 21:53:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -518,7 +518,7 @@ _bt_insertonpg(Relation rel,
|
||||
}
|
||||
else
|
||||
{
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
_bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page");
|
||||
itup_off = newitemoff;
|
||||
itup_blkno = BufferGetBlockNumber(buf);
|
||||
@@ -563,7 +563,7 @@ _bt_insertonpg(Relation rel,
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
}
|
||||
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
/* Write out the updated page and release pin/lock */
|
||||
_bt_wrtbuf(rel, buf);
|
||||
}
|
||||
@@ -774,7 +774,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
|
||||
* NO ELOG(ERROR) till right sibling is updated.
|
||||
*
|
||||
*/
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
{
|
||||
xl_btree_split xlrec;
|
||||
int flag = (newitemonleft) ?
|
||||
@@ -863,7 +863,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
|
||||
/* write and release the old right sibling */
|
||||
if (!P_RIGHTMOST(ropaque))
|
||||
_bt_wrtbuf(rel, sbuf);
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* split's done */
|
||||
return rbuf;
|
||||
@@ -1160,7 +1160,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
|
||||
metad = BTPageGetMeta(metapg);
|
||||
|
||||
/* NO ELOG(ERROR) from here till newroot op is logged */
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
/* set btree special data */
|
||||
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
||||
@@ -1253,7 +1253,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
|
||||
PageSetSUI(metapg, ThisStartUpID);
|
||||
|
||||
}
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* write and let go of the new root buffer */
|
||||
_bt_wrtbuf(rel, rootbuf);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.45 2000/12/29 20:47:17 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.46 2001/01/12 21:53:55 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Postgres btree pages look like ordinary relation pages. The opaque
|
||||
@@ -165,7 +165,7 @@ _bt_getroot(Relation rel, int access)
|
||||
rootpage = BufferGetPage(rootbuf);
|
||||
|
||||
/* NO ELOG(ERROR) till meta is updated */
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
metad->btm_root = rootblkno;
|
||||
metad->btm_level = 1;
|
||||
@@ -197,7 +197,7 @@ _bt_getroot(Relation rel, int access)
|
||||
PageSetSUI(metapg, ThisStartUpID);
|
||||
}
|
||||
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
_bt_wrtnorelbuf(rel, rootbuf);
|
||||
|
||||
@@ -410,7 +410,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
|
||||
buf = _bt_getbuf(rel, blkno, BT_WRITE);
|
||||
page = BufferGetPage(buf);
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
PageIndexTupleDelete(page, offno);
|
||||
/* XLOG stuff */
|
||||
{
|
||||
@@ -435,7 +435,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
|
||||
PageSetLSN(page, recptr);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
}
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* write the buffer and release the lock */
|
||||
_bt_wrtbuf(rel, buf);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.91 2000/12/28 13:00:08 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.92 2001/01/12 21:53:56 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -678,7 +678,7 @@ RecordTransactionCommit()
|
||||
rdata.len = SizeOfXactCommit;
|
||||
rdata.next = NULL;
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
/*
|
||||
* SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
*/
|
||||
@@ -697,7 +697,7 @@ RecordTransactionCommit()
|
||||
TransactionIdCommit(xid);
|
||||
|
||||
MyProc->logRec.xrecoff = 0;
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
}
|
||||
|
||||
if (leak)
|
||||
@@ -800,12 +800,12 @@ RecordTransactionAbort(void)
|
||||
rdata.len = SizeOfXactAbort;
|
||||
rdata.next = NULL;
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_ABORT, &rdata);
|
||||
|
||||
TransactionIdAbort(xid);
|
||||
MyProc->logRec.xrecoff = 0;
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.48 2001/01/09 06:24:32 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.49 2001/01/12 21:53:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,7 +42,7 @@
|
||||
int XLOGbuffers = 8;
|
||||
int XLOGfiles = 0; /* how many files to pre-allocate */
|
||||
XLogRecPtr MyLastRecPtr = {0, 0};
|
||||
uint32 CritSectionCount = 0;
|
||||
volatile uint32 CritSectionCount = 0;
|
||||
bool InRecovery = false;
|
||||
StartUpID ThisStartUpID = 0;
|
||||
XLogRecPtr RedoRecPtr;
|
||||
@@ -382,7 +382,7 @@ begin:;
|
||||
if (len == 0 || len > MAXLOGRECSZ)
|
||||
elog(STOP, "XLogInsert: invalid record len %u", len);
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
/* obtain xlog insert lock */
|
||||
if (TAS(&(XLogCtl->insert_lck))) /* busy */
|
||||
@@ -447,7 +447,7 @@ begin:;
|
||||
if (repeat)
|
||||
{
|
||||
S_UNLOCK(&(XLogCtl->insert_lck));
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
goto begin;
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ begin:;
|
||||
S_UNLOCK(&(XLogCtl->info_lck));
|
||||
}
|
||||
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
return (RecPtr);
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ XLogFlush(XLogRecPtr record)
|
||||
if (XLByteLE(record, LgwrResult.Flush))
|
||||
return;
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
WriteRqst = LgwrRqst.Write;
|
||||
for (;;)
|
||||
@@ -659,7 +659,7 @@ XLogFlush(XLogRecPtr record)
|
||||
if (XLByteLE(record, LgwrResult.Flush))
|
||||
{
|
||||
S_UNLOCK(&(XLogCtl->info_lck));
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
return;
|
||||
}
|
||||
if (XLByteLT(XLogCtl->LgwrRqst.Flush, record))
|
||||
@@ -705,7 +705,7 @@ XLogFlush(XLogRecPtr record)
|
||||
if (XLByteLE(record, LgwrResult.Flush))
|
||||
{
|
||||
S_UNLOCK(&(XLogCtl->lgwr_lck));
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
return;
|
||||
}
|
||||
if (XLByteLT(LgwrResult.Write, WriteRqst))
|
||||
@@ -715,7 +715,7 @@ XLogFlush(XLogRecPtr record)
|
||||
S_UNLOCK(&(XLogCtl->lgwr_lck));
|
||||
if (XLByteLT(LgwrResult.Flush, record))
|
||||
elog(STOP, "XLogFlush: request is not satisfied");
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -756,7 +756,7 @@ XLogFlush(XLogRecPtr record)
|
||||
|
||||
S_UNLOCK(&(XLogCtl->lgwr_lck));
|
||||
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -2081,7 +2081,7 @@ CreateCheckPoint(bool shutdown)
|
||||
if (MyLastRecPtr.xrecoff != 0)
|
||||
elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block");
|
||||
|
||||
START_CRIT_CODE;
|
||||
START_CRIT_SECTION();
|
||||
|
||||
/* Grab lock, using larger than normal sleep between tries (1 sec) */
|
||||
while (TAS(&(XLogCtl->chkp_lck)))
|
||||
@@ -2230,7 +2230,7 @@ CreateCheckPoint(bool shutdown)
|
||||
S_UNLOCK(&(XLogCtl->chkp_lck));
|
||||
|
||||
MyLastRecPtr.xrecoff = 0; /* to avoid commit record */
|
||||
END_CRIT_CODE;
|
||||
END_CRIT_SECTION();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user