Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a8c65cd2
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a8c65cd2
编写于
5月 09, 2023
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support restore dnode clause
上级
843d6060
变更
12
展开全部
显示空白变更内容
内联
并排
Showing
12 changed file
with
4908 addition
and
4070 deletion
+4908
-4070
include/common/tmsg.h
include/common/tmsg.h
+0
-2
include/common/ttokendef.h
include/common/ttokendef.h
+332
-329
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+5
-0
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+4
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+0
-4
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+45
-0
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+10
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+9
-3
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+8
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+29
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+4409
-3731
source/libs/parser/test/parAlterToBalanceTest.cpp
source/libs/parser/test/parAlterToBalanceTest.cpp
+57
-1
未找到文件。
include/common/tmsg.h
浏览文件 @
a8c65cd2
...
...
@@ -1634,8 +1634,6 @@ enum {
typedef
struct
{
int32_t
dnodeId
;
char
fqdn
[
TSDB_FQDN_LEN
];
int32_t
port
;
int8_t
restoreType
;
}
SRestoreDnodeReq
;
...
...
include/common/ttokendef.h
浏览文件 @
a8c65cd2
此差异已折叠。
点击以展开。
include/libs/nodes/cmdnodes.h
浏览文件 @
a8c65cd2
...
...
@@ -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
];
...
...
include/libs/nodes/nodes.h
浏览文件 @
a8c65cd2
...
...
@@ -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
,
...
...
source/common/src/tmsg.c
浏览文件 @
a8c65cd2
...
...
@@ -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
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
a8c65cd2
...
...
@@ -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
:
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
a8c65cd2
...
...
@@ -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
);
...
...
source/libs/parser/inc/sql.y
100644 → 100755
浏览文件 @
a8c65cd2
...
...
@@ -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); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
a8c65cd2
...
...
@@ -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
))
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
a8c65cd2
...
...
@@ -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
;
}
...
...
source/libs/parser/src/sql.c
浏览文件 @
a8c65cd2
此差异已折叠。
点击以展开。
source/libs/parser/test/parAlterToBalanceTest.cpp
浏览文件 @
a8c65cd2
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录