提交 a8c65cd2 编写于 作者: D dapan1121

feat: support restore dnode clause

上级 843d6060
......@@ -1634,8 +1634,6 @@ enum {
typedef struct {
int32_t dnodeId;
char fqdn[TSDB_FQDN_LEN];
int32_t port;
int8_t restoreType;
} SRestoreDnodeReq;
......
此差异已折叠。
......@@ -350,6 +350,11 @@ typedef struct SDropComponentNodeStmt {
int32_t dnodeId;
} SDropComponentNodeStmt;
typedef struct SRestoreComponentNodeStmt {
ENodeType type;
int32_t dnodeId;
} SRestoreComponentNodeStmt;
typedef struct SCreateTopicStmt {
ENodeType type;
char topicName[TSDB_TABLE_NAME_LEN];
......
......@@ -211,6 +211,10 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_DB_ALIVE_STMT,
QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
QUERY_NODE_RESTORE_DNODE_STMT,
QUERY_NODE_RESTORE_QNODE_STMT,
QUERY_NODE_RESTORE_MNODE_STMT,
QUERY_NODE_RESTORE_VNODE_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
......
......@@ -1726,8 +1726,6 @@ int32_t tSerializeSRestoreDnodeReq(void *buf, int32_t bufLen, SRestoreDnodeReq *
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
if (tEncodeI8(&encoder, pReq->restoreType) < 0) return -1;
tEndEncode(&encoder);
......@@ -1742,8 +1740,6 @@ int32_t tDeserializeSRestoreDnodeReq(void *buf, int32_t bufLen, SRestoreDnodeReq
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
if (tDecodeI8(&decoder, &pReq->restoreType) < 0) return -1;
tEndDecode(&decoder);
......
......@@ -257,6 +257,14 @@ const char* nodesNodeName(ENodeType type) {
return "DeleteStmt";
case QUERY_NODE_INSERT_STMT:
return "InsertStmt";
case QUERY_NODE_RESTORE_DNODE_STMT:
return "RestoreDnodeStmt";
case QUERY_NODE_RESTORE_QNODE_STMT:
return "RestoreQnodeStmt";
case QUERY_NODE_RESTORE_MNODE_STMT:
return "RestoreMnodeStmt";
case QUERY_NODE_RESTORE_VNODE_STMT:
return "RestoreVnodeStmt";
case QUERY_NODE_LOGIC_PLAN_SCAN:
return "LogicScan";
case QUERY_NODE_LOGIC_PLAN_JOIN:
......@@ -5533,6 +5541,35 @@ static int32_t jsonToDropDnodeStmt(const SJson* pJson, void* pObj) {
return code;
}
static const char* jkRestoreComponentNodeStmtDnodeId = "DnodeId";
static int32_t restoreComponentNodeStmtToJson(const void* pObj, SJson* pJson) {
const SRestoreComponentNodeStmt* pNode = (const SRestoreComponentNodeStmt*)pObj;
return tjsonAddIntegerToObject(pJson, jkRestoreComponentNodeStmtDnodeId, pNode->dnodeId);
}
static int32_t jsonToRestoreComponentNodeStmt(const SJson* pJson, void* pObj) {
SRestoreComponentNodeStmt* pNode = (SRestoreComponentNodeStmt*)pObj;
return tjsonGetIntValue(pJson, jkRestoreComponentNodeStmtDnodeId, &pNode->dnodeId);
}
static int32_t jsonToRestoreDnodeStmt(const SJson* pJson, void* pObj) {
return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreQnodeStmt(const SJson* pJson, void* pObj) {
return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreMnodeStmt(const SJson* pJson, void* pObj) {
return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreVnodeStmt(const SJson* pJson, void* pObj) {
return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static const char* jkCreateTopicStmtTopicName = "TopicName";
static const char* jkCreateTopicStmtSubscribeDbName = "SubscribeDbName";
static const char* jkCreateTopicStmtIgnoreExists = "IgnoreExists";
......@@ -6820,6 +6857,14 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return jsonToDeleteStmt(pJson, pObj);
case QUERY_NODE_INSERT_STMT:
return jsonToInsertStmt(pJson, pObj);
case QUERY_NODE_RESTORE_DNODE_STMT:
return jsonToRestoreDnodeStmt(pJson, pObj);
case QUERY_NODE_RESTORE_QNODE_STMT:
return jsonToRestoreQnodeStmt(pJson, pObj);
case QUERY_NODE_RESTORE_MNODE_STMT:
return jsonToRestoreMnodeStmt(pJson, pObj);
case QUERY_NODE_RESTORE_VNODE_STMT:
return jsonToRestoreVnodeStmt(pJson, pObj);
case QUERY_NODE_LOGIC_PLAN_SCAN:
return jsonToLogicScanNode(pJson, pObj);
case QUERY_NODE_LOGIC_PLAN_JOIN:
......
......@@ -455,6 +455,11 @@ SNode* nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SInsertStmt));
case QUERY_NODE_QUERY:
return makeNode(type, sizeof(SQuery));
case QUERY_NODE_RESTORE_DNODE_STMT:
case QUERY_NODE_RESTORE_QNODE_STMT:
case QUERY_NODE_RESTORE_MNODE_STMT:
case QUERY_NODE_RESTORE_VNODE_STMT:
return makeNode(type, sizeof(SRestoreComponentNodeStmt));
case QUERY_NODE_LOGIC_PLAN_SCAN:
return makeNode(type, sizeof(SScanLogicNode));
case QUERY_NODE_LOGIC_PLAN_JOIN:
......@@ -1046,6 +1051,11 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pQuery->pPrepareRoot);
break;
}
case QUERY_NODE_RESTORE_DNODE_STMT: // no pointer field
case QUERY_NODE_RESTORE_QNODE_STMT: // no pointer field
case QUERY_NODE_RESTORE_MNODE_STMT: // no pointer field
case QUERY_NODE_RESTORE_VNODE_STMT: // no pointer field
break;
case QUERY_NODE_LOGIC_PLAN_SCAN: {
SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
......
......@@ -123,7 +123,7 @@ priv_level(A) ::= topic_name(B).
with_opt(A) ::= . { A = NULL; }
with_opt(A) ::= WITH search_condition(B). { A = B; }
/************************************************ create/drop/alter dnode *********************************************/
/************************************************ create/drop/alter/restore dnode *********************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
cmd ::= CREATE DNODE dnode_endpoint(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
cmd ::= DROP DNODE NK_INTEGER(A) force_opt(B). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A, B); }
......@@ -132,6 +132,7 @@ cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B).
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B) NK_STRING(C). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, &C); }
cmd ::= ALTER ALL DNODES NK_STRING(A). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, NULL); }
cmd ::= ALTER ALL DNODES NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, &B); }
cmd ::= RESTORE DNODE NK_INTEGER(A). { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_DNODE_STMT, &A); }
%type dnode_endpoint { SToken }
%destructor dnode_endpoint { }
......@@ -148,9 +149,10 @@ force_opt(A) ::= FORCE.
cmd ::= ALTER LOCAL NK_STRING(A). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, NULL); }
cmd ::= ALTER LOCAL NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, &B); }
/************************************************ create/drop qnode ***************************************************/
/************************************************ create/drop/restore qnode ***************************************************/
cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_QNODE_STMT, &A); }
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_QNODE_STMT, &A); }
cmd ::= RESTORE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_QNODE_STMT, &A); }
/************************************************ create/drop bnode ***************************************************/
cmd ::= CREATE BNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_BNODE_STMT, &A); }
......@@ -160,9 +162,13 @@ cmd ::= DROP BNODE ON DNODE NK_INTEGER(A).
cmd ::= CREATE SNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_SNODE_STMT, &A); }
cmd ::= DROP SNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_SNODE_STMT, &A); }
/************************************************ create/drop mnode ***************************************************/
/************************************************ create/drop/restore mnode ***************************************************/
cmd ::= CREATE MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &A); }
cmd ::= DROP MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &A); }
cmd ::= RESTORE MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_MNODE_STMT, &A); }
/************************************************ restore vnode ***************************************************/
cmd ::= RESTORE VNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_VNODE_STMT, &A); }
/************************************************ create/drop/use database ********************************************/
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); }
......
......@@ -1658,6 +1658,14 @@ SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, cons
return (SNode*)pStmt;
}
SNode* createRestoreComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
CHECK_PARSER_STATUS(pCxt);
SRestoreComponentNodeStmt* pStmt = (SRestoreComponentNodeStmt*)nodesMakeNode(type);
CHECK_OUT_OF_MEM(pStmt);
pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
return (SNode*)pStmt;
}
SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SNode* pQuery) {
CHECK_PARSER_STATUS(pCxt);
if (!checkTopicName(pCxt, pTopicName)) {
......
......@@ -5431,6 +5431,29 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt
return buildCmdMsg(pCxt, TDMT_MND_CONFIG_DNODE, (FSerializeFunc)tSerializeSMCfgDnodeReq, &cfgReq);
}
static int32_t translateRestoreDnode(STranslateContext* pCxt, SRestoreComponentNodeStmt* pStmt) {
SRestoreDnodeReq restoreReq = {0};
restoreReq.dnodeId = pStmt->dnodeId;
switch (nodeType((SNode*)pStmt)) {
case QUERY_NODE_RESTORE_DNODE_STMT:
restoreReq.restoreType = RESTORE_TYPE__ALL;
break;
case QUERY_NODE_RESTORE_QNODE_STMT:
restoreReq.restoreType = RESTORE_TYPE__QNODE;
break;
case QUERY_NODE_RESTORE_MNODE_STMT:
restoreReq.restoreType = RESTORE_TYPE__MNODE;
break;
case QUERY_NODE_RESTORE_VNODE_STMT:
restoreReq.restoreType = RESTORE_TYPE__VNODE;
break;
default:
return -1;
}
return buildCmdMsg(pCxt, TDMT_MND_RESTORE_DNODE, (FSerializeFunc)tSerializeSRestoreDnodeReq, &restoreReq);
}
static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
int32_t* pVgId) {
SVgroupInfo vg = {0};
......@@ -6916,6 +6939,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
code = translateShowCreateTable(pCxt, (SShowCreateTableStmt*)pNode);
break;
case QUERY_NODE_RESTORE_DNODE_STMT:
case QUERY_NODE_RESTORE_QNODE_STMT:
case QUERY_NODE_RESTORE_MNODE_STMT:
case QUERY_NODE_RESTORE_VNODE_STMT:
code = translateRestoreDnode(pCxt, (SRestoreComponentNodeStmt*)pNode);
break;
default:
break;
}
......
此差异已折叠。
......@@ -92,6 +92,62 @@ TEST_F(ParserInitialATest, alterDnode) {
clearCfgDnodeReq();
}
TEST_F(ParserInitialATest, restoreDnode) {
useDb("root", "test");
SRestoreDnodeReq expect = {0};
auto clearRestoreDnodeReq = [&]() { memset(&expect, 0, sizeof(SRestoreDnodeReq)); };
auto setRestoreDnodeReq = [&](int32_t dnodeId, int8_t type) {
expect.dnodeId = dnodeId;
expect.restoreType = type;
};
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
int32_t expectNodeType = 0;
switch (expect.restoreType) {
case RESTORE_TYPE__ALL:
expectNodeType = QUERY_NODE_RESTORE_DNODE_STMT;
break;
case RESTORE_TYPE__MNODE:
expectNodeType = QUERY_NODE_RESTORE_MNODE_STMT;
break;
case RESTORE_TYPE__VNODE:
expectNodeType = QUERY_NODE_RESTORE_VNODE_STMT;
break;
case RESTORE_TYPE__QNODE:
expectNodeType = QUERY_NODE_RESTORE_QNODE_STMT;
break;
default:
break;
}
ASSERT_EQ(nodeType(pQuery->pRoot), expectNodeType);
ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_RESTORE_DNODE);
SRestoreDnodeReq req = {0};
ASSERT_EQ(tDeserializeSRestoreDnodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
ASSERT_EQ(req.dnodeId, expect.dnodeId);
ASSERT_EQ(req.restoreType, expect.restoreType);
});
setRestoreDnodeReq(1, RESTORE_TYPE__ALL);
run("RESTORE DNODE 1");
clearRestoreDnodeReq();
setRestoreDnodeReq(2, RESTORE_TYPE__MNODE);
run("RESTORE MNODE ON DNODE 2");
clearRestoreDnodeReq();
setRestoreDnodeReq(1, RESTORE_TYPE__VNODE);
run("RESTORE VNODE ON DNODE 1");
clearRestoreDnodeReq();
setRestoreDnodeReq(2, RESTORE_TYPE__QNODE);
run("RESTORE QNODE ON DNODE 2");
clearRestoreDnodeReq();
}
/*
* ALTER DATABASE db_name [alter_database_options]
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册