Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
72ebd995
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
72ebd995
编写于
5月 11, 2023
作者:
W
wade zhang
提交者:
GitHub
5月 11, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21247 from taosdata/feat/restore-dnode
Feat/restore dnode
上级
55fc4079
06d94f6c
变更
31
展开全部
显示空白变更内容
内联
并排
Showing
31 changed file
with
5245 addition
and
4069 deletion
+5245
-4069
include/common/tmsg.h
include/common/tmsg.h
+15
-0
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
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
include/libs/tfs/tfs.h
include/libs/tfs/tfs.h
+10
-0
include/util/taoserror.h
include/util/taoserror.h
+2
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+27
-0
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+1
-0
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+18
-2
source/dnode/mgmt/node_mgmt/src/dmEnv.c
source/dnode/mgmt/node_mgmt/src/dmEnv.c
+1
-0
source/dnode/mnode/impl/CMakeLists.txt
source/dnode/mnode/impl/CMakeLists.txt
+1
-0
source/dnode/mnode/impl/inc/mndMnode.h
source/dnode/mnode/impl/inc/mndMnode.h
+4
-0
source/dnode/mnode/impl/inc/mndQnode.h
source/dnode/mnode/impl/inc/mndQnode.h
+3
-0
source/dnode/mnode/impl/inc/mndVgroup.h
source/dnode/mnode/impl/inc/mndVgroup.h
+3
-0
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+19
-0
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+107
-1
source/dnode/mnode/impl/src/mndQnode.c
source/dnode/mnode/impl/src/mndQnode.c
+6
-2
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+101
-0
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/parAst.h
source/libs/parser/inc/parAst.h
+1
-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/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+2
-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
+1
-1
source/libs/parser/test/parExplainToSyncdbTest.cpp
source/libs/parser/test/parExplainToSyncdbTest.cpp
+57
-0
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+8
-0
source/util/src/terror.c
source/util/src/terror.c
+6
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
72ebd995
...
...
@@ -1625,6 +1625,21 @@ typedef struct {
int32_t
tSerializeSDropDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SDropDnodeReq
*
pReq
);
int32_t
tDeserializeSDropDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SDropDnodeReq
*
pReq
);
enum
{
RESTORE_TYPE__ALL
=
1
,
RESTORE_TYPE__MNODE
,
RESTORE_TYPE__VNODE
,
RESTORE_TYPE__QNODE
,
};
typedef
struct
{
int32_t
dnodeId
;
int8_t
restoreType
;
}
SRestoreDnodeReq
;
int32_t
tSerializeSRestoreDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SRestoreDnodeReq
*
pReq
);
int32_t
tDeserializeSRestoreDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SRestoreDnodeReq
*
pReq
);
typedef
struct
{
int32_t
dnodeId
;
char
config
[
TSDB_DNODE_CONFIG_LEN
];
...
...
include/common/tmsgdef.h
浏览文件 @
72ebd995
...
...
@@ -178,6 +178,7 @@ enum {
// TD_DEF_MSG_TYPE(TDMT_MND_STREAM_BEGIN_CHECKPOINT, "stream-begin-checkpoint", NULL, NULL)
TD_DEF_MSG_TYPE
(
TDMT_MND_MAX_MSG
,
"mnd-max"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_BALANCE_VGROUP_LEADER
,
"balance-vgroup-leader"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_RESTORE_DNODE
,
"restore-dnode"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_VND_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBMIT
,
"submit"
,
SSubmitReq
,
SSubmitRsp
)
...
...
include/common/ttokendef.h
浏览文件 @
72ebd995
此差异已折叠。
点击以展开。
include/libs/nodes/cmdnodes.h
浏览文件 @
72ebd995
...
...
@@ -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
浏览文件 @
72ebd995
...
...
@@ -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
,
...
...
include/libs/tfs/tfs.h
浏览文件 @
72ebd995
...
...
@@ -133,6 +133,16 @@ int32_t tfsMkdirAt(STfs *pTfs, const char *rname, SDiskID diskId);
*/
int32_t
tfsMkdirRecurAt
(
STfs
*
pTfs
,
const
char
*
rname
,
SDiskID
diskId
);
/**
* @brief check directories exist in tfs.
*
* @param pTfs The fs object.
* @param rname The rel name of directory.
* @param diskId The disk ID.
* @return true for exist, false for not exist.
*/
bool
tfsDirExistAt
(
STfs
*
pTfs
,
const
char
*
rname
,
SDiskID
diskId
);
/**
* @brief Remove directory at all levels in tfs.
*
...
...
include/util/taoserror.h
浏览文件 @
72ebd995
...
...
@@ -406,6 +406,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0411)
#define TSDB_CODE_MNODE_NOT_CATCH_UP TAOS_DEF_ERROR_CODE(0, 0x0412) // internal
#define TSDB_CODE_MNODE_ALREADY_IS_VOTER TAOS_DEF_ERROR_CODE(0, 0x0413) // internal
#define TSDB_CODE_MNODE_ONLY_TWO_MNODE TAOS_DEF_ERROR_CODE(0, 0x0414) // internal
// vnode
// #define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) // 2.x
...
...
@@ -442,6 +443,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_VND_QUERY_BUSY TAOS_DEF_ERROR_CODE(0, 0x0531)
#define TSDB_CODE_VND_NOT_CATCH_UP TAOS_DEF_ERROR_CODE(0, 0x0532) // internal
#define TSDB_CODE_VND_ALREADY_IS_VOTER TAOS_DEF_ERROR_CODE(0, 0x0533) // internal
#define TSDB_CODE_VND_DIR_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0534)
// tsdb
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
...
...
source/common/src/tmsg.c
浏览文件 @
72ebd995
...
...
@@ -1720,6 +1720,33 @@ int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq
return
0
;
}
int32_t
tSerializeSRestoreDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SRestoreDnodeReq
*
pReq
)
{
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
dnodeId
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
restoreType
)
<
0
)
return
-
1
;
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
tEncoderClear
(
&
encoder
);
return
tlen
;
}
int32_t
tDeserializeSRestoreDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SRestoreDnodeReq
*
pReq
)
{
SDecoder
decoder
=
{
0
};
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
dnodeId
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
restoreType
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
return
0
;
}
int32_t
tSerializeSMCfgDnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SMCfgDnodeReq
*
pReq
)
{
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
...
...
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
浏览文件 @
72ebd995
...
...
@@ -174,6 +174,7 @@ SArray *mmGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_SERVER_VERSION
,
mmPutMsgToReadQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_CREATE_INDEX
,
mmPutMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_DROP_INDEX
,
mmPutMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_RESTORE_DNODE
,
mmPutMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SCH_QUERY
,
mmPutMsgToQueryQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SCH_MERGE_QUERY
,
mmPutMsgToQueryQueue
,
1
)
==
NULL
)
goto
_OVER
;
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
72ebd995
...
...
@@ -255,7 +255,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
SVnodeObj
*
pVnode
=
vmAcquireVnode
(
pMgmt
,
req
.
vgId
);
if
(
pVnode
!=
NULL
)
{
d
Info
(
"vgId:%d, already exist"
,
req
.
vgId
);
d
Error
(
"vgId:%d, already exist"
,
req
.
vgId
);
tFreeSCreateVnodeReq
(
&
req
);
vmReleaseVnode
(
pMgmt
,
pVnode
);
terrno
=
TSDB_CODE_VND_ALREADY_EXIST
;
...
...
@@ -264,7 +264,22 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
}
snprintf
(
path
,
TSDB_FILENAME_LEN
,
"vnode%svnode%d"
,
TD_DIRSEP
,
vnodeCfg
.
vgId
);
if
(
vnodeCreate
(
path
,
&
vnodeCfg
,
pMgmt
->
pTfs
)
<
0
)
{
if
(
pMgmt
->
pTfs
)
{
if
(
tfsDirExistAt
(
pMgmt
->
pTfs
,
path
,
(
SDiskID
){
0
}))
{
terrno
=
TSDB_CODE_VND_DIR_ALREADY_EXIST
;
dError
(
"vgId:%d, failed to restore vnode since %s"
,
req
.
vgId
,
terrstr
());
return
-
1
;
}
}
else
{
if
(
taosDirExist
(
path
))
{
terrno
=
TSDB_CODE_VND_DIR_ALREADY_EXIST
;
dError
(
"vgId:%d, failed to restore vnode since %s"
,
req
.
vgId
,
terrstr
());
return
-
1
;
}
}
if
(
vnodeCreate
(
path
,
&
vnodeCfg
,
pMgmt
->
pTfs
)
<
0
)
{
tFreeSCreateVnodeReq
(
&
req
);
dError
(
"vgId:%d, failed to create vnode since %s"
,
req
.
vgId
,
terrstr
());
code
=
terrno
;
...
...
@@ -344,6 +359,7 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
ESyncRole
role
=
vnodeGetRole
(
pVnode
->
pImpl
);
dInfo
(
"vgId:%d, checking node role:%d"
,
req
.
vgId
,
role
);
if
(
role
==
TAOS_SYNC_ROLE_VOTER
){
dError
(
"vgId:%d, failed to alter vnode type since node already is role:%d"
,
req
.
vgId
,
role
);
terrno
=
TSDB_CODE_VND_ALREADY_IS_VOTER
;
vmReleaseVnode
(
pMgmt
,
pVnode
);
return
-
1
;
...
...
source/dnode/mgmt/node_mgmt/src/dmEnv.c
浏览文件 @
72ebd995
...
...
@@ -218,6 +218,7 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
ESyncRole
role
=
(
*
pWrapper
->
func
.
nodeRoleFp
)(
pWrapper
->
pMgmt
);
dInfo
(
"node:%s, checking node role:%d"
,
pWrapper
->
name
,
role
);
if
(
role
==
TAOS_SYNC_ROLE_VOTER
){
dError
(
"node:%s, failed to alter node type since node already is role:%d"
,
pWrapper
->
name
,
role
);
terrno
=
TSDB_CODE_MNODE_ALREADY_IS_VOTER
;
return
-
1
;
}
...
...
source/dnode/mnode/impl/CMakeLists.txt
浏览文件 @
72ebd995
...
...
@@ -6,6 +6,7 @@ IF (TD_ENTERPRISE)
LIST
(
APPEND MNODE_SRC
${
TD_ENTERPRISE_DIR
}
/src/plugins/privilege/src/privilege.c
)
LIST
(
APPEND MNODE_SRC
${
TD_ENTERPRISE_DIR
}
/src/plugins/mnode/src/mndDb.c
)
LIST
(
APPEND MNODE_SRC
${
TD_ENTERPRISE_DIR
}
/src/plugins/mnode/src/mndVgroup.c
)
LIST
(
APPEND MNODE_SRC
${
TD_ENTERPRISE_DIR
}
/src/plugins/mnode/src/mndDnode.c
)
ENDIF
()
add_library
(
mnode STATIC
${
MNODE_SRC
}
)
...
...
source/dnode/mnode/impl/inc/mndMnode.h
浏览文件 @
72ebd995
...
...
@@ -29,6 +29,10 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj);
bool
mndIsMnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
void
mndGetMnodeEpSet
(
SMnode
*
pMnode
,
SEpSet
*
pEpSet
);
int32_t
mndSetDropMnodeInfoToTrans
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
,
bool
force
);
int32_t
mndSetRestoreCreateMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
);
int32_t
mndSetCreateMnodeCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
);
int32_t
mndSetRestoreAlterMnodeTypeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
);
int32_t
mndSetRestoreCreateMnodeRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/inc/mndQnode.h
浏览文件 @
72ebd995
...
...
@@ -30,6 +30,9 @@ SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId);
void
mndReleaseQnode
(
SMnode
*
pMnode
,
SQnodeObj
*
pObj
);
int32_t
mndCreateQnodeList
(
SMnode
*
pMnode
,
SArray
**
pList
,
int32_t
limit
);
int32_t
mndSetDropQnodeInfoToTrans
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SQnodeObj
*
pObj
,
bool
force
);
bool
mndQnodeInDnode
(
SQnodeObj
*
pQnode
,
int32_t
dnodeId
);
int32_t
mndSetCreateQnodeCommitLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
);
int32_t
mndSetCreateQnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SQnodeObj
*
pObj
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/inc/mndVgroup.h
浏览文件 @
72ebd995
...
...
@@ -49,6 +49,9 @@ int32_t mndBuildCompactVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
void
*
mndBuildCreateVnodeReq
(
SMnode
*
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
int32_t
*
pContLen
);
void
*
mndBuildDropVnodeReq
(
SMnode
*
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
int32_t
*
pContLen
);
bool
mndVgroupInDb
(
SVgObj
*
pVgroup
,
int64_t
dbUid
);
bool
mndVgroupInDnode
(
SVgObj
*
pVgroup
,
int32_t
dnodeId
);
int32_t
mndBuildRestoreAlterVgroupAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
db
,
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
);
int32_t
mndSplitVgroup
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
...
...
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
72ebd995
...
...
@@ -58,6 +58,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq);
static
int32_t
mndProcessConfigDnodeReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessConfigDnodeRsp
(
SRpcMsg
*
pRsp
);
static
int32_t
mndProcessStatusReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessRestoreDnodeReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndRetrieveConfigs
(
SRpcMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
);
static
void
mndCancelGetNextConfig
(
SMnode
*
pMnode
,
void
*
pIter
);
...
...
@@ -83,6 +84,7 @@ int32_t mndInitDnode(SMnode *pMnode) {
mndSetMsgHandle
(
pMnode
,
TDMT_MND_STATUS
,
mndProcessStatusReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DNODE_LIST
,
mndProcessDnodeListReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_SHOW_VARIABLES
,
mndProcessShowVariablesReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_RESTORE_DNODE
,
mndProcessRestoreDnodeReq
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_CONFIGS
,
mndRetrieveConfigs
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_CONFIGS
,
mndCancelGetNextConfig
);
...
...
@@ -294,6 +296,11 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
return
sdbGetSize
(
pSdb
,
SDB_DNODE
);
}
int32_t
mndGetDbSize
(
SMnode
*
pMnode
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbGetSize
(
pSdb
,
SDB_DB
);
}
bool
mndIsDnodeOnline
(
SDnodeObj
*
pDnode
,
int64_t
curMs
)
{
int64_t
interval
=
TABS
(
pDnode
->
lastAccessTime
-
curMs
);
if
(
interval
>
5000
*
(
int64_t
)
tsStatusInterval
)
{
...
...
@@ -745,6 +752,18 @@ _OVER:
return
code
;
}
extern
int32_t
mndProcessRestoreDnodeReqImpl
(
SRpcMsg
*
pReq
);
int32_t
mndProcessRestoreDnodeReq
(
SRpcMsg
*
pReq
){
return
mndProcessRestoreDnodeReqImpl
(
pReq
);
}
#ifndef TD_ENTERPRISE
int32_t
mndProcessRestoreDnodeReqImpl
(
SRpcMsg
*
pReq
){
return
0
;
}
#endif
static
int32_t
mndDropDnode
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pMObj
,
SQnodeObj
*
pQObj
,
SSnodeObj
*
pSObj
,
int32_t
numOfVnodes
,
bool
force
)
{
int32_t
code
=
-
1
;
...
...
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
72ebd995
...
...
@@ -275,6 +275,14 @@ static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeO
return
0
;
}
int32_t
mndSetRestoreCreateMnodeRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndMnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateMnodeUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
SSdbRaw
*
pUndoRaw
=
mndMnodeActionEncode
(
pObj
);
if
(
pUndoRaw
==
NULL
)
return
-
1
;
...
...
@@ -283,7 +291,7 @@ static int32_t mndSetCreateMnodeUndoLogs(SMnode *pMnode, STrans *pTrans, SMnodeO
return
0
;
}
static
int32_t
mndSetCreateMnodeCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
int32_t
mndSetCreateMnodeCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndMnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
...
...
@@ -421,6 +429,55 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
return
0
;
}
int32_t
mndSetRestoreCreateMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
SDCreateMnodeReq
createReq
=
{
0
};
SEpSet
createEpset
=
{
0
};
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
if
(
pMObj
->
id
==
pDnode
->
id
)
{
sdbRelease
(
pSdb
,
pMObj
);
continue
;
}
if
(
pMObj
->
role
==
TAOS_SYNC_ROLE_VOTER
){
createReq
.
replicas
[
createReq
.
replica
].
id
=
pMObj
->
id
;
createReq
.
replicas
[
createReq
.
replica
].
port
=
pMObj
->
pDnode
->
port
;
memcpy
(
createReq
.
replicas
[
createReq
.
replica
].
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
createReq
.
replica
++
;
}
else
{
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
id
=
pMObj
->
id
;
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
port
=
pMObj
->
pDnode
->
port
;
memcpy
(
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
createReq
.
learnerReplica
++
;
}
sdbRelease
(
pSdb
,
pMObj
);
}
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
id
=
pDnode
->
id
;
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
port
=
pDnode
->
port
;
memcpy
(
createReq
.
learnerReplicas
[
createReq
.
learnerReplica
].
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
createReq
.
learnerReplica
++
;
createReq
.
lastIndex
=
pObj
->
lastIndex
;
createEpset
.
inUse
=
0
;
createEpset
.
numOfEps
=
1
;
createEpset
.
eps
[
0
].
port
=
pDnode
->
port
;
memcpy
(
createEpset
.
eps
[
0
].
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
if
(
mndBuildCreateMnodeRedoAction
(
pTrans
,
&
createReq
,
&
createEpset
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetAlterMnodeTypeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
...
...
@@ -465,6 +522,55 @@ static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, S
return
0
;
}
int32_t
mndSetRestoreAlterMnodeTypeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
SDAlterMnodeTypeReq
alterReq
=
{
0
};
SEpSet
createEpset
=
{
0
};
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
if
(
pMObj
->
id
==
pDnode
->
id
)
{
sdbRelease
(
pSdb
,
pMObj
);
continue
;
}
if
(
pMObj
->
role
==
TAOS_SYNC_ROLE_VOTER
){
alterReq
.
replicas
[
alterReq
.
replica
].
id
=
pMObj
->
id
;
alterReq
.
replicas
[
alterReq
.
replica
].
port
=
pMObj
->
pDnode
->
port
;
memcpy
(
alterReq
.
replicas
[
alterReq
.
replica
].
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
alterReq
.
replica
++
;
}
else
{
alterReq
.
learnerReplicas
[
alterReq
.
learnerReplica
].
id
=
pMObj
->
id
;
alterReq
.
learnerReplicas
[
alterReq
.
learnerReplica
].
port
=
pMObj
->
pDnode
->
port
;
memcpy
(
alterReq
.
learnerReplicas
[
alterReq
.
learnerReplica
].
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
alterReq
.
learnerReplica
++
;
}
sdbRelease
(
pSdb
,
pMObj
);
}
alterReq
.
replicas
[
alterReq
.
replica
].
id
=
pDnode
->
id
;
alterReq
.
replicas
[
alterReq
.
replica
].
port
=
pDnode
->
port
;
memcpy
(
alterReq
.
replicas
[
alterReq
.
replica
].
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
alterReq
.
replica
++
;
alterReq
.
lastIndex
=
pObj
->
lastIndex
;
createEpset
.
inUse
=
0
;
createEpset
.
numOfEps
=
1
;
createEpset
.
eps
[
0
].
port
=
pDnode
->
port
;
memcpy
(
createEpset
.
eps
[
0
].
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
if
(
mndBuildAlterMnodeTypeRedoAction
(
pTrans
,
&
alterReq
,
&
createEpset
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDnodeObj
*
pDnode
,
SMCreateMnodeReq
*
pCreate
)
{
int32_t
code
=
-
1
;
...
...
source/dnode/mnode/impl/src/mndQnode.c
浏览文件 @
72ebd995
...
...
@@ -180,7 +180,7 @@ static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) {
return
0
;
}
static
int32_t
mndSetCreateQnodeCommitLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
int32_t
mndSetCreateQnodeCommitLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndQnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
...
...
@@ -188,7 +188,11 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
return
0
;
}
static
int32_t
mndSetCreateQnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SQnodeObj
*
pObj
)
{
bool
mndQnodeInDnode
(
SQnodeObj
*
pQnode
,
int32_t
dnodeId
)
{
return
pQnode
->
pDnode
->
id
==
dnodeId
;
}
int32_t
mndSetCreateQnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SQnodeObj
*
pObj
)
{
SDCreateQnodeReq
createReq
=
{
0
};
createReq
.
dnodeId
=
pDnode
->
id
;
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
72ebd995
...
...
@@ -1155,6 +1155,28 @@ int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg
return
0
;
}
int32_t
mndRestoreAddCreateVnodeAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
)
{
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildCreateVnodeReq
(
pMnode
,
pDnode
,
pDb
,
pVgroup
,
&
contLen
);
if
(
pReq
==
NULL
)
return
-
1
;
action
.
pCont
=
pReq
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_DND_CREATE_VNODE
;
action
.
acceptableCode
=
TSDB_CODE_VND_ALREADY_EXIST
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
pReq
);
return
-
1
;
}
return
0
;
}
int32_t
mndAddAlterVnodeConfirmAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
...
...
@@ -1274,6 +1296,29 @@ int32_t mndAddAlterVnodeTypeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
return
0
;
}
int32_t
mndRestoreAddAlterVnodeTypeAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
)
{
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildAlterVnodeReplicaReq
(
pMnode
,
pDb
,
pVgroup
,
pDnode
->
id
,
&
contLen
);
if
(
pReq
==
NULL
)
return
-
1
;
action
.
pCont
=
pReq
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_DND_ALTER_VNODE_TYPE
;
action
.
acceptableCode
=
TSDB_CODE_VND_ALREADY_IS_VOTER
;
action
.
retryCode
=
TSDB_CODE_VND_NOT_CATCH_UP
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
pReq
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndAddDisableVnodeWriteAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
int32_t
dnodeId
)
{
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
dnodeId
);
...
...
@@ -2113,6 +2158,55 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
return
0
;
}
int32_t
mndBuildRestoreAlterVgroupAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
db
,
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
)
{
SVgObj
newVgroup
=
{
0
};
memcpy
(
&
newVgroup
,
pVgroup
,
sizeof
(
SVgObj
));
mInfo
(
"db:%s, vgId:%d, restore vnodes, vn:0 dnode:%d"
,
pVgroup
->
dbName
,
pVgroup
->
vgId
,
pVgroup
->
vnodeGid
[
0
].
dnodeId
);
if
(
newVgroup
.
replica
==
1
){
int
selected
=
0
;
for
(
int
i
=
0
;
i
<
newVgroup
.
replica
;
i
++
){
newVgroup
.
vnodeGid
[
i
].
nodeRole
=
TAOS_SYNC_ROLE_VOTER
;
if
(
newVgroup
.
vnodeGid
[
i
].
dnodeId
==
pDnode
->
id
){
selected
=
i
;
}
}
if
(
mndAddCreateVnodeAction
(
pMnode
,
pTrans
,
db
,
&
newVgroup
,
&
newVgroup
.
vnodeGid
[
selected
])
!=
0
)
return
-
1
;
}
else
if
(
newVgroup
.
replica
==
3
){
for
(
int
i
=
0
;
i
<
newVgroup
.
replica
;
i
++
){
if
(
newVgroup
.
vnodeGid
[
i
].
dnodeId
==
pDnode
->
id
){
newVgroup
.
vnodeGid
[
i
].
nodeRole
=
TAOS_SYNC_ROLE_LEARNER
;
}
else
{
newVgroup
.
vnodeGid
[
i
].
nodeRole
=
TAOS_SYNC_ROLE_VOTER
;
}
}
if
(
mndRestoreAddCreateVnodeAction
(
pMnode
,
pTrans
,
db
,
&
newVgroup
,
pDnode
)
!=
0
)
return
-
1
;
for
(
int
i
=
0
;
i
<
newVgroup
.
replica
;
i
++
){
newVgroup
.
vnodeGid
[
i
].
nodeRole
=
TAOS_SYNC_ROLE_VOTER
;
if
(
newVgroup
.
vnodeGid
[
i
].
dnodeId
==
pDnode
->
id
){
}
}
if
(
mndRestoreAddAlterVnodeTypeAction
(
pMnode
,
pTrans
,
db
,
&
newVgroup
,
pDnode
)
!=
0
)
return
-
1
;
}
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
&
newVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
{
sdbFreeRaw
(
pVgRaw
);
return
-
1
;
}
(
void
)
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
);
return
0
;
}
static
int32_t
mndAddAdjustVnodeHashRangeAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
return
0
;
}
...
...
@@ -2437,6 +2531,13 @@ _OVER:
bool
mndVgroupInDb
(
SVgObj
*
pVgroup
,
int64_t
dbUid
)
{
return
!
pVgroup
->
isTsma
&&
pVgroup
->
dbUid
==
dbUid
;
}
bool
mndVgroupInDnode
(
SVgObj
*
pVgroup
,
int32_t
dnodeId
)
{
for
(
int
i
=
0
;
i
<
pVgroup
->
replica
;
i
++
){
if
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
==
dnodeId
)
return
true
;
}
return
false
;
}
static
void
*
mndBuildCompactVnodeReq
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
,
int32_t
*
pContLen
,
int64_t
compactTs
,
STimeWindow
tw
)
{
SCompactVnodeReq
compactReq
=
{
0
};
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
72ebd995
...
...
@@ -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
浏览文件 @
72ebd995
...
...
@@ -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/parAst.h
浏览文件 @
72ebd995
...
...
@@ -202,6 +202,7 @@ SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInt
SNode
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pIndexName
);
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createRestoreComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createCreateTopicStmtUseQuery
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pTopicName
,
SNode
*
pQuery
);
SNode
*
createCreateTopicStmtUseDb
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pTopicName
,
SToken
*
pSubDbName
,
bool
withMeta
);
...
...
source/libs/parser/inc/sql.y
100644 → 100755
浏览文件 @
72ebd995
...
...
@@ -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
浏览文件 @
72ebd995
...
...
@@ -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/parTokenizer.c
浏览文件 @
72ebd995
...
...
@@ -181,6 +181,7 @@ static SKeyword keywordTable[] = {
{
"REPLACE"
,
TK_REPLACE
},
{
"REPLICA"
,
TK_REPLICA
},
{
"RESET"
,
TK_RESET
},
{
"RESTORE"
,
TK_RESTORE
},
{
"RETENTIONS"
,
TK_RETENTIONS
},
{
"REVOKE"
,
TK_REVOKE
},
{
"ROLLUP"
,
TK_ROLLUP
},
...
...
@@ -252,6 +253,7 @@ static SKeyword keywordTable[] = {
{
"VERBOSE"
,
TK_VERBOSE
},
{
"VGROUP"
,
TK_VGROUP
},
{
"VGROUPS"
,
TK_VGROUPS
},
{
"VNODE"
,
TK_VNODE
},
{
"VNODES"
,
TK_VNODES
},
{
"WAL_FSYNC_PERIOD"
,
TK_WAL_FSYNC_PERIOD
},
{
"WAL_LEVEL"
,
TK_WAL_LEVEL
},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
72ebd995
...
...
@@ -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
浏览文件 @
72ebd995
此差异已折叠。
点击以展开。
source/libs/parser/test/parAlterToBalanceTest.cpp
浏览文件 @
72ebd995
source/libs/parser/test/parExplainToSyncdbTest.cpp
浏览文件 @
72ebd995
...
...
@@ -133,6 +133,63 @@ TEST_F(ParserExplainToSyncdbTest, redistributeVgroup) {
run
(
"REDISTRIBUTE VGROUP 5 DNODE 10 DNODE 20 DNODE 30"
);
}
TEST_F
(
ParserExplainToSyncdbTest
,
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
();
}
// todo reset query cache
TEST_F
(
ParserExplainToSyncdbTest
,
revoke
)
{
...
...
source/libs/tfs/src/tfs.c
浏览文件 @
72ebd995
...
...
@@ -283,6 +283,14 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) {
return
0
;
}
bool
tfsDirExistAt
(
STfs
*
pTfs
,
const
char
*
rname
,
SDiskID
diskId
)
{
STfsDisk
*
pDisk
=
TFS_DISK_AT
(
pTfs
,
diskId
);
char
aname
[
TMPNAME_LEN
];
snprintf
(
aname
,
TMPNAME_LEN
,
"%s%s%s"
,
pDisk
->
path
,
TD_DIRSEP
,
rname
);
return
taosDirExist
(
aname
);
}
int32_t
tfsRmdir
(
STfs
*
pTfs
,
const
char
*
rname
)
{
if
(
rname
[
0
]
==
0
)
{
return
0
;
...
...
source/util/src/terror.c
浏览文件 @
72ebd995
...
...
@@ -320,6 +320,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QNODE_NOT_DEPLOYED, "Qnode not deployed")
TAOS_DEFINE_ERROR
(
TSDB_CODE_SNODE_NOT_FOUND
,
"Snode not found"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SNODE_ALREADY_DEPLOYED
,
"Snode already deployed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SNODE_NOT_DEPLOYED
,
"Snode not deployed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MNODE_NOT_CATCH_UP
,
"Mnode didn't catch the leader"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MNODE_ALREADY_IS_VOTER
,
"Mnode already is a leader"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MNODE_ONLY_TWO_MNODE
,
"Only two mnodes exist"
)
// vnode
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_INVALID_VGROUP_ID
,
"Vnode is closed or removed"
)
...
...
@@ -335,6 +338,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_AVAIL_BUFPOOL, "No availabe buffer po
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_STOPPED
,
"Vnode stopped"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_DUP_REQUEST
,
"Duplicate write request"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_QUERY_BUSY
,
"Query busy"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_NOT_CATCH_UP
,
"Vnode didn't catch up its leader"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_ALREADY_IS_VOTER
,
"Vnode already is a voter"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_DIR_ALREADY_EXIST
,
"Vnode directory already exist"
)
// tsdb
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_TABLE_ID
,
"Invalid table ID"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录