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

Commit36839c1

Browse files
committed
Restructure backend SIGINT/SIGTERM handling so that 'die' interrupts
are treated more like 'cancel' interrupts: the signal handler sets aflag that is examined at well-defined spots, rather than trying to copewith an interrupt that might happen anywhere. See pghackers discussionof 1/12/01.
1 parent027f144 commit36839c1

File tree

24 files changed

+615
-480
lines changed

24 files changed

+615
-480
lines changed

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

Lines changed: 2 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/nbtree/nbtinsert.c,v 1.73 2001/01/12 21:53:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.74 2001/01/14 05:08:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -17,6 +17,7 @@
1717

1818
#include"access/heapam.h"
1919
#include"access/nbtree.h"
20+
#include"miscadmin.h"
2021

2122

2223
typedefstruct

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

Lines changed: 18 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.92 2001/01/12 21:53:56 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.93 2001/01/14 05:08:14 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -1015,6 +1015,9 @@ CommitTransaction(void)
10151015
if (s->state!=TRANS_INPROGRESS)
10161016
elog(NOTICE,"CommitTransaction and not in in-progress state ");
10171017

1018+
/* Prevent cancel/die interrupt while cleaning up */
1019+
START_CRIT_SECTION();
1020+
10181021
/* ----------------
10191022
*Tell the trigger manager that this transaction is about to be
10201023
*committed. He'll invoke all trigger deferred until XACT before
@@ -1083,6 +1086,8 @@ CommitTransaction(void)
10831086
* ----------------
10841087
*/
10851088
s->state=TRANS_DEFAULT;
1089+
1090+
END_CRIT_SECTION();
10861091
}
10871092

10881093
/* --------------------------------
@@ -1095,6 +1100,9 @@ AbortTransaction(void)
10951100
{
10961101
TransactionStates=CurrentTransactionState;
10971102

1103+
/* Prevent cancel/die interrupt while cleaning up */
1104+
START_CRIT_SECTION();
1105+
10981106
/*
10991107
* Let others to know about no transaction in progress - vadim
11001108
* 11/26/96
@@ -1113,13 +1121,21 @@ AbortTransaction(void)
11131121
*/
11141122
ProcReleaseSpins(NULL);
11151123
UnlockBuffers();
1124+
/*
1125+
* Also clean up any open wait for lock, since the lock manager
1126+
* will choke if we try to wait for another lock before doing this.
1127+
*/
1128+
LockWaitCancel();
11161129

11171130
/* ----------------
11181131
*check the current transaction state
11191132
* ----------------
11201133
*/
11211134
if (s->state==TRANS_DISABLED)
1135+
{
1136+
END_CRIT_SECTION();
11221137
return;
1138+
}
11231139

11241140
if (s->state!=TRANS_INPROGRESS)
11251141
elog(NOTICE,"AbortTransaction and not in in-progress state");
@@ -1169,6 +1185,7 @@ AbortTransaction(void)
11691185
*State remains TRANS_ABORT until CleanupTransaction().
11701186
* ----------------
11711187
*/
1188+
END_CRIT_SECTION();
11721189
}
11731190

11741191
/* --------------------------------

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

Lines changed: 1 addition & 2 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.49 2001/01/12 21:53:56 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.50 2001/01/14 05:08:15 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -42,7 +42,6 @@
4242
intXLOGbuffers=8;
4343
intXLOGfiles=0;/* how many files to pre-allocate */
4444
XLogRecPtrMyLastRecPtr= {0,0};
45-
volatileuint32CritSectionCount=0;
4645
boolInRecovery= false;
4746
StartUpIDThisStartUpID=0;
4847
XLogRecPtrRedoRecPtr;

‎src/backend/bootstrap/bootstrap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.102 2000/12/28 13:00:12 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.103 2001/01/14 05:08:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -329,9 +329,10 @@ BootstrapMain(int argc, char *argv[])
329329

330330
if (!IsUnderPostmaster)
331331
{
332-
pqsignal(SIGINT, (pqsigfunc)die);
333-
pqsignal(SIGHUP, (pqsigfunc)die);
334-
pqsignal(SIGTERM, (pqsigfunc)die);
332+
pqsignal(SIGHUP,die);
333+
pqsignal(SIGINT,die);
334+
pqsignal(SIGTERM,die);
335+
pqsignal(SIGQUIT,die);
335336
}
336337

