Commit 07140ee0 authored by Bruce Momjian's avatar Bruce Momjian

Allow cancel from client of backend query. Change some int variables

to bool's.
parent ef567413
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.40 1998/04/26 04:06:04 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.41 1998/05/19 18:05:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -312,8 +312,8 @@ BootstrapMain(int argc, char *argv[]) ...@@ -312,8 +312,8 @@ BootstrapMain(int argc, char *argv[])
*/ */
/* Set defaults, to be overriden by explicit options below */ /* Set defaults, to be overriden by explicit options below */
Quiet = 0; Quiet = false;
Noversion = 0; Noversion = false;
dbName = NULL; dbName = NULL;
DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */ DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
...@@ -325,19 +325,19 @@ BootstrapMain(int argc, char *argv[]) ...@@ -325,19 +325,19 @@ BootstrapMain(int argc, char *argv[])
DataDir = optarg; DataDir = optarg;
break; break;
case 'd': case 'd':
DebugMode = 1; /* print out debugging info while parsing */ DebugMode = true; /* print out debugging info while parsing */
break; break;
case 'C': case 'C':
Noversion = 1; Noversion = true;
break; break;
case 'F': case 'F':
fsyncOff = 1; fsyncOff = true;
break; break;
case 'O': case 'O':
override = true; override = true;
break; break;
case 'Q': case 'Q':
Quiet = 1; Quiet = true;
break; break;
case 'P': /* specify port */ case 'P': /* specify port */
portFd = atoi(optarg); portFd = atoi(optarg);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.9 1998/02/26 04:31:11 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.10 1998/05/19 18:05:45 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -74,6 +74,8 @@ ...@@ -74,6 +74,8 @@
*/ */
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h"
#include "tcop/tcopprot.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "executor/nodeResult.h" #include "executor/nodeResult.h"
#include "executor/nodeAppend.h" #include "executor/nodeAppend.h"
...@@ -233,6 +235,10 @@ ExecProcNode(Plan *node, Plan *parent) ...@@ -233,6 +235,10 @@ ExecProcNode(Plan *node, Plan *parent)
* deal with NULL nodes.. * deal with NULL nodes..
* ---------------- * ----------------
*/ */
if (QueryCancel)
CancelQuery();
if (node == NULL) if (node == NULL)
return NULL; return NULL;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.40 1998/03/02 05:41:53 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.41 1998/05/19 18:05:46 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -409,18 +409,15 @@ pq_sendoob(char *msg, int len) ...@@ -409,18 +409,15 @@ pq_sendoob(char *msg, int len)
{ {
int fd = fileno(Pfout); int fd = fileno(Pfout);
return (send(fd, msg, len, MSG_OOB)); return send(fd, msg, len, MSG_OOB);
} }
int int
pq_recvoob(char *msgPtr, int *lenPtr) pq_recvoob(char *msgPtr, int len)
{ {
int fd = fileno(Pfout); int fd = fileno(Pfout);
int len = 0;
len = recv(fd, msgPtr + len, *lenPtr, MSG_OOB); return recv(fd, msgPtr, len, MSG_OOB);
*lenPtr = len;
return (len);
} }
/* -------------------------------- /* --------------------------------
...@@ -523,7 +520,7 @@ pq_async_notify() ...@@ -523,7 +520,7 @@ pq_async_notify()
/* int len = sizeof(msg); */ /* int len = sizeof(msg); */
int len = 20; int len = 20;
if (pq_recvoob(msg, &len) >= 0) if (pq_recvoob(msg, len) >= 0)
{ {
/* debugging */ /* debugging */
printf("received notification: %s\n", msg); printf("received notification: %s\n", msg);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.19 1998/05/14 17:18:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.20 1998/05/19 18:05:47 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -288,7 +288,8 @@ BeginCommand(char *pname, ...@@ -288,7 +288,8 @@ BeginCommand(char *pname,
* oops.. */ * oops.. */
pq_putint((int) attrs[i]->atttypid, sizeof(attrs[i]->atttypid)); pq_putint((int) attrs[i]->atttypid, sizeof(attrs[i]->atttypid));
pq_putint(attrs[i]->attlen, sizeof(attrs[i]->attlen)); pq_putint(attrs[i]->attlen, sizeof(attrs[i]->attlen));
pq_putint(attrs[i]->atttypmod, sizeof(attrs[i]->atttypmod)); if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
pq_putint(attrs[i]->atttypmod, sizeof(attrs[i]->atttypmod));
} }
} }
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.68 1998/05/06 23:50:19 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.69 1998/05/19 18:05:48 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -119,7 +119,7 @@ jmp_buf Warn_restart; ...@@ -119,7 +119,7 @@ jmp_buf Warn_restart;
sigjmp_buf Warn_restart; sigjmp_buf Warn_restart;
#endif /* defined(nextstep) */ #endif /* defined(nextstep) */
int InError; bool InError;
extern int NBuffers; extern int NBuffers;
...@@ -618,6 +618,9 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -618,6 +618,9 @@ pg_exec_query_dest(char *query_string, /* string to execute */
/* plan the queries */ /* plan the queries */
plan_list = pg_parse_and_plan(query_string, typev, nargs, &querytree_list, dest); plan_list = pg_parse_and_plan(query_string, typev, nargs, &querytree_list, dest);
if (QueryCancel)
CancelQuery();
/* pg_parse_and_plan could have failed */ /* pg_parse_and_plan could have failed */
if (querytree_list == NULL) if (querytree_list == NULL)
return; return;
...@@ -776,6 +779,26 @@ FloatExceptionHandler(SIGNAL_ARGS) ...@@ -776,6 +779,26 @@ FloatExceptionHandler(SIGNAL_ARGS)
} }
/* signal handler for query cancel */
static void
QueryCancelHandler(SIGNAL_ARGS)
{
QueryCancel = true;
}
void
CancelQuery(void)
{
char dummy;
/* throw it away */
while (pq_recvoob(&dummy, 1) > 0)
;
/* QueryCancel reset in longjump after elog() call */
elog(ERROR, "Query was cancelled.");
}
static void static void
usage(char *progname) usage(char *progname)
{ {
...@@ -819,11 +842,11 @@ usage(char *progname) ...@@ -819,11 +842,11 @@ usage(char *progname)
int int
PostgresMain(int argc, char *argv[]) PostgresMain(int argc, char *argv[])
{ {
int flagC; bool flagC = false,
int flagQ; flagQ = false,
int flagE; flagE = false,
int flagEu; flagEu = false;
int flag; int flag;
char *DBName = NULL; char *DBName = NULL;
int errs = 0; int errs = 0;
...@@ -865,7 +888,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -865,7 +888,7 @@ PostgresMain(int argc, char *argv[])
/* /*
* Set default values. * Set default values.
*/ */
flagC = flagQ = flagE = flagEu = ShowStats = 0; ShowStats = 0;
ShowParserStats = ShowPlannerStats = ShowExecutorStats = 0; ShowParserStats = ShowPlannerStats = ShowExecutorStats = 0;
#ifdef LOCK_MGR_DEBUG #ifdef LOCK_MGR_DEBUG
lockDebug = 0; lockDebug = 0;
...@@ -928,14 +951,14 @@ PostgresMain(int argc, char *argv[]) ...@@ -928,14 +951,14 @@ PostgresMain(int argc, char *argv[])
* don't print version string (don't know why this is 'C' --mao) * don't print version string (don't know why this is 'C' --mao)
* ---------------- * ----------------
*/ */
flagC = 1; flagC = true;
break; break;
case 'D': /* PGDATA directory */ case 'D': /* PGDATA directory */
DataDir = optarg; DataDir = optarg;
case 'd': /* debug level */ case 'd': /* debug level */
flagQ = 0; flagQ = false;
DebugLvl = (short) atoi(optarg); DebugLvl = (short) atoi(optarg);
if (DebugLvl > 1) if (DebugLvl > 1)
DebugPrintQuery = true; DebugPrintQuery = true;
...@@ -952,7 +975,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -952,7 +975,7 @@ PostgresMain(int argc, char *argv[])
* E - echo the query the user entered * E - echo the query the user entered
* ---------------- * ----------------
*/ */
flagE = 1; flagE = true;
break; break;
case 'e': case 'e':
...@@ -960,7 +983,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -960,7 +983,7 @@ PostgresMain(int argc, char *argv[])
* Use european date formats. * Use european date formats.
* -------------------------- * --------------------------
*/ */
flagEu = 1; flagEu = true;
break; break;
case 'F': case 'F':
...@@ -1064,7 +1087,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1064,7 +1087,7 @@ PostgresMain(int argc, char *argv[])
* Q - set Quiet mode (reduce debugging output) * Q - set Quiet mode (reduce debugging output)
* ---------------- * ----------------
*/ */
flagQ = 1; flagQ = true;
break; break;
case 'S': case 'S':
...@@ -1252,6 +1275,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1252,6 +1275,7 @@ PostgresMain(int argc, char *argv[])
} }
pq_init(Portfd); pq_init(Portfd);
whereToSendOutput = Remote; whereToSendOutput = Remote;
pq_regoob(QueryCancelHandler); /* we do it here so the backend it connected */
} }
else else
whereToSendOutput = Debug; whereToSendOutput = Debug;
...@@ -1282,7 +1306,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1282,7 +1306,7 @@ PostgresMain(int argc, char *argv[])
if (sigsetjmp(Warn_restart, 1) != 0) if (sigsetjmp(Warn_restart, 1) != 0)
{ {
InError = 1; InError = true;
time(&tim); time(&tim);
...@@ -1292,8 +1316,10 @@ PostgresMain(int argc, char *argv[]) ...@@ -1292,8 +1316,10 @@ PostgresMain(int argc, char *argv[])
MemSet(parser_input, 0, MAX_PARSE_BUFFER); MemSet(parser_input, 0, MAX_PARSE_BUFFER);
AbortCurrentTransaction(); AbortCurrentTransaction();
} }
InError = 0;
InError = false;
/* ---------------- /* ----------------
* POSTGRES main processing loop begins here * POSTGRES main processing loop begins here
...@@ -1302,7 +1328,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1302,7 +1328,7 @@ PostgresMain(int argc, char *argv[])
if (IsUnderPostmaster == false) if (IsUnderPostmaster == false)
{ {
puts("\nPOSTGRES backend interactive interface"); puts("\nPOSTGRES backend interactive interface");
puts("$Revision: 1.68 $ $Date: 1998/05/06 23:50:19 $"); puts("$Revision: 1.69 $ $Date: 1998/05/19 18:05:48 $");
} }
/* ---------------- /* ----------------
...@@ -1329,6 +1355,9 @@ PostgresMain(int argc, char *argv[]) ...@@ -1329,6 +1355,9 @@ PostgresMain(int argc, char *argv[])
MemSet(parser_input, 0, MAX_PARSE_BUFFER); MemSet(parser_input, 0, MAX_PARSE_BUFFER);
firstchar = ReadCommand(parser_input); firstchar = ReadCommand(parser_input);
QueryCancel = false;
/* process the command */ /* process the command */
switch (firstchar) switch (firstchar)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.27 1998/02/26 04:37:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.28 1998/05/19 18:05:50 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -175,7 +175,7 @@ elog(int lev, const char *fmt,...) ...@@ -175,7 +175,7 @@ elog(int lev, const char *fmt,...)
if (lev == ERROR) if (lev == ERROR)
{ {
extern int InError; extern bool InError;
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */ ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
if (!InError) if (!InError)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.21 1998/02/26 04:37:56 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.22 1998/05/19 18:05:51 momjian Exp $
* *
* NOTES * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
...@@ -37,8 +37,10 @@ ...@@ -37,8 +37,10 @@
ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST; ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST;
int Portfd = -1; int Portfd = -1;
int Noversion = 0;
int Quiet = 1; bool Noversion = false;
bool Quiet = false;
bool QueryCancel = false;
int MyProcPid; int MyProcPid;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: libpq.h,v 1.13 1998/03/02 05:42:06 scrappy Exp $ * $Id: libpq.h,v 1.14 1998/05/19 18:05:55 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -269,7 +269,7 @@ extern void pq_putstr(char *s); ...@@ -269,7 +269,7 @@ extern void pq_putstr(char *s);
extern void pq_putnchar(char *s, int n); extern void pq_putnchar(char *s, int n);
extern void pq_putint(int i, int b); extern void pq_putint(int i, int b);
extern int pq_sendoob(char *msg, int len); extern int pq_sendoob(char *msg, int len);
extern int pq_recvoob(char *msgPtr, int *lenPtr); extern int pq_recvoob(char *msgPtr, int len);
extern int pq_getinaddr(struct sockaddr_in * sin, char *host, int port); extern int pq_getinaddr(struct sockaddr_in * sin, char *host, int port);
extern int pq_getinserv(struct sockaddr_in * sin, char *host, char *serv); extern int pq_getinserv(struct sockaddr_in * sin, char *host, char *serv);
extern int extern int
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: miscadmin.h,v 1.22 1998/04/05 21:04:50 momjian Exp $ * $Id: miscadmin.h,v 1.23 1998/05/19 18:05:52 momjian Exp $
* *
* NOTES * NOTES
* some of the information in this file will be moved to * some of the information in this file will be moved to
...@@ -35,8 +35,9 @@ extern int PostmasterMain(int argc, char *argv[]); ...@@ -35,8 +35,9 @@ extern int PostmasterMain(int argc, char *argv[]);
* from utils/init/globals.c * from utils/init/globals.c
*/ */
extern int Portfd; extern int Portfd;
extern int Noversion; extern bool Noversion;
extern int Quiet; extern bool Quiet;
extern bool QueryCancel;
extern char *DataDir; extern char *DataDir;
extern int MyProcPid; extern int MyProcPid;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: tcopprot.h,v 1.11 1998/02/26 04:43:41 momjian Exp $ * $Id: tcopprot.h,v 1.12 1998/05/19 18:05:58 momjian Exp $
* *
* OLD COMMENTS * OLD COMMENTS
* This file was created so that other c files could get the two * This file was created so that other c files could get the two
...@@ -34,6 +34,7 @@ pg_exec_query_dest(char *query_string, char **argv, Oid *typev, ...@@ -34,6 +34,7 @@ pg_exec_query_dest(char *query_string, char **argv, Oid *typev,
extern void handle_warn(SIGNAL_ARGS); extern void handle_warn(SIGNAL_ARGS);
extern void die(SIGNAL_ARGS); extern void die(SIGNAL_ARGS);
extern void CancelQuery(void);
extern int PostgresMain(int argc, char *argv[]); extern int PostgresMain(int argc, char *argv[]);
extern void ResetUsage(void); extern void ResetUsage(void);
extern void ShowUsage(void); extern void ShowUsage(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment