diff options
author | Tom Lane | 2001-01-12 21:54:01 +0000 |
---|---|---|
committer | Tom Lane | 2001-01-12 21:54:01 +0000 |
commit | 6162432de9fb023b710c171f196e27b910e45fa7 (patch) | |
tree | 51bba2e60ca2d3497b365b23edd52d52574faae2 /src/backend/access | |
parent | be8477bc3718a05b02dd7e9f8236c16394f9a027 (diff) |
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().
Diffstat (limited to 'src/backend/access')
-rw-r--r-- | src/backend/access/heap/heapam.c | 14 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtinsert.c | 14 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtpage.c | 10 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 10 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 24 |
5 files changed, 36 insertions, 36 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 612e4c68611..db443218b4d 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -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); diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index cdd5c6d6207..1aae86c0025 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -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); diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index e2e403a2afc..81faf71c9d4 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -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); diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 50f4f1a1009..e3f4a5618f7 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -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(); } /* diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index c0b6104db5a..e995b06f914 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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; } |