forked from huawei/openGauss-server
add shutdown opt and test case
This commit is contained in:
parent
9b1f35bdd1
commit
738fe74f94
|
|
@ -5713,6 +5713,13 @@ static BloomFilterSet* _copyBloomFilterSet(const BloomFilterSet* from)
|
|||
return newnode;
|
||||
}
|
||||
|
||||
static ShutdownStmt* _copyShutdownStmt(const ShutdownStmt* from)
|
||||
{
|
||||
ShutdownStmt* newnode = makeNode(ShutdownStmt);
|
||||
COPY_STRING_FIELD(mode);
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* copyObject
|
||||
*
|
||||
|
|
@ -6766,6 +6773,11 @@ void* copyObject(const void* from)
|
|||
case T_DropDirectoryStmt:
|
||||
retval = _copyDropDirectoryStmt((DropDirectoryStmt*)from);
|
||||
break;
|
||||
|
||||
/* shutdown */
|
||||
case T_ShutdownStmt:
|
||||
retval = _copyShutdownStmt((ShutdownStmt*)from);
|
||||
break;
|
||||
default:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNRECOGNIZED_NODE_TYPE), errmsg("unrecognized node type: %d", (int)nodeTag(from))));
|
||||
|
|
|
|||
|
|
@ -2690,6 +2690,12 @@ static bool _equalGroupingId(const GroupingId* a, const GroupingId* b)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool _equalShutDown(const ShutdownStmt* a, const ShutdownStmt* b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* equal
|
||||
* returns whether two nodes are equal
|
||||
|
|
@ -3298,6 +3304,9 @@ bool equal(const void* a, const void* b)
|
|||
case T_AlterTSConfigurationStmt:
|
||||
retval = _equalAlterTSConfigurationStmt((AlterTSConfigurationStmt*)a, (AlterTSConfigurationStmt*)b);
|
||||
break;
|
||||
case T_ShutdownStmt:
|
||||
retval = _equalShutDown((ShutdownStmt*)a, (ShutdownStmt*)b);
|
||||
break;
|
||||
|
||||
case T_A_Expr:
|
||||
retval = _equalAExpr((A_Expr*)a, (A_Expr*)b);
|
||||
|
|
|
|||
|
|
@ -381,6 +381,7 @@ static const TagStr g_tagStrArr[] = {{T_Invalid, "Invalid"},
|
|||
{T_DropDirectoryStmt, "DropDirectoryStmt"},
|
||||
{T_CreateRlsPolicyStmt, "CreateRlsPolicyStmt"},
|
||||
{T_AlterRlsPolicyStmt, "AlterRlsPolicyStmt"},
|
||||
{T_ShutdownStmt, "ShutdownStmt"},
|
||||
{T_A_Expr, "A_Expr"},
|
||||
{T_ColumnRef, "ColumnRef"},
|
||||
{T_ParamRef, "ParamRef"},
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ static void ParseUpdateMultiSet(List *set_target_list, SelectStmt *stmt, core_yy
|
|||
RuleActionStmt RuleActionStmtOrEmpty RuleStmt
|
||||
SecLabelStmt SelectStmt TransactionStmt TruncateStmt CallFuncStmt
|
||||
UnlistenStmt UpdateStmt VacuumStmt
|
||||
VariableResetStmt VariableSetStmt VariableShowStmt VerifyStmt
|
||||
VariableResetStmt VariableSetStmt VariableShowStmt VerifyStmt ShutdownStmt
|
||||
ViewStmt CheckPointStmt CreateConversionStmt
|
||||
DeallocateStmt PrepareStmt ExecuteStmt
|
||||
DropOwnedStmt ReassignOwnedStmt
|
||||
|
|
@ -684,7 +684,7 @@ static void ParseUpdateMultiSet(List *set_target_list, SelectStmt *stmt, core_yy
|
|||
ROW ROWS RULE
|
||||
|
||||
SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
|
||||
SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHIPPABLE SHOW
|
||||
SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHIPPABLE SHOW SHUTDOWN
|
||||
SIMILAR SIMPLE SIZE SMALLDATETIME SMALLDATETIME_FORMAT_P SMALLINT SNAPSHOT SOME SOURCE_P SPACE SPILL SPLIT STABLE STANDALONE_P START
|
||||
STATEMENT STATEMENT_ID STATISTICS STDIN STDOUT STORAGE STORE_P STRICT_P STRIP_P SUBSTRING
|
||||
SYMMETRIC SYNONYM SYSDATE SYSID SYSTEM_P SYS_REFCURSOR
|
||||
|
|
@ -976,6 +976,7 @@ stmt :
|
|||
| RuleStmt
|
||||
| SecLabelStmt
|
||||
| SelectStmt
|
||||
| ShutdownStmt
|
||||
| TransactionStmt
|
||||
| TruncateStmt
|
||||
| UnlistenStmt
|
||||
|
|
@ -2074,6 +2075,25 @@ constraints_set_mode:
|
|||
| IMMEDIATE { $$ = FALSE; }
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* SHUTDOWN STATEMENT
|
||||
*
|
||||
*****************************************************************************/
|
||||
ShutdownStmt:
|
||||
SHUTDOWN
|
||||
{
|
||||
ShutdownStmt *n = makeNode(ShutdownStmt);
|
||||
n->mode = NULL;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| SHUTDOWN var_name
|
||||
{
|
||||
ShutdownStmt *n = makeNode(ShutdownStmt);
|
||||
n->mode = $2;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
;
|
||||
|
||||
/*
|
||||
* Checkpoint statement
|
||||
|
|
@ -17842,6 +17862,7 @@ unreserved_keyword:
|
|||
| SHARE
|
||||
| SHIPPABLE
|
||||
| SHOW
|
||||
| SHUTDOWN
|
||||
| SIMPLE
|
||||
| SIZE
|
||||
| SMALLDATETIME_FORMAT_P
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ OBJS = aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \
|
|||
portalcmds.o prepare.o proclang.o \
|
||||
schemacmds.o seclabel.o sec_rls_cmds.o sequence.o tablecmds.o tablespace.o trigger.o \
|
||||
tsearchcmds.o typecmds.o user.o vacuum.o vacuumlazy.o \
|
||||
variable.o verify.o view.o gds_stream.o obs_stream.o formatter.o datasourcecmds.o directory.o
|
||||
variable.o verify.o view.o gds_stream.o obs_stream.o formatter.o datasourcecmds.o directory.o shutdown.o
|
||||
|
||||
include $(top_srcdir)/src/gausskernel/common.mk
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/* -------------------------------------------------------------------------
|
||||
*
|
||||
* shutdown.cpp
|
||||
* do shutdown command
|
||||
*
|
||||
* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/gausskernel/optimizer/commands/shutdown.cpp
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include "knl/knl_variable.h"
|
||||
#include "miscadmin.h"
|
||||
#include "commands/shutdown.h"
|
||||
|
||||
void DoShutdown(ShutdownStmt* stmt)
|
||||
{
|
||||
if (!superuser()) {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("Only system admin can shutdown database."))));
|
||||
}
|
||||
|
||||
int signal;
|
||||
char* shutdown_mode = stmt->mode;
|
||||
|
||||
if (shutdown_mode == NULL || strcmp(shutdown_mode, "fast") == 0) {
|
||||
signal = SIGINT;
|
||||
} else if (strcmp(shutdown_mode, "smart") == 0) {
|
||||
signal = SIGTERM;
|
||||
} else if (strcmp(shutdown_mode, "immediate") == 0) {
|
||||
signal = SIGQUIT;
|
||||
} else {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unknow parameter: %s\nshutdown only support fast, smart and immediate mode.\n", shutdown_mode)));
|
||||
}
|
||||
|
||||
if (gs_signal_send(PostmasterPid, signal)) {
|
||||
ereport(WARNING,
|
||||
(errmsg("Failed to send %s shutdown signal to postmaster.", shutdown_mode)));
|
||||
}
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@
|
|||
#include "commands/seclabel.h"
|
||||
#include "commands/sec_rls_cmds.h"
|
||||
#include "commands/sequence.h"
|
||||
#include "commands/shutdown.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "commands/tablespace.h"
|
||||
#include "commands/directory.h"
|
||||
|
|
@ -4911,6 +4912,11 @@ void standard_ProcessUtility(Node* parse_tree, const char* query_string, ParamLi
|
|||
|
||||
GetPGVariable(n->name, dest);
|
||||
} break;
|
||||
case T_ShutdownStmt: {
|
||||
ShutdownStmt* n = (ShutdownStmt*)parse_tree;
|
||||
|
||||
DoShutdown(n);
|
||||
} break;
|
||||
|
||||
case T_DiscardStmt:
|
||||
#ifdef PGXC
|
||||
|
|
@ -7517,6 +7523,9 @@ const char* CreateCommandTag(Node* parse_tree)
|
|||
case T_DropDirectoryStmt:
|
||||
tag = "DROP DIRECTORY";
|
||||
break;
|
||||
case T_ShutdownStmt:
|
||||
tag = "SHUTDOWN";
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARNING, "unrecognized node type: %d", (int)nodeTag(parse_tree));
|
||||
|
|
@ -8235,6 +8244,10 @@ LogStmtLevel GetCommandLogLevel(Node* parse_tree)
|
|||
lev = LOGSTMT_DDL;
|
||||
break;
|
||||
|
||||
case T_ShutdownStmt:
|
||||
lev = LOGSTMT_ALL;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARNING, "unrecognized node type: %d", (int)nodeTag(parse_tree));
|
||||
lev = LOGSTMT_ALL;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/* -------------------------------------------------------------------------
|
||||
*
|
||||
* shutdown.h
|
||||
* prototypes for shutdown.cpp
|
||||
*
|
||||
* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
||||
*
|
||||
* src/include/commands/shutdown.h
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef SHUTDOWN_H
|
||||
#define SHUTDOWN_H
|
||||
|
||||
#include "nodes/parsenodes.h"
|
||||
|
||||
extern void DoShutdown(ShutdownStmt* stmt);
|
||||
|
||||
#endif /* SHUTDOWN_H */
|
||||
|
|
@ -389,6 +389,7 @@ typedef enum NodeTag {
|
|||
T_AlterSeqStmt,
|
||||
T_VariableSetStmt,
|
||||
T_VariableShowStmt,
|
||||
T_ShutdownStmt,
|
||||
T_DiscardStmt,
|
||||
T_CreateTrigStmt,
|
||||
T_CreatePLangStmt,
|
||||
|
|
|
|||
|
|
@ -1768,6 +1768,15 @@ typedef struct VariableShowStmt {
|
|||
char* name;
|
||||
} VariableShowStmt;
|
||||
|
||||
/* ----------------------
|
||||
* Shutdown Statement
|
||||
* ----------------------
|
||||
*/
|
||||
typedef struct ShutdownStmt {
|
||||
NodeTag type;
|
||||
char* mode;
|
||||
} ShutdownStmt;
|
||||
|
||||
/*
|
||||
* definition of a range partition.
|
||||
* range partition pattern: PARTITION [partitionName] LESS THAN [boundary]
|
||||
|
|
|
|||
|
|
@ -453,6 +453,7 @@ PG_KEYWORD("sets", SETS, UNRESERVED_KEYWORD)
|
|||
PG_KEYWORD("share", SHARE, UNRESERVED_KEYWORD)
|
||||
PG_KEYWORD("shippable", SHIPPABLE, UNRESERVED_KEYWORD)
|
||||
PG_KEYWORD("show", SHOW, UNRESERVED_KEYWORD)
|
||||
PG_KEYWORD("shutdown", SHUTDOWN, UNRESERVED_KEYWORD)
|
||||
PG_KEYWORD("similar", SIMILAR, TYPE_FUNC_NAME_KEYWORD)
|
||||
PG_KEYWORD("simple", SIMPLE, UNRESERVED_KEYWORD)
|
||||
PG_KEYWORD("size", SIZE, UNRESERVED_KEYWORD)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
DROP ROLE IF EXISTS shutdown_test;
|
||||
NOTICE: role "shutdown_test" does not exist, skipping
|
||||
CREATE USER shutdown_test WITH PASSWORD 'Shutdown@123';
|
||||
SET SESSION AUTHORIZATION shutdown_test PASSWORD 'Shutdown@123';
|
||||
shutdown;
|
||||
ERROR: Only system admin can shutdown database.
|
||||
shutdown invalid_str;
|
||||
ERROR: Only system admin can shutdown database.
|
||||
shutdown fast;
|
||||
ERROR: Only system admin can shutdown database.
|
||||
shutdown smart;
|
||||
ERROR: Only system admin can shutdown database.
|
||||
shutdown immediate;
|
||||
ERROR: Only system admin can shutdown database.
|
||||
\c
|
||||
DROP USER shutdown_test;
|
||||
shutdown invalid_str;
|
||||
ERROR: unknow parameter: invalid_str
|
||||
shutdown only support fast, smart and immediate mode.
|
||||
|
||||
|
|
@ -70,6 +70,7 @@ test: hw_procedure_define hw_anonymous_block hw_procedure
|
|||
test: hw_grant_all hw_dynamic_sql hw_func_return_out
|
||||
#test: hw_show_tabledef
|
||||
test: hw_package_function
|
||||
test: shutdown
|
||||
|
||||
#show plan
|
||||
test: plan_hint
|
||||
|
|
|
|||
|
|
@ -18,3 +18,4 @@ test: hw_procedure_define hw_anonymous_block hw_procedure
|
|||
test: hw_grant_all hw_dynamic_sql hw_func_return_out
|
||||
#test: hw_show_tabledef
|
||||
test: hw_package_function
|
||||
test: shutdown
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
DROP ROLE IF EXISTS shutdown_test;
|
||||
|
||||
CREATE USER shutdown_test WITH PASSWORD 'Shutdown@123';
|
||||
|
||||
SET SESSION AUTHORIZATION shutdown_test PASSWORD 'Shutdown@123';
|
||||
|
||||
shutdown;
|
||||
shutdown invalid_str;
|
||||
shutdown fast;
|
||||
shutdown smart;
|
||||
shutdown immediate;
|
||||
|
||||
\c
|
||||
|
||||
DROP USER shutdown_test;
|
||||
|
||||
shutdown invalid_str;
|
||||
Loading…
Reference in New Issue