337338
/*
@@ -383,8 +384,6 @@ BootstrapMain(int argc, char *argv[])
383384
*abort processing resumes here
384385
* ----------------
385386
*/
386-
pqsignal(SIGHUP,handle_warn);
387-
388387
if (sigsetjmp(Warn_restart,1)!=0)
389388
{
390389
Warnings++;

‎src/backend/commands/analyze.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.10 2000/12/02 19:38:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.11 2001/01/14 05:08:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -72,8 +72,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
7272
* Check for user-requested abort.Note we want this to be inside a
7373
* transaction, so xact.c doesn't issue useless NOTICE.
7474
*/
75-
if (QueryCancel)
76-
CancelQuery();
75+
CHECK_FOR_INTERRUPTS();
7776

7877
/*
7978
* Race condition -- if the pg_class tuple has gone away since the

‎src/backend/commands/copy.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.128 2001/01/06 03:33:17 ishii Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.129 2001/01/14 05:08:15 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -449,8 +449,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp,
449449
{
450450
boolneed_delim= false;
451451

452-
if (QueryCancel)
453-
CancelQuery();
452+
CHECK_FOR_INTERRUPTS();
454453

455454
if (binary)
456455
{
@@ -702,11 +701,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
702701

703702
while (!done)
704703
{
705-
if (QueryCancel)
706-
{
707-
lineno=0;
708-
CancelQuery();
709-
}
704+
CHECK_FOR_INTERRUPTS();
710705

711706
lineno++;
712707

‎src/backend/commands/vacuum.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.182 2001/01/12 21:53:56 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.183 2001/01/14 05:08:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -378,8 +378,7 @@ vacuum_rel(Oid relid)
378378
* Check for user-requested abort.Note we want this to be inside a
379379
* transaction, so xact.c doesn't issue useless NOTICE.
380380
*/
381-
if (QueryCancel)
382-
CancelQuery();
381+
CHECK_FOR_INTERRUPTS();
383382

384383
/*
385384
* Race condition -- if the pg_class tuple has gone away since the

‎src/backend/executor/execProcnode.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.22 2000/10/26 21:35:15 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.23 2001/01/14 05:08:15 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -248,14 +248,12 @@ ExecProcNode(Plan *node, Plan *parent)
248248
{
249249
TupleTableSlot*result;
250250

251+
CHECK_FOR_INTERRUPTS();
252+
251253
/* ----------------
252254
*deal with NULL nodes..
253255
* ----------------
254256
*/
255-
256-
if (QueryCancel)
257-
CancelQuery();
258-
259257
if (node==NULL)
260258
returnNULL;
261259

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 59 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/storage/buffer/bufmgr.c,v 1.103 2001/01/12 21:53:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.104 2001/01/14 05:08:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -92,6 +92,7 @@ static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
9292
boolbufferLockHeld);
9393
staticBufferDesc*BufferAlloc(Relationreln,BlockNumberblockNum,
9494
bool*foundPtr,boolbufferLockHeld);
95+
staticintReleaseBufferWithBufferLock(Bufferbuffer);
9596
staticintBufferReplace(BufferDesc*bufHdr);
9697
voidPrintBufferDescs(void);
9798

