未验证 提交 343646f9 编写于 作者: X Xiaoyu Wang 提交者: GitHub

Merge pull request #19166 from taosdata/feat/vnode_compact_wxy

feat: sql command 'compact database'
此差异已折叠。
...@@ -123,6 +123,11 @@ typedef struct STrimDatabaseStmt { ...@@ -123,6 +123,11 @@ typedef struct STrimDatabaseStmt {
int32_t maxSpeed; int32_t maxSpeed;
} STrimDatabaseStmt; } STrimDatabaseStmt;
typedef struct SCompactDatabaseStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
} SCompactDatabaseStmt;
typedef struct STableOptions { typedef struct STableOptions {
ENodeType type; ENodeType type;
bool commentNull; bool commentNull;
......
...@@ -155,7 +155,7 @@ typedef enum ENodeType { ...@@ -155,7 +155,7 @@ typedef enum ENodeType {
QUERY_NODE_EXPLAIN_STMT, QUERY_NODE_EXPLAIN_STMT,
QUERY_NODE_DESCRIBE_STMT, QUERY_NODE_DESCRIBE_STMT,
QUERY_NODE_RESET_QUERY_CACHE_STMT, QUERY_NODE_RESET_QUERY_CACHE_STMT,
QUERY_NODE_COMPACT_STMT, QUERY_NODE_COMPACT_DATABASE_STMT,
QUERY_NODE_CREATE_FUNCTION_STMT, QUERY_NODE_CREATE_FUNCTION_STMT,
QUERY_NODE_DROP_FUNCTION_STMT, QUERY_NODE_DROP_FUNCTION_STMT,
QUERY_NODE_CREATE_STREAM_STMT, QUERY_NODE_CREATE_STREAM_STMT,
......
...@@ -165,6 +165,8 @@ const char* nodesNodeName(ENodeType type) { ...@@ -165,6 +165,8 @@ const char* nodesNodeName(ENodeType type) {
return "ExplainStmt"; return "ExplainStmt";
case QUERY_NODE_DESCRIBE_STMT: case QUERY_NODE_DESCRIBE_STMT:
return "DescribeStmt"; return "DescribeStmt";
case QUERY_NODE_COMPACT_DATABASE_STMT:
return "CompactDatabaseStmt";
case QUERY_NODE_CREATE_STREAM_STMT: case QUERY_NODE_CREATE_STREAM_STMT:
return "CreateStreamStmt"; return "CreateStreamStmt";
case QUERY_NODE_DROP_STREAM_STMT: case QUERY_NODE_DROP_STREAM_STMT:
...@@ -5675,6 +5677,18 @@ static int32_t jsonToDescribeStmt(const SJson* pJson, void* pObj) { ...@@ -5675,6 +5677,18 @@ static int32_t jsonToDescribeStmt(const SJson* pJson, void* pObj) {
return code; return code;
} }
static const char* jkCompactDatabaseStmtDbName = "DbName";
static int32_t compactDatabaseStmtToJson(const void* pObj, SJson* pJson) {
const SCompactDatabaseStmt* pNode = (const SCompactDatabaseStmt*)pObj;
return tjsonAddStringToObject(pJson, jkCompactDatabaseStmtDbName, pNode->dbName);
}
static int32_t jsonToCompactDatabaseStmt(const SJson* pJson, void* pObj) {
SCompactDatabaseStmt* pNode = (SCompactDatabaseStmt*)pObj;
return tjsonGetStringValue(pJson, jkCompactDatabaseStmtDbName, pNode->dbName);
}
static const char* jkCreateStreamStmtStreamName = "StreamName"; static const char* jkCreateStreamStmtStreamName = "StreamName";
static const char* jkCreateStreamStmtTargetDbName = "TargetDbName"; static const char* jkCreateStreamStmtTargetDbName = "TargetDbName";
static const char* jkCreateStreamStmtTargetTabName = "TargetTabName"; static const char* jkCreateStreamStmtTargetTabName = "TargetTabName";
...@@ -6386,6 +6400,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { ...@@ -6386,6 +6400,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
return explainStmtToJson(pObj, pJson); return explainStmtToJson(pObj, pJson);
case QUERY_NODE_DESCRIBE_STMT: case QUERY_NODE_DESCRIBE_STMT:
return describeStmtToJson(pObj, pJson); return describeStmtToJson(pObj, pJson);
case QUERY_NODE_COMPACT_DATABASE_STMT:
return compactDatabaseStmtToJson(pObj, pJson);
case QUERY_NODE_CREATE_STREAM_STMT: case QUERY_NODE_CREATE_STREAM_STMT:
return createStreamStmtToJson(pObj, pJson); return createStreamStmtToJson(pObj, pJson);
case QUERY_NODE_DROP_STREAM_STMT: case QUERY_NODE_DROP_STREAM_STMT:
...@@ -6692,6 +6708,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { ...@@ -6692,6 +6708,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return jsonToExplainStmt(pJson, pObj); return jsonToExplainStmt(pJson, pObj);
case QUERY_NODE_DESCRIBE_STMT: case QUERY_NODE_DESCRIBE_STMT:
return jsonToDescribeStmt(pJson, pObj); return jsonToDescribeStmt(pJson, pObj);
case QUERY_NODE_COMPACT_DATABASE_STMT:
return jsonToCompactDatabaseStmt(pJson, pObj);
case QUERY_NODE_CREATE_STREAM_STMT: case QUERY_NODE_CREATE_STREAM_STMT:
return jsonToCreateStreamStmt(pJson, pObj); return jsonToCreateStreamStmt(pJson, pObj);
case QUERY_NODE_DROP_STREAM_STMT: case QUERY_NODE_DROP_STREAM_STMT:
......
...@@ -374,8 +374,8 @@ SNode* nodesMakeNode(ENodeType type) { ...@@ -374,8 +374,8 @@ SNode* nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SDescribeStmt)); return makeNode(type, sizeof(SDescribeStmt));
case QUERY_NODE_RESET_QUERY_CACHE_STMT: case QUERY_NODE_RESET_QUERY_CACHE_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SNode));
case QUERY_NODE_COMPACT_STMT: case QUERY_NODE_COMPACT_DATABASE_STMT:
break; return makeNode(type, sizeof(SCompactDatabaseStmt));
case QUERY_NODE_CREATE_FUNCTION_STMT: case QUERY_NODE_CREATE_FUNCTION_STMT:
return makeNode(type, sizeof(SCreateFunctionStmt)); return makeNode(type, sizeof(SCreateFunctionStmt));
case QUERY_NODE_DROP_FUNCTION_STMT: case QUERY_NODE_DROP_FUNCTION_STMT:
...@@ -919,7 +919,7 @@ void nodesDestroyNode(SNode* pNode) { ...@@ -919,7 +919,7 @@ void nodesDestroyNode(SNode* pNode) {
taosMemoryFree(((SDescribeStmt*)pNode)->pMeta); taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
break; break;
case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field
case QUERY_NODE_COMPACT_STMT: // no pointer field case QUERY_NODE_COMPACT_DATABASE_STMT: // no pointer field
case QUERY_NODE_CREATE_FUNCTION_STMT: // no pointer field case QUERY_NODE_CREATE_FUNCTION_STMT: // no pointer field
case QUERY_NODE_DROP_FUNCTION_STMT: // no pointer field case QUERY_NODE_DROP_FUNCTION_STMT: // no pointer field
break; break;
......
...@@ -151,6 +151,7 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, STo ...@@ -151,6 +151,7 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, STo
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions);
SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t maxSpeed); SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t maxSpeed);
SNode* createCompactStmt(SAstCreateContext* pCxt, SToken* pDbName);
SNode* createDefaultTableOptions(SAstCreateContext* pCxt); SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
SNode* createAlterTableOptions(SAstCreateContext* pCxt); SNode* createAlterTableOptions(SAstCreateContext* pCxt);
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal);
...@@ -210,7 +211,6 @@ SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* p ...@@ -210,7 +211,6 @@ SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* p
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery); SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery);
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable); SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt); SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups);
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
const SToken* pLibPath, SDataType dataType, int32_t bufSize); const SToken* pLibPath, SDataType dataType, int32_t bufSize);
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pFuncName); SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pFuncName);
......
...@@ -167,6 +167,7 @@ cmd ::= USE db_name(A). ...@@ -167,6 +167,7 @@ cmd ::= USE db_name(A).
cmd ::= ALTER DATABASE db_name(A) alter_db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); } cmd ::= ALTER DATABASE db_name(A) alter_db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
cmd ::= FLUSH DATABASE db_name(A). { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &A); } cmd ::= FLUSH DATABASE db_name(A). { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &A); }
cmd ::= TRIM DATABASE db_name(A) speed_opt(B). { pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &A, B); } cmd ::= TRIM DATABASE db_name(A) speed_opt(B). { pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &A, B); }
cmd ::= COMPACT DATABASE db_name(A). { pCxt->pRootNode = createCompactStmt(pCxt, &A); }
%type not_exists_opt { bool } %type not_exists_opt { bool }
%destructor not_exists_opt { } %destructor not_exists_opt { }
...@@ -519,9 +520,6 @@ explain_options(A) ::= . ...@@ -519,9 +520,6 @@ explain_options(A) ::= .
explain_options(A) ::= explain_options(B) VERBOSE NK_BOOL(C). { A = setExplainVerbose(pCxt, B, &C); } explain_options(A) ::= explain_options(B) VERBOSE NK_BOOL(C). { A = setExplainVerbose(pCxt, B, &C); }
explain_options(A) ::= explain_options(B) RATIO NK_FLOAT(C). { A = setExplainRatio(pCxt, B, &C); } explain_options(A) ::= explain_options(B) RATIO NK_FLOAT(C). { A = setExplainRatio(pCxt, B, &C); }
/************************************************ compact *************************************************************/
//cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
/************************************************ create/drop function ************************************************/ /************************************************ create/drop function ************************************************/
cmd ::= CREATE agg_func_opt(A) FUNCTION not_exists_opt(F) function_name(B) cmd ::= CREATE agg_func_opt(A) FUNCTION not_exists_opt(F) function_name(B)
AS NK_STRING(C) OUTPUTTYPE type_name(D) bufsize_opt(E). { pCxt->pRootNode = createCreateFunctionStmt(pCxt, F, A, &B, &C, D, E); } AS NK_STRING(C) OUTPUTTYPE type_name(D) bufsize_opt(E). { pCxt->pRootNode = createCreateFunctionStmt(pCxt, F, A, &B, &C, D, E); }
...@@ -1077,6 +1075,6 @@ null_ordering_opt(A) ::= . ...@@ -1077,6 +1075,6 @@ null_ordering_opt(A) ::= .
null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; } null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; }
null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; } null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; }
%fallback ABORT AFTER ATTACH BEFORE BEGIN BITAND BITNOT BITOR BLOCKS CHANGE COMMA COMPACT CONCAT CONFLICT COPY DEFERRED DELIMITERS DETACH DIVIDE DOT EACH END FAIL %fallback ABORT AFTER ATTACH BEFORE BEGIN BITAND BITNOT BITOR BLOCKS CHANGE COMMA CONCAT CONFLICT COPY DEFERRED DELIMITERS DETACH DIVIDE DOT EACH END FAIL
FILE FOR GLOB ID IMMEDIATE IMPORT INITIALLY INSTEAD ISNULL KEY MODULES NK_BITNOT NK_SEMI NOTNULL OF PLUS PRIVILEGE RAISE REPLACE RESTRICT ROW SEMI STAR STATEMENT FILE FOR GLOB ID IMMEDIATE IMPORT INITIALLY INSTEAD ISNULL KEY MODULES NK_BITNOT NK_SEMI NOTNULL OF PLUS PRIVILEGE RAISE REPLACE RESTRICT ROW SEMI STAR STATEMENT
STRICT STRING TIMES UPDATE VALUES VARIABLE VIEW WAL. STRICT STRING TIMES UPDATE VALUES VARIABLE VIEW WAL.
...@@ -1087,6 +1087,17 @@ SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t ...@@ -1087,6 +1087,17 @@ SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createCompactStmt(SAstCreateContext* pCxt, SToken* pDbName) {
CHECK_PARSER_STATUS(pCxt);
if (!checkDbName(pCxt, pDbName, false)) {
return NULL;
}
SCompactDatabaseStmt* pStmt = (SCompactDatabaseStmt*)nodesMakeNode(QUERY_NODE_COMPACT_DATABASE_STMT);
CHECK_OUT_OF_MEM(pStmt);
COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
return (SNode*)pStmt;
}
SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
...@@ -1697,13 +1708,6 @@ SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) { ...@@ -1697,13 +1708,6 @@ SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) {
return pStmt; return pStmt;
} }
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
CHECK_PARSER_STATUS(pCxt);
SNode* pStmt = nodesMakeNode(QUERY_NODE_COMPACT_STMT);
CHECK_OUT_OF_MEM(pStmt);
return pStmt;
}
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
const SToken* pLibPath, SDataType dataType, int32_t bufSize) { const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
......
...@@ -61,6 +61,7 @@ static SKeyword keywordTable[] = { ...@@ -61,6 +61,7 @@ static SKeyword keywordTable[] = {
{"COLUMN", TK_COLUMN}, {"COLUMN", TK_COLUMN},
{"COMMENT", TK_COMMENT}, {"COMMENT", TK_COMMENT},
{"COMP", TK_COMP}, {"COMP", TK_COMP},
{"COMPACT", TK_COMPACT},
{"CONNECTION", TK_CONNECTION}, {"CONNECTION", TK_CONNECTION},
{"CONNECTIONS", TK_CONNECTIONS}, {"CONNECTIONS", TK_CONNECTIONS},
{"CONNS", TK_CONNS}, {"CONNS", TK_CONNS},
......
...@@ -5445,7 +5445,7 @@ static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pSt ...@@ -5445,7 +5445,7 @@ static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pSt
} }
static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) { static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) {
// todo // The statement is executed directly on the client without constructing a message.
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -5460,6 +5460,14 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) ...@@ -5460,6 +5460,14 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt)
return refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta); return refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
} }
static int32_t translateCompact(STranslateContext* pCxt, SCompactDatabaseStmt* pStmt) {
SCompactDbReq compactReq = {0};
SName name;
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
tNameGetFullDbName(&name, compactReq.db);
return buildCmdMsg(pCxt, TDMT_MND_COMPACT_DB, (FSerializeFunc)tSerializeSCompactDbReq, &compactReq);
}
static int32_t translateKillConnection(STranslateContext* pCxt, SKillStmt* pStmt) { static int32_t translateKillConnection(STranslateContext* pCxt, SKillStmt* pStmt) {
SKillConnReq killReq = {0}; SKillConnReq killReq = {0};
killReq.connId = pStmt->targetId; killReq.connId = pStmt->targetId;
...@@ -6015,6 +6023,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { ...@@ -6015,6 +6023,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case QUERY_NODE_DESCRIBE_STMT: case QUERY_NODE_DESCRIBE_STMT:
code = translateDescribe(pCxt, (SDescribeStmt*)pNode); code = translateDescribe(pCxt, (SDescribeStmt*)pNode);
break; break;
case QUERY_NODE_COMPACT_DATABASE_STMT:
code = translateCompact(pCxt, (SCompactDatabaseStmt*)pNode);
break;
case QUERY_NODE_KILL_CONNECTION_STMT: case QUERY_NODE_KILL_CONNECTION_STMT:
code = translateKillConnection(pCxt, (SKillStmt*)pNode); code = translateKillConnection(pCxt, (SKillStmt*)pNode);
break; break;
......
此差异已折叠。
...@@ -21,6 +21,26 @@ namespace ParserTest { ...@@ -21,6 +21,26 @@ namespace ParserTest {
class ParserInitialCTest : public ParserDdlTest {}; class ParserInitialCTest : public ParserDdlTest {};
/*
* COMPACT DATABASE db_name
*/
TEST_F(ParserInitialCTest, compact) {
SCompactDbReq expect = {0};
auto setCompactDbReq = [&](const char* pDb) { snprintf(expect.db, sizeof(expect.db), "0.%s", pDb); };
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_COMPACT_DATABASE_STMT);
ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_COMPACT_DB);
SCompactDbReq req = {0};
ASSERT_EQ(tDeserializeSCompactDbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
ASSERT_EQ(std::string(req.db), std::string(expect.db));
});
setCompactDbReq("wxy_db");
run("COMPACT DATABASE wxy_db");
}
/* /*
* CREATE ACCOUNT account_name PASS value [create_account_options] * CREATE ACCOUNT account_name PASS value [create_account_options]
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册