Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
c06fb4d9
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c06fb4d9
编写于
4月 02, 2020
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-17] add show mnodes command in cluster version
上级
61b2342b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
585 addition
and
110 deletion
+585
-110
cmake/define.inc
cmake/define.inc
+10
-3
src/mnode/inc/mgmtMnode.h
src/mnode/inc/mgmtMnode.h
+0
-3
src/mnode/src/mgmtBalance.c
src/mnode/src/mgmtBalance.c
+2
-1
src/mnode/src/mgmtDnode.c
src/mnode/src/mgmtDnode.c
+453
-2
src/mnode/src/mgmtMnode.c
src/mnode/src/mgmtMnode.c
+61
-101
src/mnode/src/mgmtVgroup.c
src/mnode/src/mgmtVgroup.c
+9
-0
src/util/inc/tstatus.h
src/util/inc/tstatus.h
+15
-0
src/util/src/.tqueue.c.swp
src/util/src/.tqueue.c.swp
+0
-0
src/util/src/tstatus.c
src/util/src/tstatus.c
+19
-0
tests/script/general/show/dnodes.sim
tests/script/general/show/dnodes.sim
+16
-0
未找到文件。
cmake/define.inc
浏览文件 @
c06fb4d9
...
...
@@ -3,10 +3,17 @@ PROJECT(TDengine)
IF
(
TD_CLUSTER
)
ADD_DEFINITIONS
(
-
D_CLUSTER
)
ADD_DEFINITIONS
(
-
DTSDB_REPLICA_MAX_NUM
=
1
)
ENDIF
()
IF
(
TD_MPEER
)
ADD_DEFINITIONS
(
-
D_MPEER
)
ENDIF
()
IF
(
TD_VPEER
)
ADD_DEFINITIONS
(
-
D_VPEER
)
ADD_DEFINITIONS
(
-
DTSDB_REPLICA_MAX_NUM
=
3
)
ELSE
()
ADD_DEFINITIONS
(
-
DLITE
)
ADD_DEFINITIONS
(
-
DTSDB_REPLICA_MAX_NUM
=
1
)
ADD_DEFINITIONS
(
-
DTSDB_REPLICA_MAX_NUM
=
1
)
ENDIF
()
IF
(
TD_ACCOUNT
)
...
...
src/mnode/inc/mgmtMnode.h
浏览文件 @
c06fb4d9
...
...
@@ -30,9 +30,6 @@ bool mgmtCheckRedirect(void *handle);
void
mgmtGetMnodePrivateIpList
(
SRpcIpSet
*
ipSet
);
void
mgmtGetMnodePublicIpList
(
SRpcIpSet
*
ipSet
);
int32_t
mgmtAddMnode
(
uint32_t
privateIp
,
uint32_t
publicIp
);
int32_t
mgmtRemoveMnode
(
uint32_t
privateIp
);
#ifdef __cplusplus
}
#endif
...
...
src/mnode/src/mgmtBalance.c
浏览文件 @
c06fb4d9
...
...
@@ -49,6 +49,7 @@ int32_t mgmtAllocVnodes(SVgObj *pVgroup) {
pVgroup
->
vnodeGid
[
0
].
dnodeId
=
pSelDnode
->
dnodeId
;
pVgroup
->
vnodeGid
[
0
].
privateIp
=
pSelDnode
->
privateIp
;
pVgroup
->
vnodeGid
[
0
].
publicIp
=
pSelDnode
->
publicIp
;
mTrace
(
"dnode:%d, alloc one vnode to vgroup"
,
pSelDnode
->
dnodeId
);
mTrace
(
"dnode:%d, alloc one vnode to vgroup, openVnodes:%d"
,
pSelDnode
->
dnodeId
,
pSelDnode
->
openVnodes
);
return
TSDB_CODE_SUCCESS
;
}
src/mnode/src/mgmtDnode.c
浏览文件 @
c06fb4d9
...
...
@@ -29,10 +29,19 @@
static
void
mgmtProcessCfgDnodeMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessCfgDnodeMsgRsp
(
SRpcMsg
*
rpcMsg
)
;
static
void
mgmtProcessDnodeStatusMsg
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mgmtGetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mgmtGetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mgmtGetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mgmtGetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
extern
int32_t
clusterInit
();
extern
void
clusterCleanUp
();
extern
int32_t
clusterGetDnodesNum
();
extern
void
*
clusterGetNextDnode
(
void
*
pNode
,
SDnodeObj
**
pDnode
);
extern
void
*
clusterGetNextDnode
(
void
*
pNode
,
void
**
pDnode
);
extern
SDnodeObj
*
clusterGetDnode
(
int32_t
dnodeId
);
extern
SDnodeObj
*
clusterGetDnodeByIp
(
uint32_t
ip
);
#ifndef _CLUSTER
...
...
@@ -43,7 +52,15 @@ int32_t mgmtInitDnodes() {
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CONFIG_DNODE
,
mgmtProcessCfgDnodeMsg
);
mgmtAddDClientRspHandle
(
TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP
,
mgmtProcessCfgDnodeMsgRsp
);
mgmtAddDServerMsgHandle
(
TSDB_MSG_TYPE_DM_STATUS
,
mgmtProcessDnodeStatusMsg
);
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_MODULE
,
mgmtGetModuleMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_MODULE
,
mgmtRetrieveModules
);
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_CONFIGS
,
mgmtGetConfigMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_CONFIGS
,
mgmtRetrieveConfigs
);
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_VNODES
,
mgmtGetVnodeMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_VNODES
,
mgmtRetrieveVnodes
);
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_DNODE
,
mgmtGetDnodeMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_DNODE
,
mgmtRetrieveDnodes
);
#ifdef _CLUSTER
return
clusterInit
();
#else
...
...
@@ -250,3 +267,437 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
rpcSendResponse
(
&
rpcRsp
);
}
static
int32_t
mgmtGetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pConn
,
NULL
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"private ip"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"public ip"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
10
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"open vnodes"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"total vnodes"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
#ifdef _VPEER
pShow
->
bytes
[
cols
]
=
18
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"balance"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
#endif
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
mgmtGetDnodesNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pNode
=
NULL
;
return
0
;
}
static
int32_t
mgmtRetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
char
ipstr
[
32
];
while
(
numOfRows
<
rows
)
{
pShow
->
pNode
=
mgmtGetNextDnode
(
pShow
->
pNode
,
(
SDnodeObj
**
)
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
dnodeId
;
cols
++
;
tinet_ntoa
(
ipstr
,
pDnode
->
privateIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
ipstr
);
cols
++
;
tinet_ntoa
(
ipstr
,
pDnode
->
publicIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
ipstr
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pDnode
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetDnodeStatusStr
(
pDnode
->
status
)
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
openVnodes
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
numOfTotalVnodes
;
cols
++
;
#ifdef _VPEER
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetDnodeLbStatusStr
(
pDnode
->
lbStatus
));
cols
++
;
#endif
numOfRows
++
;
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
bool
clusterCheckModuleInDnode
(
SDnodeObj
*
pDnode
,
int32_t
moduleType
)
{
uint32_t
status
=
pDnode
->
moduleStatus
&
(
1
<<
moduleType
);
return
status
>
0
;
}
static
int32_t
mgmtGetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pConn
,
NULL
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"IP"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
10
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"module type"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
10
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"module status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
while
(
1
)
{
pShow
->
pNode
=
mgmtGetNextDnode
(
pShow
->
pNode
,
(
SDnodeObj
**
)
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
for
(
int32_t
moduleType
=
0
;
moduleType
<
TSDB_MOD_MAX
;
++
moduleType
)
{
if
(
clusterCheckModuleInDnode
(
pDnode
,
moduleType
))
{
pShow
->
numOfRows
++
;
}
}
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pNode
=
NULL
;
return
0
;
}
int32_t
mgmtRetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
char
ipstr
[
20
];
while
(
numOfRows
<
rows
)
{
pShow
->
pNode
=
mgmtGetNextDnode
(
pShow
->
pNode
,
(
SDnodeObj
**
)
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
for
(
int32_t
moduleType
=
0
;
moduleType
<
TSDB_MOD_MAX
;
++
moduleType
)
{
if
(
!
clusterCheckModuleInDnode
(
pDnode
,
moduleType
))
{
continue
;
}
cols
=
0
;
tinet_ntoa
(
ipstr
,
pDnode
->
privateIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
ipstr
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
tsModule
[
moduleType
].
name
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetDnodeStatusStr
(
pDnode
->
status
)
);
cols
++
;
numOfRows
++
;
}
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
bool
clusterCheckConfigShow
(
SGlobalConfig
*
cfg
)
{
if
(
!
(
cfg
->
cfgType
&
TSDB_CFG_CTYPE_B_SHOW
))
return
false
;
return
true
;
}
static
int32_t
mgmtGetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pConn
,
NULL
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
TSDB_CFG_OPTION_LEN
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"config name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_CFG_VALUE_LEN
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"config value"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
pShow
->
numOfRows
=
0
;
for
(
int32_t
i
=
tsGlobalConfigNum
-
1
;
i
>=
0
;
--
i
)
{
SGlobalConfig
*
cfg
=
tsGlobalConfig
+
i
;
if
(
!
clusterCheckConfigShow
(
cfg
))
continue
;
pShow
->
numOfRows
++
;
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pNode
=
NULL
;
return
0
;
}
static
int32_t
mgmtRetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
for
(
int32_t
i
=
tsGlobalConfigNum
-
1
;
i
>=
0
&&
numOfRows
<
rows
;
--
i
)
{
SGlobalConfig
*
cfg
=
tsGlobalConfig
+
i
;
if
(
!
clusterCheckConfigShow
(
cfg
))
continue
;
char
*
pWrite
;
int32_t
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
snprintf
(
pWrite
,
TSDB_CFG_OPTION_LEN
,
"%s"
,
cfg
->
option
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
switch
(
cfg
->
valType
)
{
case
TSDB_CFG_VTYPE_SHORT
:
snprintf
(
pWrite
,
TSDB_CFG_VALUE_LEN
,
"%d"
,
*
((
int16_t
*
)
cfg
->
ptr
));
numOfRows
++
;
break
;
case
TSDB_CFG_VTYPE_INT
:
snprintf
(
pWrite
,
TSDB_CFG_VALUE_LEN
,
"%d"
,
*
((
int32_t
*
)
cfg
->
ptr
));
numOfRows
++
;
break
;
case
TSDB_CFG_VTYPE_UINT
:
snprintf
(
pWrite
,
TSDB_CFG_VALUE_LEN
,
"%d"
,
*
((
uint32_t
*
)
cfg
->
ptr
));
numOfRows
++
;
break
;
case
TSDB_CFG_VTYPE_FLOAT
:
snprintf
(
pWrite
,
TSDB_CFG_VALUE_LEN
,
"%f"
,
*
((
float
*
)
cfg
->
ptr
));
numOfRows
++
;
break
;
case
TSDB_CFG_VTYPE_STRING
:
case
TSDB_CFG_VTYPE_IPSTR
:
case
TSDB_CFG_VTYPE_DIRECTORY
:
snprintf
(
pWrite
,
TSDB_CFG_VALUE_LEN
,
"%s"
,
(
char
*
)
cfg
->
ptr
);
numOfRows
++
;
break
;
default:
break
;
}
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
int32_t
mgmtGetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pConn
,
NULL
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"vnode"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
12
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
12
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"sync_status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
SDnodeObj
*
pDnode
=
NULL
;
if
(
pShow
->
payloadLen
>
0
)
{
uint32_t
ip
=
ip2uint
(
pShow
->
payload
);
pDnode
=
mgmtGetDnodeByIp
(
ip
);
if
(
NULL
==
pDnode
)
{
return
TSDB_CODE_NODE_OFFLINE
;
}
SVnodeLoad
*
pVnode
;
pShow
->
numOfRows
=
0
;
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_VNODES
;
i
++
)
{
pVnode
=
&
pDnode
->
vload
[
i
];
if
(
0
!=
pVnode
->
vgId
)
{
pShow
->
numOfRows
++
;
}
}
pShow
->
pNode
=
pDnode
;
}
else
{
while
(
true
)
{
pShow
->
pNode
=
mgmtGetNextDnode
(
pShow
->
pNode
,
(
SDnodeObj
**
)
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
pShow
->
numOfRows
+=
pDnode
->
openVnodes
;
if
(
0
==
pShow
->
numOfRows
)
return
TSDB_CODE_NODE_OFFLINE
;
}
pShow
->
pNode
=
NULL
;
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
return
0
;
}
static
int32_t
mgmtRetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
if
(
0
==
rows
)
return
0
;
if
(
pShow
->
payloadLen
)
{
// output the vnodes info of the designated dnode. And output all vnodes of this dnode, instead of rows (max 100)
pDnode
=
(
SDnodeObj
*
)(
pShow
->
pNode
);
if
(
pDnode
!=
NULL
)
{
SVnodeLoad
*
pVnode
;
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_VNODES
;
i
++
)
{
pVnode
=
&
pDnode
->
vload
[
i
];
if
(
0
==
pVnode
->
vgId
)
{
continue
;
}
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
uint32_t
*
)
pWrite
=
pVnode
->
vgId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetVnodeStatusStr
(
pVnode
->
status
));
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetVnodeSyncStatusStr
(
pVnode
->
syncStatus
));
cols
++
;
numOfRows
++
;
}
}
}
else
{
// TODO: output all vnodes of all dnodes
numOfRows
=
0
;
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
\ No newline at end of file
src/mnode/src/mgmtMnode.c
浏览文件 @
c06fb4d9
...
...
@@ -15,122 +15,82 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "tstatus.h"
#include "trpc.h"
#include "mgmtMnode.h"
#include "mgmtSdb.h"
#include "mgmtShell.h"
#include "mgmtUser.h"
int32_t
(
*
mpeerAddMnodeFp
)(
uint32_t
privateIp
,
uint32_t
publicIp
)
=
NULL
;
int32_t
(
*
mpeerRemoveMnodeFp
)(
uint32_t
privateIp
)
=
NULL
;
int32_t
(
*
mpeerGetMnodesNumFp
)()
=
NULL
;
void
*
(
*
mpeerGetNextMnodeFp
)(
SShowObj
*
pShow
,
SMnodeObj
**
pMnode
)
=
NULL
;
int32_t
(
*
mpeerInitMnodesFp
)()
=
NULL
;
void
(
*
mpeerCleanUpMnodesFp
)()
=
NULL
;
#ifndef _MPEER
static
SMnodeObj
tsMnodeObj
=
{
0
};
static
bool
tsMnodeIsMaster
=
false
;
static
bool
tsMnodeIsServing
=
false
;
static
int32_t
mgmtGetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
char
*
mgmtMnodeStatusStr
[]
=
{
"offline"
,
"unsynced"
,
"syncing"
,
"serving"
,
"null"
};
static
char
*
mgmtMnodeRoleStr
[]
=
{
"unauthed"
,
"undecided"
,
"master"
,
"slave"
,
"null"
};
int32_t
mgmtInitMnodes
()
{
if
(
mpeerInitMnodesFp
)
{
return
(
*
mpeerInitMnodesFp
)();
}
else
{
tsMnodeIsServing
=
true
;
tsMnodeIsMaster
=
true
;
return
0
;
}
}
void
mgmtCleanupMnodes
()
{
if
(
mpeerCleanUpMnodesFp
)
{
(
*
mpeerCleanUpMnodesFp
)();
}
}
bool
mgmtInServerStatus
()
{
return
tsMnodeIsServing
;
}
bool
mgmtIsMaster
()
{
return
tsMnodeIsMaster
;
}
bool
mgmtCheckRedirect
(
void
*
handle
)
{
return
false
;
}
int32_t
mgmtAddMnode
(
uint32_t
privateIp
,
uint32_t
publicIp
)
{
if
(
mpeerAddMnodeFp
)
{
return
(
*
mpeerAddMnodeFp
)(
privateIp
,
publicIp
);
}
else
{
return
0
;
}
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_MNODE
,
mgmtGetMnodeMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_MNODE
,
mgmtRetrieveMnodes
);
tsMnodeObj
.
mnodeId
=
1
;
tsMnodeObj
.
privateIp
=
inet_addr
(
tsPrivateIp
);
tsMnodeObj
.
publicIp
=
inet_addr
(
tsPublicIp
);
tsMnodeObj
.
createdTime
=
taosGetTimestampMs
();
tsMnodeObj
.
role
=
TSDB_MN_ROLE_MASTER
;
tsMnodeObj
.
status
=
TSDB_MN_STATUS_SERVING
;
tsMnodeObj
.
numOfMnodes
=
1
;
sprintf
(
tsMnodeObj
.
mnodeName
,
"%d"
,
tsMnodeObj
.
mnodeId
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtRemoveMnode
(
uint32_t
privateIp
)
{
if
(
mpeerRemoveMnodeFp
)
{
return
(
*
mpeerRemoveMnodeFp
)(
privateIp
);
}
else
{
return
0
;
}
}
void
mgmtCleanupMnodes
()
{}
bool
mgmtInServerStatus
()
{
return
tsMnodeObj
.
status
==
TSDB_MN_STATUS_SERVING
;
}
bool
mgmtIsMaster
()
{
return
tsMnodeObj
.
role
==
TSDB_MN_ROLE_MASTER
;
}
bool
mgmtCheckRedirect
(
void
*
handle
)
{
return
false
;
}
static
int32_t
mgmtGetMnodesNum
()
{
if
(
mpeerGetMnodesNumFp
)
{
return
(
*
mpeerGetMnodesNumFp
)();
}
else
{
return
1
;
}
return
1
;
}
static
void
*
mgmtGetNextMnode
(
SShowObj
*
pShow
,
SMnodeObj
**
pMnode
)
{
if
(
mpeerGetNextMnodeFp
)
{
return
(
*
mpeerGetNextMnodeFp
)(
pShow
,
pMnode
)
;
static
void
*
mgmtGetNextMnode
(
void
*
pNode
,
SMnodeObj
**
pMnode
)
{
if
(
*
pMnode
==
NULL
)
{
*
pMnode
=
&
tsMnodeObj
;
}
else
{
if
(
*
pMnode
==
NULL
)
{
*
pMnode
=
&
tsMnodeObj
;
}
else
{
*
pMnode
=
NULL
;
}
*
pMnode
=
NULL
;
}
return
*
pMnode
;
}
static
int32_t
mgmtGetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pConn
,
NULL
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"private ip"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"public ip"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
...
...
@@ -149,12 +109,6 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
16
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"public ip"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
...
...
@@ -163,7 +117,7 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
mgmtGet
M
nodesNum
();
pShow
->
numOfRows
=
mgmtGet
D
nodesNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pNode
=
NULL
;
...
...
@@ -171,38 +125,42 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
}
static
int32_t
mgmtRetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SMnodeObj
*
pMnode
=
NULL
;
char
*
pWrite
;
char
ipstr
[
32
];
char
*
pWrite
;
char
ipstr
[
32
];
while
(
numOfRows
<
rows
)
{
pShow
->
pNode
=
mgmtGetNextMnode
(
pShow
,
(
SMnodeObj
**
)
&
pMnode
);
pShow
->
pNode
=
mgmtGetNextMnode
(
pShow
->
pNode
,
(
SMnodeObj
**
)
&
pMnode
);
if
(
pMnode
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pMnode
->
mnodeId
;
cols
++
;
tinet_ntoa
(
ipstr
,
pMnode
->
privateIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
ipstr
);
cols
++
;
tinet_ntoa
(
ipstr
,
pMnode
->
publicIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pMnode
->
createdTime
;
strcpy
(
pWrite
,
ipstr
)
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
mgmtMnodeStatusStr
[
pMnode
->
status
])
;
*
(
int64_t
*
)
pWrite
=
pMnode
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
mgmtMnodeRoleStr
[
pMnode
->
role
]
);
strcpy
(
pWrite
,
taosGetMnodeStatusStr
(
pMnode
->
status
)
);
cols
++
;
tinet_ntoa
(
ipstr
,
pMnode
->
publicIp
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
ipstr
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
taosGetMnodeRoleStr
(
pMnode
->
role
));
cols
++
;
numOfRows
++
;
...
...
@@ -216,12 +174,14 @@ void mgmtGetMnodePrivateIpList(SRpcIpSet *ipSet) {
ipSet
->
inUse
=
0
;
ipSet
->
port
=
htons
(
tsMnodeDnodePort
);
ipSet
->
numOfIps
=
1
;
ipSet
->
ip
[
0
]
=
htonl
(
inet_addr
(
tsMasterIp
)
);
ipSet
->
ip
[
0
]
=
htonl
(
tsMnodeObj
.
privateIp
);
}
void
mgmtGetMnodePublicIpList
(
SRpcIpSet
*
ipSet
)
{
ipSet
->
inUse
=
0
;
ipSet
->
port
=
htons
(
tsMnodeDnodePort
);
ipSet
->
numOfIps
=
1
;
ipSet
->
ip
[
0
]
=
htonl
(
inet_addr
(
tsMasterIp
));
}
\ No newline at end of file
ipSet
->
ip
[
0
]
=
htonl
(
tsMnodeObj
.
publicIp
);
}
#endif
\ No newline at end of file
src/mnode/src/mgmtVgroup.c
浏览文件 @
c06fb4d9
...
...
@@ -53,6 +53,14 @@ static int32_t mgmtVgroupActionDestroy(SSdbOperDesc *pOper) {
if
(
pVgroup
->
tableList
)
{
tfree
(
pVgroup
->
tableList
);
}
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SDnodeObj
*
pDnode
=
mgmtGetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
if
(
pDnode
)
{
atomic_sub_fetch_32
(
&
pDnode
->
openVnodes
,
1
);
}
}
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -87,6 +95,7 @@ static int32_t mgmtVgroupActionInsert(SSdbOperDesc *pOper) {
pVgroup
->
vnodeGid
[
i
].
privateIp
=
pDnode
->
privateIp
;
pVgroup
->
vnodeGid
[
i
].
publicIp
=
pDnode
->
publicIp
;
pVgroup
->
vnodeGid
[
i
].
vnode
=
pVgroup
->
vgId
;
atomic_add_fetch_32
(
&
pDnode
->
openVnodes
,
1
);
}
mgmtAddVgroupIntoDb
(
pVgroup
);
...
...
src/util/inc/tstatus.h
浏览文件 @
c06fb4d9
...
...
@@ -62,6 +62,19 @@ enum _TSDB_VN_DROP_STATUS {
TSDB_VN_DROP_STATUS_DROPPING
};
enum
_TSDB_MN_STATUS
{
TSDB_MN_STATUS_OFFLINE
,
TSDB_MN_STATUS_UNSYNCED
,
TSDB_MN_STATUS_SYNCING
,
TSDB_MN_STATUS_SERVING
};
enum
_TSDB_MN_ROLE
{
TSDB_MN_ROLE_UNDECIDED
,
TSDB_MN_ROLE_SLAVE
,
TSDB_MN_ROLE_MASTER
};
enum
_TSDB_DN_STATUS
{
TSDB_DN_STATUS_OFFLINE
,
TSDB_DN_STATUS_READY
...
...
@@ -104,6 +117,8 @@ char* taosGetVgroupLbStatusStr(int32_t vglbStatus);
char
*
taosGetVnodeStreamStatusStr
(
int32_t
vnodeStreamStatus
);
char
*
taosGetTableStatusStr
(
int32_t
tableStatus
);
char
*
taosGetShowTypeStr
(
int32_t
showType
);
char
*
taosGetMnodeStatusStr
(
int32_t
mnodeStatus
);
char
*
taosGetMnodeRoleStr
(
int32_t
mnodeRole
);
#ifdef __cplusplus
}
...
...
src/util/src/.tqueue.c.swp
已删除
100644 → 0
浏览文件 @
61b2342b
文件已删除
src/util/src/tstatus.c
浏览文件 @
c06fb4d9
...
...
@@ -136,3 +136,22 @@ char *taosGetShowTypeStr(int32_t showType) {
default:
return
"undefined"
;
}
}
char
*
taosGetMnodeStatusStr
(
int32_t
mnodeStatus
)
{
switch
(
mnodeStatus
)
{
case
TSDB_MN_STATUS_OFFLINE
:
return
"offline"
;
case
TSDB_MN_STATUS_UNSYNCED
:
return
"unsynced"
;
case
TSDB_MN_STATUS_SYNCING
:
return
"syncing"
;
case
TSDB_MN_STATUS_SERVING
:
return
"serving"
;
default:
return
"undefined"
;
}
}
char
*
taosGetMnodeRoleStr
(
int32_t
mnodeRole
)
{
switch
(
mnodeRole
)
{
case
TSDB_MN_ROLE_UNDECIDED
:
return
"undicided"
;
case
TSDB_MN_ROLE_SLAVE
:
return
"slave"
;
case
TSDB_MN_ROLE_MASTER
:
return
"master"
;
default:
return
"undefined"
;
}
}
tests/script/general/show/dnodes.sim
0 → 100644
浏览文件 @
c06fb4d9
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1
system sh/exec.sh -n dnode1 -s start
sql connect
print =============== unsupport
sql_error create dnode 192.168.0.2
sql_error drop dnode 192.168.0.2
print =============== show dnodes
sql show dnodes;
if $rows != 1 then
return -1
endi
print $data00 $data01 $data02
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录