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

Commit6162432

Browse files
committed
Add more critical-section calls: all code sections that hold spinlocks
are now critical sections, so as to ensure die() won't interrupt us whilewe are munging shared-memory data structures. Avoid insecure intermediatestates in some code that proc_exit will call, like palloc/pfree. RenameSTART/END_CRIT_CODE to START/END_CRIT_SECTION, since that seems to bewhat people tend to call them anyway, and make them be called with () likea function call, in hopes of not confusing pg_indent.I doubt that this is sufficient to make SIGTERM safe anywhere; there'sjust too much code that could get invoked during proc_exit().
1 parentbe8477b commit6162432

File tree

17 files changed

+163
-129
lines changed

17 files changed

+163
-129
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.106 2001/01/07 22:14:31 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.107 2001/01/12 21:53:54 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1359,7 +1359,7 @@ heap_insert(Relation relation, HeapTuple tup)
13591359
buffer=RelationGetBufferForTuple(relation,tup->t_len);
13601360

13611361
/* NO ELOG(ERROR) from here till changes are logged */
1362-
START_CRIT_CODE;
1362+
START_CRIT_SECTION();
13631363
RelationPutHeapTuple(relation,buffer,tup);
13641364

13651365
/* XLOG stuff */
@@ -1405,7 +1405,7 @@ heap_insert(Relation relation, HeapTuple tup)
14051405
PageSetLSN(page,recptr);
14061406
PageSetSUI(page,ThisStartUpID);
14071407
}
1408-
END_CRIT_CODE;
1408+
END_CRIT_SECTION();
14091409

14101410
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
14111411
WriteBuffer(buffer);
@@ -1503,7 +1503,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
15031503
returnresult;
15041504
}
15051505

1506-
START_CRIT_CODE;
1506+
START_CRIT_SECTION();
15071507
/* store transaction information of xact deleting the tuple */
15081508
TransactionIdStore(GetCurrentTransactionId(),&(tp.t_data->t_xmax));
15091509
tp.t_data->t_cmax=GetCurrentCommandId();
@@ -1532,7 +1532,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
15321532
PageSetLSN(dp,recptr);
15331533
PageSetSUI(dp,ThisStartUpID);
15341534
}
1535-
END_CRIT_CODE;
1535+
END_CRIT_SECTION();
15361536

15371537
#ifdefTUPLE_TOASTER_ACTIVE
15381538
/* ----------
@@ -1702,7 +1702,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
17021702
}
17031703

17041704
/* NO ELOG(ERROR) from here till changes are logged */
1705-
START_CRIT_CODE;
1705+
START_CRIT_SECTION();
17061706

17071707
RelationPutHeapTuple(relation,newbuf,newtup);/* insert new tuple */
17081708
if (buffer==newbuf)
@@ -1734,7 +1734,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
17341734
PageSetLSN(BufferGetPage(buffer),recptr);
17351735
PageSetSUI(BufferGetPage(buffer),ThisStartUpID);
17361736
}
1737-
END_CRIT_CODE;
1737+
END_CRIT_SECTION();
17381738

17391739
if (newbuf!=buffer)
17401740
LockBuffer(newbuf,BUFFER_LOCK_UNLOCK);

‎src/backend/access/nbtree/nbtinsert.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.72 2000/12/29 20:47:16 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.73 2001/01/12 21:53:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -518,7 +518,7 @@ _bt_insertonpg(Relation rel,
518518
}
519519
else
520520
{
521-
START_CRIT_CODE;
521+
START_CRIT_SECTION();
522522
_bt_pgaddtup(rel,page,itemsz,btitem,newitemoff,"page");
523523
itup_off=newitemoff;
524524
itup_blkno=BufferGetBlockNumber(buf);
@@ -563,7 +563,7 @@ _bt_insertonpg(Relation rel,
563563
PageSetSUI(page,ThisStartUpID);
564564
}
565565

566-
END_CRIT_CODE;
566+
END_CRIT_SECTION();
567567
/* Write out the updated page and release pin/lock */
568568
_bt_wrtbuf(rel,buf);
569569
}
@@ -774,7 +774,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
774774
* NO ELOG(ERROR) till right sibling is updated.
775775
*
776776
*/
777-
START_CRIT_CODE;
777+
START_CRIT_SECTION();
778778
{
779779
xl_btree_splitxlrec;
780780
intflag= (newitemonleft) ?
@@ -863,7 +863,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
863863
/* write and release the old right sibling */
864864
if (!P_RIGHTMOST(ropaque))
865865
_bt_wrtbuf(rel,sbuf);
866-
END_CRIT_CODE;
866+
END_CRIT_SECTION();
867867

868868
/* split's done */
869869
returnrbuf;
@@ -1160,7 +1160,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11601160
metad=BTPageGetMeta(metapg);
11611161

11621162
/* NO ELOG(ERROR) from here till newroot op is logged */
1163-
START_CRIT_CODE;
1163+
START_CRIT_SECTION();
11641164

11651165
/* set btree special data */
11661166
rootopaque= (BTPageOpaque)PageGetSpecialPointer(rootpage);
@@ -1253,7 +1253,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
12531253
PageSetSUI(metapg,ThisStartUpID);
12541254

12551255
}
1256-
END_CRIT_CODE;
1256+
END_CRIT_SECTION();
12571257