@@ -687,10 +688,14 @@ ReleaseAndReadBuffer(Buffer buffer,
687688
{
688689
bufHdr=&BufferDescriptors[buffer-1];
689690
Assert(PrivateRefCount[buffer-1]>0);
690-
PrivateRefCount[buffer-1]--;
691-
if (PrivateRefCount[buffer-1]==0)
691+
if (PrivateRefCount[buffer-1]>1)
692+
{
693+
PrivateRefCount[buffer-1]--;
694+
}
695+
else
692696
{
693697
SpinAcquire(BufMgrLock);
698+
PrivateRefCount[buffer-1]=0;
694699
Assert(bufHdr->refcount>0);
695700
bufHdr->refcount--;
696701
if (bufHdr->refcount==0)
@@ -1185,10 +1190,7 @@ DropRelationBuffers(Relation rel)
11851190
/* Assert checks that buffer will actually get freed! */
11861191
Assert(PrivateRefCount[i-1]==1&&
11871192
bufHdr->refcount==1);
1188-
/* ReleaseBuffer expects we do not hold the lock at entry */
1189-
SpinRelease(BufMgrLock);
1190-
ReleaseBuffer(i);
1191-
SpinAcquire(BufMgrLock);
1193+
ReleaseBufferWithBufferLock(i);
11921194
}
11931195
/*
11941196
* And mark the buffer as no longer occupied by this rel.
@@ -1270,10 +1272,7 @@ DropRelFileNodeBuffers(RelFileNode rnode)
12701272
/* Assert checks that buffer will actually get freed! */
12711273
Assert(PrivateRefCount[i-1]==1&&
12721274
bufHdr->refcount==1);
1273-
/* ReleaseBuffer expects we do not hold the lock at entry */
1274-
SpinRelease(BufMgrLock);
1275-
ReleaseBuffer(i);
1276-
SpinAcquire(BufMgrLock);
1275+
ReleaseBufferWithBufferLock(i);
12771276
}
12781277
/*
12791278
* And mark the buffer as no longer occupied by this rel.
@@ -1624,10 +1623,14 @@ ReleaseBuffer(Buffer buffer)
16241623
bufHdr=&BufferDescriptors[buffer-1];
16251624

16261625
Assert(PrivateRefCount[buffer-1]>0);
1627-
PrivateRefCount[buffer-1]--;
1628-
if (PrivateRefCount[buffer-1]==0)
1626+
if (PrivateRefCount[buffer-1]>1)
1627+
{
1628+
PrivateRefCount[buffer-1]--;
1629+
}
1630+
else
16291631
{
16301632
SpinAcquire(BufMgrLock);
1633+
PrivateRefCount[buffer-1]=0;
16311634
Assert(bufHdr->refcount>0);
16321635
bufHdr->refcount--;
16331636
if (bufHdr->refcount==0)
@@ -1641,6 +1644,48 @@ ReleaseBuffer(Buffer buffer)
16411644
returnSTATUS_OK;
16421645
}
16431646

1647+
/*
1648+
* ReleaseBufferWithBufferLock
1649+
*Same as ReleaseBuffer except we hold the lock
1650+
*/
1651+
staticint
1652+
ReleaseBufferWithBufferLock(Bufferbuffer)
1653+
{
1654+
BufferDesc*bufHdr;
1655+
1656+
if (BufferIsLocal(buffer))
1657+
{
1658+
Assert(LocalRefCount[-buffer-1]>0);
1659+
LocalRefCount[-buffer-1]--;
1660+
returnSTATUS_OK;
1661+
}
1662+
1663+
if (BAD_BUFFER_ID(buffer))
1664+
returnSTATUS_ERROR;
1665+
1666+
bufHdr=&BufferDescriptors[buffer-1];
1667+
1668+
Assert(PrivateRefCount[buffer-1]>0);
1669+
if (PrivateRefCount[buffer-1]>1)
1670+
{
1671+
PrivateRefCount[buffer-1]--;
1672+
}
1673+
else
1674+
{
1675+
PrivateRefCount[buffer-1]=0;
1676+
Assert(bufHdr->refcount>0);
1677+
bufHdr->refcount--;
1678+
if (bufHdr->refcount==0)
1679+
{
1680+
AddBufferToFreelist(bufHdr);
1681+
bufHdr->flags |=BM_FREE;
1682+
}
1683+
}
1684+
1685+
returnSTATUS_OK;
1686+
}
1687+
1688+
16441689
#ifdefNOT_USED
16451690
void
16461691
IncrBufferRefCount_Debug(char*file,intline,Bufferbuffer)
@@ -2217,9 +2262,9 @@ MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer))
22172262
SpinRelease(BufMgrLock);
22182263

22192264
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
2220-
PrivateRefCount[buffer-1]--;
22212265

22222266
SpinAcquire(BufMgrLock);
2267+
PrivateRefCount[buffer-1]=0;
22232268
Assert(bufHdr->refcount>0);
22242269
bufHdr->flags |= (BM_DIRTY |BM_JUST_DIRTIED);
22252270
bufHdr->CleanupFunc=CleanupFunc;

‎src/backend/storage/buffer/s_lock.c

Lines changed: 8 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/storage/buffer/Attic/s_lock.c,v 1.28 2000/12/29 21:31:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/s_lock.c,v 1.29 2001/01/14 05:08:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -17,6 +17,7 @@
1717
#include<sys/time.h>
1818
#include<unistd.h>
1919

20+
#include"miscadmin.h"
2021
#include"storage/s_lock.h"
2122

2223

@@ -101,10 +102,16 @@ s_lock(volatile slock_t *lock, const char *file, const int line)
101102
/*
102103
* If you are thinking of changing this code, be careful. This same
103104
* loop logic is used in other places that call TAS() directly.
105+
*
106+
* While waiting for a lock, we check for cancel/die interrupts (which
107+
* is a no-op if we are inside a critical section). The interrupt check
108+
* can be omitted in places that know they are inside a critical section.
109+
* Note that an interrupt must NOT be accepted after acquiring the lock.
104110
*/
105111
while (TAS(lock))
106112
{
107113
s_lock_sleep(spins++,0,lock,file,line);
114+
CHECK_FOR_INTERRUPTS();
108115
}
109116
}
110117

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp