提交 318e6c39 编写于 作者: H Heikki Linnakangas

Remove gp_cancel_query() and friends.

The upstream pg_cancel_backend() function should work fine on GPDB. It's
not exactly the same: in gp_cancel_query(), you would pass the sesssion ID
and command ID as argument, while pg_cancel_backend() takes a PID. But it
seems just as good from a usability point of view. Let's avoid the
duplicate code, and remove gp_cancel_query().

Also remove the gp_cancel_query_print_log and gp_cancel_query_delay_time
GUCs. They were not directly related to gp_cancel_query() - they would
have an effect on cancellations caused by pg_cancel_backend() or
statement_timeout, too. But they were marked as "developer options", and
they printed the session and command ID so I think they were meant to be
used with gp_cancel_backend(). I don't think anyone uses them, though, so
let's just remove them, rather than change them to print PIDs.
上级 8880c885
......@@ -22,7 +22,6 @@ all:
$(MAKE) -C contrib/gp_distribution_policy all
$(MAKE) -C contrib/gp_inject_fault all
$(MAKE) -C contrib/gp_internal_tools all
$(MAKE) -C contrib/gp_cancel_query all
$(MAKE) -C contrib/indexscan all
$(MAKE) -C contrib/pg_upgrade_support all
$(MAKE) -C contrib/pg_upgrade all
......@@ -58,7 +57,6 @@ install:
$(MAKE) -C contrib/gp_distribution_policy $@
$(MAKE) -C contrib/gp_inject_fault $@
$(MAKE) -C contrib/gp_internal_tools $@
$(MAKE) -C contrib/gp_cancel_query $@
$(MAKE) -C contrib/indexscan $@
$(MAKE) -C contrib/pg_upgrade_support $@
$(MAKE) -C contrib/pg_upgrade $@
......
......@@ -55,7 +55,6 @@ SUBDIRS += \
gp_distribution_policy \
gp_internal_tools \
gp_inject_fault \
gp_cancel_query \
gp_sparse_vector \
indexscan \
......
MODULE_big = gp_cancel_query
OBJS = gp_cancel_query.o
PG_CPPFLAGS = -I$(libpq_srcdir)
ifdef USE_PGXS
PGXS := $(shell pg_config --pgxs)
include $(PGXS)
else
subdir = contrib/gp_cancel_query
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
/*
* Copyright (c) 2011 EMC Corporation All Rights Reserved
*
* This software is protected, without limitation, by copyright law
* and international treaties. Use of this software and the intellectual
* property contained therein is expressly limited to the terms and
* conditions of the License Agreement under which it is provided by
* or on behalf of EMC.
*
* ---------------------------------------------------------------------
*
* Interface to gp_cancel_query_wrapper function.
*
* The gp_cancel_query_wrapper function is a wrapper around the gp_cancel_query
* function located in the postgres backend executable. Since we can not call the
* gp_cancel_query function directly without a change to the catalog tables, this
* wrapper will allow a user to create a function using this wrapper and indirectly
* call gp_cancel_query.
*
* The dynamicly linked library created from this source can be reference by
* creating a function in psql that references it. For example,
*
* CREATE OR REPLACE FUNCTION gp_cancel_query(int, int)
* RETURNS bool
* AS '$libdir/gp_cancel_query.so', 'gp_cancel_query_wrapper' LANGUAGE C STRICT;
*
*/
#include "postgres.h"
#include <string.h>
#include "fmgr.h"
#include "funcapi.h"
#include "utils/builtins.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
extern Datum gp_cancel_query(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(gp_cancel_query_wrapper);
extern Datum gp_cancel_query_wrapper(PG_FUNCTION_ARGS);
/*
* gp_cancel_query_wrapper
* The wrapper for creating a user-defined C function for gp_cancel_query.
*/
Datum
gp_cancel_query_wrapper(PG_FUNCTION_ARGS)
{
return gp_cancel_query(fcinfo);
}
......@@ -760,14 +760,6 @@ gpvars_check_statement_mem(int *newval, void **extra, GucSource source)
void
increment_command_count()
{
if (gp_cancel_query_print_log)
{
ereport(LOG,
(errmsg("Incrementing command count from %d to %d",
gp_command_count, gp_command_count + 1),
errprintstack(true)));
}
gp_command_count++;
if (gp_command_count <= 0)
{
......
......@@ -2372,23 +2372,6 @@ void mppExecutorCleanup(QueryDesc *queryDesc)
QueryCancelCleanup)
{
gpmon_qlog_query_canceling(queryDesc->gpmon_pkt);
if (gp_cancel_query_print_log)
{
elog(LOG, "canceling query (%d, %d)",
queryDesc->gpmon_pkt->u.qlog.key.ssid,
queryDesc->gpmon_pkt->u.qlog.key.ccnt);
}
}
/*
* Delaying the cancellation for a specified time.
*/
if (Gp_role == GP_ROLE_DISPATCH &&
QueryCancelCleanup &&
gp_cancel_query_delay_time > 0)
{
pg_usleep(gp_cancel_query_delay_time * 1000);
}
/*
......
......@@ -3672,55 +3672,6 @@ FindProcByGpSessionId(long gp_session_id)
return NULL;
}
/*
* FindAndSignalProcess
* Find the PGPROC entry in procArray which contains the given sessionId and commandId,
* and send the corresponding process an interrupt signal.
*
* This function returns false if not such an entry found in procArray or the interrupt
* signal can not be sent to the process.
*/
bool
FindAndSignalProcess(int sessionId, int commandId)
{
Assert(sessionId > 0 && commandId > 0);
bool queryCancelled = false;
int pid = 0;
LWLockAcquire(ProcArrayLock, LW_SHARED);
for (int index = 0; index < procArray->numProcs; index++)
{
PGPROC *proc = &allProcs[procArray->pgprocnos[index]];
if (proc->mppSessionId == sessionId &&
proc->queryCommandId == commandId)
{
/* If we have setsid(), signal the backend's whole process group */
#ifdef HAVE_SETSID
if (kill(-proc->pid, SIGINT) == 0)
#else
if (kill(proc->pid, SIGINT) == 0)
#endif
{
pid = proc->pid;
queryCancelled = true;
}
break;
}
}
LWLockRelease(ProcArrayLock);
if (gp_cancel_query_print_log && queryCancelled)
{
elog(NOTICE, "sent an interrupt to process %d", pid);
}
return queryCancelled;
}
/* ----------------------------------------------
* KnownAssignedTransactions sub-module
* ----------------------------------------------
......
......@@ -493,8 +493,6 @@ InitProcess(void)
/* Set wait portal (do not check if resource scheduling is enabled) */
MyProc->waitPortalId = INVALID_PORTALID;
MyProc->queryCommandId = -1;
/* Init gxact */
initGxact(MyTmGxact);
......@@ -653,8 +651,6 @@ InitAuxiliaryProcess(void)
*/
PGSemaphoreReset(&MyProc->sem);
MyProc->queryCommandId = -1;
/*
* Arrange to clean up at process exit.
*/
......
......@@ -1558,17 +1558,8 @@ exec_simple_query(const char *query_string)
char msec_str[32];
if (Gp_role != GP_ROLE_EXECUTE)
{
increment_command_count();
MyProc->queryCommandId = gp_command_count;
if (gp_cancel_query_print_log)
{
elog(NOTICE, "running query (sessionId, commandId): (%d, %d)",
MyProc->mppSessionId, gp_command_count);
}
}
/*
* Report query to various monitoring facilities.
*/
......@@ -2621,24 +2612,7 @@ exec_execute_message(const char *portal_name, int64 max_rows)
}
}
if (is_utility_stmt)
{
increment_command_count();
MyProc->queryCommandId = gp_command_count;
if (gp_cancel_query_print_log)
{
elog(NOTICE, "running query (sessionId, commandId): (%d, %d)",
MyProc->mppSessionId, gp_command_count);
elog(LOG, "In exec_execute_message found utility statement, incrementing command_count");
}
}
else
{
if (gp_cancel_query_print_log)
{
elog(LOG, "In exec_execute_message found non-utility statement, NOT incrementing command count");
}
}
}
/* Does the portal contain a transaction command? */
......
......@@ -114,17 +114,8 @@ CreateQueryDesc(PlannedStmt *plannedstmt,
qd->gpmon_pkt = NULL;
if (Gp_role != GP_ROLE_EXECUTE)
{
increment_command_count();
MyProc->queryCommandId = gp_command_count;
if (gp_cancel_query_print_log)
{
elog(NOTICE, "running query (sessionId, commandId): (%d, %d)",
MyProc->mppSessionId, gp_command_count);
}
}
if(gp_enable_gpperfmon && Gp_role == GP_ROLE_DISPATCH)
{
qd->gpmon_pkt = (gpmon_packet_t *) palloc0(sizeof(gpmon_packet_t));
......
......@@ -219,60 +219,6 @@ pg_terminate_backend_msg(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(pg_signal_backend(pid, SIGTERM, msg) == SIGNAL_BACKEND_SUCCESS);
}
/*
* gp_cancel_query_internal
* Cancel the query that is identified by (sessionId, commandId) pair.
*
* This function errors out if this is called by non-super user.
* This function prints a warning and returns false when (sessionId, commandId) does not
* exist.
*
* In all other cases, this function finds the process id from procArray, and sends
* an interrupt signal to the process.
*/
static bool
gp_cancel_query_internal(int sessionId, int commandId)
{
if (!superuser())
{
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to cancel a query"))));
}
if (!(sessionId > 0 && commandId > 0))
{
ereport(WARNING,
(errcode(ERRCODE_WARNING),
errmsg("invalid session_id or command_id for query (session_id, command_id): (%d, %d)",
DatumGetInt32(sessionId), DatumGetInt32(commandId))));
return false;
}
bool succeed = FindAndSignalProcess(sessionId, commandId);
if (!succeed)
{
ereport(WARNING,
(errcode(ERRCODE_WARNING),
errmsg("failed to cancel query (session_id, command_id): (%d, %d)",
DatumGetInt32(sessionId), DatumGetInt32(commandId))));
return false;
}
return true;
}
/*
* gp_cancel_query
* Cancel the query that is identified by (sessionId, commandId) pair.
*/
Datum
gp_cancel_query(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(gp_cancel_query_internal(PG_GETARG_INT32(0),
PG_GETARG_INT32(1)));
}
/*
* Signal to reload the database configuration
*/
......
......@@ -280,9 +280,6 @@ int gp_test_time_slice_report_level = ERROR;
bool gp_test_deadlock_hazard;
int gp_test_deadlock_hazard_report_level = ERROR;
/* query cancellation GUC */
bool gp_cancel_query_print_log;
int gp_cancel_query_delay_time;
bool vmem_process_interrupt = false;
bool execute_pruned_plan = false;
......@@ -1982,17 +1979,6 @@ struct config_bool ConfigureNamesBool_gp[] =
NULL, NULL, NULL
},
{
{"gp_cancel_query_print_log", PGC_USERSET, DEVELOPER_OPTIONS,
gettext_noop("Print out debugging info for a canceled query"),
NULL,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_GPDB_ADDOPT
},
&gp_cancel_query_print_log,
false,
NULL, NULL, NULL
},
{
{"gp_partitioning_dynamic_selection_log", PGC_USERSET, DEVELOPER_OPTIONS,
gettext_noop("Print out debugging info for GPDB dynamic partition selection"),
......@@ -3078,17 +3064,6 @@ struct config_int ConfigureNamesInt_gp[] =
NULL, NULL, NULL
},
{
{"gp_cancel_query_delay_time", PGC_USERSET, DEVELOPER_OPTIONS,
gettext_noop("The time in milliseconds to delay a query cancellation."),
NULL,
GUC_UNIT_MS | GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_GPDB_ADDOPT
},
&gp_cancel_query_delay_time,
0, 0, INT_MAX,
NULL, NULL, NULL
},
{
{"gp_max_local_distributed_cache", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Sets the number of local-distributed transactions to cache for optimizing visibility processing by backends."),
......
......@@ -166,8 +166,6 @@ struct PGPROC
*/
uint32 combocid_map_count; /* how many entries in the map ? */
int queryCommandId; /* command_id for the running query */
bool serializableIsoLevel; /* true if proc has serializable isolation level set */
/*
......
......@@ -90,8 +90,6 @@ extern void updateSharedLocalSnapshot(struct DtxContextInfo *dtxContextInfo, str
extern void GetSlotTableDebugInfo(void **snapshotArray, int *maxSlots);
extern bool FindAndSignalProcess(int sessionId, int commandId);
extern void getDtxCheckPointInfo(char **result, int *result_size);
extern List *ListAllGxid(void);
......
......@@ -503,7 +503,6 @@ extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
extern Datum pg_terminate_backend(PG_FUNCTION_ARGS);
extern Datum pg_cancel_backend_msg(PG_FUNCTION_ARGS);
extern Datum pg_terminate_backend_msg(PG_FUNCTION_ARGS);
extern Datum gp_cancel_query(PG_FUNCTION_ARGS);
extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
extern Datum pg_tablespace_location(PG_FUNCTION_ARGS);
......
......@@ -322,8 +322,6 @@ extern int temp_file_limit;
extern int num_temp_buffers;
extern bool gp_cancel_query_print_log;
extern int gp_cancel_query_delay_time;
extern bool vmem_process_interrupt;
extern bool execute_pruned_plan;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册