12581258
/* write and let go of the new root buffer */
12591259
_bt_wrtbuf(rel,rootbuf);

‎src/backend/access/nbtree/nbtpage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.45 2000/12/29 20:47:17 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.46 2001/01/12 21:53:55 tgl Exp $
1313
*
1414
*NOTES
1515
* Postgres btree pages look like ordinary relation pages.The opaque
@@ -165,7 +165,7 @@ _bt_getroot(Relation rel, int access)
165165
rootpage=BufferGetPage(rootbuf);
166166

167167
/* NO ELOG(ERROR) till meta is updated */
168-
START_CRIT_CODE;
168+
START_CRIT_SECTION();
169169

170170
metad->btm_root=rootblkno;
171171
metad->btm_level=1;
@@ -197,7 +197,7 @@ _bt_getroot(Relation rel, int access)
197197
PageSetSUI(metapg,ThisStartUpID);
198198
}
199199

200-
END_CRIT_CODE;
200+
END_CRIT_SECTION();
201201

202202
_bt_wrtnorelbuf(rel,rootbuf);
203203

@@ -410,7 +410,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
410410
buf=_bt_getbuf(rel,blkno,BT_WRITE);
411411
page=BufferGetPage(buf);
412412

413-
START_CRIT_CODE;
413+
START_CRIT_SECTION();
414414
PageIndexTupleDelete(page,offno);
415415
/* XLOG stuff */
416416
{
@@ -435,7 +435,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
435435
PageSetLSN(page,recptr);
436436
PageSetSUI(page,ThisStartUpID);
437437
}
438-
END_CRIT_CODE;
438+
END_CRIT_SECTION();
439439

440440
/* write the buffer and release the lock */
441441
_bt_wrtbuf(rel,buf);

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

Lines changed: 5 additions & 5 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.91 2000/12/28 13:00:08 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.92 2001/01/12 21:53:56 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -678,7 +678,7 @@ RecordTransactionCommit()
678678
rdata.len=SizeOfXactCommit;
679679
rdata.next=NULL;
680680

681-
START_CRIT_CODE;
681+
START_CRIT_SECTION();
682682
/*
683683
* SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
684684
*/
@@ -697,7 +697,7 @@ RecordTransactionCommit()
697697
TransactionIdCommit(xid);
698698

699699
MyProc->logRec.xrecoff=0;
700-
END_CRIT_CODE;
700+
END_CRIT_SECTION();
701701
}
702702

703703
if (leak)
@@ -800,12 +800,12 @@ RecordTransactionAbort(void)
800800
rdata.len=SizeOfXactAbort;
801801
rdata.next=NULL;
802802

803-
START_CRIT_CODE;
803+
START_CRIT_SECTION();
804804
recptr=XLogInsert(RM_XACT_ID,XLOG_XACT_ABORT,&rdata);
805805

806806
TransactionIdAbort(xid);
807807
MyProc->logRec.xrecoff=0;
808-
END_CRIT_CODE;
808+
END_CRIT_SECTION();
809809
}
810810

811811
/*

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.48 2001/01/09 06:24:32 vadim Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.49 2001/01/12 21:53:56 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -42,7 +42,7 @@
4242
intXLOGbuffers=8;
4343
intXLOGfiles=0;/* how many files to pre-allocate */
4444
XLogRecPtrMyLastRecPtr= {0,0};
45-
uint32CritSectionCount=0;
45+
volatileuint32CritSectionCount=0;
4646
boolInRecovery= false;
4747
StartUpIDThisStartUpID=0;
4848
XLogRecPtrRedoRecPtr;
@@ -382,7 +382,7 @@ begin:;
382382
if (len==0||len>MAXLOGRECSZ)
383383
elog(STOP,"XLogInsert: invalid record len %u",len);
384384

385-
START_CRIT_CODE;
385+
START_CRIT_SECTION();
386386

387387
/* obtain xlog insert lock */
388388
if (TAS(&(XLogCtl->insert_lck)))/* busy */
@@ -447,7 +447,7 @@ begin:;
447447
if (repeat)
448448
{
449449
S_UNLOCK(&(XLogCtl->insert_lck));
450-
END_CRIT_CODE;
450+
END_CRIT_SECTION();
451451
gotobegin;
452452
}
453453

