Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cb7ce7d

Browse files
committed
Fix recent breakage of query-cancel logic, see my pghackers message
of 6 Jan 2001 21:55.
1 parent 6781aa4 commit cb7ce7d

File tree

4 files changed

+65
-36
lines changed

4 files changed

+65
-36
lines changed

src/backend/tcop/postgres.c

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.198 2000/12/20 21:51:52 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.199 2001/01/07 04:17:29 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -94,7 +94,7 @@ DLLIMPORT sigjmp_buf Warn_restart;
9494

9595
bool Warn_restart_ready = false;
9696
bool InError = false;
97-
bool ProcDiePending = false;
97+
volatile bool ProcDiePending = false;
9898

9999
static bool EchoQuery = false; /* default don't echo */
100100
char pg_pathname[MAXPGPATH];
@@ -920,7 +920,10 @@ finish_xact_command(void)
920920
void
921921
handle_warn(SIGNAL_ARGS)
922922
{
923-
/* Don't joggle the elbow of a critical section */
923+
/* Don't joggle the elbow of proc_exit */
924+
if (proc_exit_inprogress)
925+
return;
926+
/* Don't joggle the elbow of a critical section, either */
924927
if (CritSectionCount > 0)
925928
{
926929
QueryCancel = true;
@@ -956,28 +959,38 @@ quickdie(SIGNAL_ARGS)
956959
void
957960
die(SIGNAL_ARGS)
958961
{
962+
int save_errno = errno;
963+
959964
PG_SETMASK(&BlockSig);
960965

961-
/* Don't joggle the elbow of a critical section */
966+
/* Don't joggle the elbow of proc_exit */
967+
if (proc_exit_inprogress)
968+
{
969+
errno = save_errno;
970+
return;
971+
}
972+
/* Don't joggle the elbow of a critical section, either */
962973
if (CritSectionCount > 0)
963974
{
964-
QueryCancel = true;
965975
ProcDiePending = true;
976+
errno = save_errno;
966977
return;
967978
}
968-
/* Don't joggle the elbow of proc_exit, either */
969-
if (proc_exit_inprogress)
970-
return;
971-
elog(FATAL, "The system is shutting down");
979+
/* Otherwise force immediate proc_exit */
980+
ForceProcDie();
972981
}
973982

974-
/* signal handler for floating point exception */
975-
static void
976-
FloatExceptionHandler(SIGNAL_ARGS)
983+
/*
984+
* This is split out of die() so that it can be invoked later from
985+
* END_CRIT_CODE.
986+
*/
987+
void
988+
ForceProcDie(void)
977989
{
978-
elog(ERROR, "floating point exception!"
979-
" The last floating point operation either exceeded legal ranges"
980-
" or was a divide by zero");
990+
/* Reset flag to avoid another elog() during shutdown */
991+
ProcDiePending = false;
992+
/* Send error message and do proc_exit() */
993+
elog(FATAL, "The system is shutting down");
981994
}
982995

983996
/* signal handler for query cancel signal from postmaster */
@@ -986,22 +999,41 @@ QueryCancelHandler(SIGNAL_ARGS)
986999
{
9871000
int save_errno = errno;
9881001

1002+
/* Don't joggle the elbow of proc_exit, nor an already-in-progress abort */
1003+
if (proc_exit_inprogress || InError)
1004+
{
1005+
errno = save_errno;
1006+
return;
1007+
}
1008+
1009+
/* Set flag to cause CancelQuery to be called when it's safe */
9891010
QueryCancel = true;
1011+
1012+
/* If we happen to be waiting for a lock, get out of that */
9901013
LockWaitCancel();
1014+
1015+
/* Otherwise, bide our time... */
9911016
errno = save_errno;
9921017
}
9931018

9941019
void
9951020
CancelQuery(void)
9961021
{
997-
998-
/*
999-
* QueryCancel flag will be reset in main loop, which we reach by
1000-
* longjmp from elog().
1001-
*/
1022+
/* Reset flag to avoid another elog() during error recovery */
1023+
QueryCancel = false;
1024+
/* Create an artificial error condition to get out of query */
10021025
elog(ERROR, "Query was cancelled.");
10031026
}
10041027

1028+
/* signal handler for floating point exception */
1029+
static void
1030+
FloatExceptionHandler(SIGNAL_ARGS)
1031+
{
1032+
elog(ERROR, "floating point exception!"
1033+
" The last floating point operation either exceeded legal ranges"
1034+
" or was a divide by zero");
1035+
}
1036+
10051037
static void
10061038
SigHupHandler(SIGNAL_ARGS)
10071039
{
@@ -1651,7 +1683,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16511683
if (!IsUnderPostmaster)
16521684
{
16531685
puts("\nPOSTGRES backend interactive interface ");
1654-
puts("$Revision: 1.198 $ $Date: 2000/12/20 21:51:52 $\n");
1686+
puts("$Revision: 1.199 $ $Date: 2001/01/07 04:17:29 $\n");
16551687
}
16561688

16571689
/*

src/backend/utils/init/globals.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.48 2000/12/28 13:00:24 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.49 2001/01/07 04:17:29 tgl Exp $
1212
*
1313
* NOTES
1414
* Globals used all over the place should be declared here and not
@@ -34,7 +34,7 @@ ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST;
3434

3535
bool Noversion = false;
3636
bool Quiet = false;
37-
bool QueryCancel = false;
37+
volatile bool QueryCancel = false;
3838

3939
int MyProcPid;
4040
struct Port *MyProcPort;

src/include/miscadmin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.75 2000/11/29 20:59:54 tgl Exp $
15+
* $Id: miscadmin.h,v 1.76 2001/01/07 04:17:28 tgl Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file will be moved to
@@ -42,7 +42,7 @@ extern int PostmasterMain(int argc, char *argv[]);
4242
*/
4343
extern bool Noversion;
4444
extern bool Quiet;
45-
extern bool QueryCancel;
45+
extern volatile bool QueryCancel;
4646
extern char *DataDir;
4747

4848
extern int MyProcPid;

src/include/utils/elog.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: elog.h,v 1.21 2000/12/18 00:44:50 tgl Exp $
10+
* $Id: elog.h,v 1.22 2001/01/07 04:17:28 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -30,11 +30,13 @@ extern int Use_syslog;
3030
/*
3131
* If CritSectionCount > 0, signal handlers mustn't do
3232
* elog(ERROR|FATAL), instead remember what action is
33-
* required with QueryCancel & ProcDiePending.
33+
* required with QueryCancel or ProcDiePending.
34+
* ProcDiePending will be honored at critical section exit,
35+
* but QueryCancel is only checked at specified points.
3436
*/
3537
extern uint32 CritSectionCount; /* duplicates access/xlog.h */
36-
extern bool QueryCancel; /* duplicates miscadmin.h */
37-
extern bool ProcDiePending;
38+
extern volatile bool ProcDiePending;
39+
extern void ForceProcDie(void); /* in postgres.c */
3840

3941
#define START_CRIT_CODE (CritSectionCount++)
4042

@@ -43,13 +45,8 @@ extern bool ProcDiePending;
4345
if (CritSectionCount == 0) \
4446
elog(STOP, "Not in critical section"); \
4547
CritSectionCount--; \
46-
if (CritSectionCount == 0 && QueryCancel) \
47-
{ \
48-
if (ProcDiePending) \
49-
elog(FATAL, "The system is shutting down"); \
50-
else \
51-
elog(ERROR, "Query was cancelled."); \
52-
} \
48+
if (CritSectionCount == 0 && ProcDiePending) \
49+
ForceProcDie(); \
5350
} while(0)
5451

5552
extern bool Log_timestamp;

0 commit comments

Comments
 (0)