@@ -618,7 +618,7 @@ begin:;
618618
S_UNLOCK(&(XLogCtl->info_lck));
619619
}
620620

621-
END_CRIT_CODE;
621+
END_CRIT_SECTION();
622622
return (RecPtr);
623623
}
624624

@@ -647,7 +647,7 @@ XLogFlush(XLogRecPtr record)
647647
if (XLByteLE(record,LgwrResult.Flush))
648648
return;
649649

650-
START_CRIT_CODE;
650+
START_CRIT_SECTION();
651651

652652
WriteRqst=LgwrRqst.Write;
653653
for (;;)
@@ -659,7 +659,7 @@ XLogFlush(XLogRecPtr record)
659659
if (XLByteLE(record,LgwrResult.Flush))
660660
{
661661
S_UNLOCK(&(XLogCtl->info_lck));
662-
END_CRIT_CODE;
662+
END_CRIT_SECTION();
663663
return;
664664
}
665665
if (XLByteLT(XLogCtl->LgwrRqst.Flush,record))
@@ -705,7 +705,7 @@ XLogFlush(XLogRecPtr record)
705705
if (XLByteLE(record,LgwrResult.Flush))
706706
{
707707
S_UNLOCK(&(XLogCtl->lgwr_lck));
708-
END_CRIT_CODE;
708+
END_CRIT_SECTION();
709709
return;
710710
}
711711
if (XLByteLT(LgwrResult.Write,WriteRqst))
@@ -715,7 +715,7 @@ XLogFlush(XLogRecPtr record)
715715
S_UNLOCK(&(XLogCtl->lgwr_lck));
716716
if (XLByteLT(LgwrResult.Flush,record))
717717
elog(STOP,"XLogFlush: request is not satisfied");
718-
END_CRIT_CODE;
718+
END_CRIT_SECTION();
719719
return;
720720
}
721721
break;
@@ -756,7 +756,7 @@ XLogFlush(XLogRecPtr record)
756756

757757
S_UNLOCK(&(XLogCtl->lgwr_lck));
758758

759-
END_CRIT_CODE;
759+
END_CRIT_SECTION();
760760
return;
761761

762762
}
@@ -2081,7 +2081,7 @@ CreateCheckPoint(bool shutdown)
20812081
if (MyLastRecPtr.xrecoff!=0)
20822082
elog(ERROR,"CreateCheckPoint: cannot be called inside transaction block");
20832083

2084-
START_CRIT_CODE;
2084+
START_CRIT_SECTION();
20852085

20862086
/* Grab lock, using larger than normal sleep between tries (1 sec) */
20872087
while (TAS(&(XLogCtl->chkp_lck)))
@@ -2230,7 +2230,7 @@ CreateCheckPoint(bool shutdown)
22302230
S_UNLOCK(&(XLogCtl->chkp_lck));
22312231

22322232
MyLastRecPtr.xrecoff=0;/* to avoid commit record */
2233-
END_CRIT_CODE;
2233+
END_CRIT_SECTION();
22342234

22352235
return;
22362236
}

‎src/backend/commands/sequence.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.47 2000/12/28 13:00:17 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.48 2001/01/12 21:53:56 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -301,7 +301,7 @@ nextval(PG_FUNCTION_ARGS)
301301
elm->last=result;/* last returned number */
302302
elm->cached=last;/* last fetched number */
303303

304-
START_CRIT_CODE;
304+
START_CRIT_SECTION();
305305
if (logit)
306306
{
307307
xl_seq_recxlrec;
@@ -338,7 +338,7 @@ nextval(PG_FUNCTION_ARGS)
338338
seq->is_called='t';
339339
Assert(log >=0);
340340
seq->log_cnt=log;/* how much is logged */
341-
END_CRIT_CODE;
341+
END_CRIT_SECTION();
342342

343343
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
344344

@@ -398,7 +398,7 @@ do_setval(char *seqname, int32 next, bool iscalled)
398398
elm->last=next;/* last returned number */
399399
elm->cached=next;/* last cached number (forget cached values) */
400400

401-
START_CRIT_CODE;
401+
START_CRIT_SECTION();
402402
{
403403
xl_seq_recxlrec;
404404
XLogRecPtrrecptr;
@@ -429,7 +429,7 @@ do_setval(char *seqname, int32 next, bool iscalled)
429429
seq->last_value=next;/* last fetched number */
430430
seq->is_called=iscalled ?'t' :'f';
431431
seq->log_cnt= (iscalled) ?0 :1;
432-
END_CRIT_CODE;
432+
END_CRIT_SECTION();
433433

434434
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
435435

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp