Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
cf687279
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cf687279
编写于
5月 27, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-335] first compiler vresion
上级
7ac821f2
变更
52
展开全部
隐藏空白更改
内联
并排
Showing
52 changed file
with
1995 addition
and
1921 deletion
+1995
-1921
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+2
-2
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-1
src/common/inc/tglobal.h
src/common/inc/tglobal.h
+1
-1
src/common/src/tglobal.c
src/common/src/tglobal.c
+2
-2
src/dnode/CMakeLists.txt
src/dnode/CMakeLists.txt
+1
-1
src/dnode/inc/dnodeMPeer.h
src/dnode/inc/dnodeMPeer.h
+3
-3
src/dnode/inc/dnodeMgmt.h
src/dnode/inc/dnodeMgmt.h
+3
-1
src/dnode/src/dnodeMPeer.c
src/dnode/src/dnodeMPeer.c
+155
-0
src/dnode/src/dnodeMRead.c
src/dnode/src/dnodeMRead.c
+9
-9
src/dnode/src/dnodeMWrite.c
src/dnode/src/dnodeMWrite.c
+42
-12
src/dnode/src/dnodeMain.c
src/dnode/src/dnodeMain.c
+4
-4
src/dnode/src/dnodeMgmt.c
src/dnode/src/dnodeMgmt.c
+89
-69
src/dnode/src/dnodeModule.c
src/dnode/src/dnodeModule.c
+3
-3
src/dnode/src/dnodePeer.c
src/dnode/src/dnodePeer.c
+7
-6
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+1
-3
src/dnode/src/dnodeVRead.c
src/dnode/src/dnodeVRead.c
+4
-4
src/dnode/src/dnodeVWrite.c
src/dnode/src/dnodeVWrite.c
+1
-1
src/inc/dnode.h
src/inc/dnode.h
+15
-10
src/inc/mnode.h
src/inc/mnode.h
+37
-19
src/inc/taosmsg.h
src/inc/taosmsg.h
+17
-17
src/inc/tbalance.h
src/inc/tbalance.h
+1
-1
src/inc/trpc.h
src/inc/trpc.h
+4
-4
src/mnode/inc/mnodeAcct.h
src/mnode/inc/mnodeAcct.h
+12
-12
src/mnode/inc/mnodeDb.h
src/mnode/inc/mnodeDb.h
+20
-20
src/mnode/inc/mnodeDef.h
src/mnode/inc/mnodeDef.h
+3
-23
src/mnode/inc/mnodeDnode.h
src/mnode/inc/mnodeDnode.h
+13
-13
src/mnode/inc/mnodeInt.h
src/mnode/inc/mnodeInt.h
+2
-2
src/mnode/inc/mnodeMnode.h
src/mnode/inc/mnodeMnode.h
+16
-16
src/mnode/inc/mnodePeer.h
src/mnode/inc/mnodePeer.h
+32
-0
src/mnode/inc/mnodeProfile.h
src/mnode/inc/mnodeProfile.h
+4
-4
src/mnode/inc/mnodeRead.h
src/mnode/inc/mnodeRead.h
+5
-4
src/mnode/inc/mnodeShow.h
src/mnode/inc/mnodeShow.h
+4
-17
src/mnode/inc/mnodeTable.h
src/mnode/inc/mnodeTable.h
+10
-10
src/mnode/inc/mnodeUser.h
src/mnode/inc/mnodeUser.h
+11
-11
src/mnode/inc/mnodeVgroup.h
src/mnode/inc/mnodeVgroup.h
+30
-30
src/mnode/inc/mnodeWrite.h
src/mnode/inc/mnodeWrite.h
+5
-6
src/mnode/src/mnodeAcct.c
src/mnode/src/mnodeAcct.c
+35
-36
src/mnode/src/mnodeBalance.c
src/mnode/src/mnodeBalance.c
+4
-8
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+116
-133
src/mnode/src/mnodeDnode.c
src/mnode/src/mnodeDnode.c
+170
-182
src/mnode/src/mnodeInt.c
src/mnode/src/mnodeInt.c
+63
-0
src/mnode/src/mnodeMain.c
src/mnode/src/mnodeMain.c
+32
-49
src/mnode/src/mnodeMnode.c
src/mnode/src/mnodeMnode.c
+109
-98
src/mnode/src/mnodePeer.c
src/mnode/src/mnodePeer.c
+28
-13
src/mnode/src/mnodeProfile.c
src/mnode/src/mnodeProfile.c
+99
-94
src/mnode/src/mnodeRead.c
src/mnode/src/mnodeRead.c
+18
-25
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+10
-10
src/mnode/src/mnodeShow.c
src/mnode/src/mnodeShow.c
+89
-220
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+404
-433
src/mnode/src/mnodeUser.c
src/mnode/src/mnodeUser.c
+95
-102
src/mnode/src/mnodeVgroup.c
src/mnode/src/mnodeVgroup.c
+141
-148
src/mnode/src/mnodeWrite.c
src/mnode/src/mnodeWrite.c
+13
-29
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
cf687279
...
...
@@ -2175,7 +2175,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
*/
SShowInfo
*
pShowInfo
=
&
pInfo
->
pDCLInfo
->
showOpt
;
int16_t
showType
=
pShowInfo
->
showType
;
if
(
showType
==
TSDB_M
NODE_TABLE_TABLE
||
showType
==
TSDB_MNODE_TABLE_METRIC
||
showType
==
TSDB_MNODE
_TABLE_VGROUP
)
{
if
(
showType
==
TSDB_M
GMT_TABLE_TABLE
||
showType
==
TSDB_MGMT_TABLE_METRIC
||
showType
==
TSDB_MGMT
_TABLE_VGROUP
)
{
// db prefix in tagCond, show table conds in payload
SSQLToken
*
pDbPrefixToken
=
&
pShowInfo
->
prefix
;
if
(
pDbPrefixToken
->
type
!=
0
)
{
...
...
@@ -2212,7 +2212,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
}
else
if
(
showType
==
TSDB_M
NODE
_TABLE_VNODES
)
{
}
else
if
(
showType
==
TSDB_M
GMT
_TABLE_VNODES
)
{
if
(
pShowInfo
->
prefix
.
type
==
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"No specified ip of dnode"
);
}
...
...
src/client/src/tscServer.c
浏览文件 @
cf687279
...
...
@@ -1116,7 +1116,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SShowInfo
*
pShowInfo
=
&
pInfo
->
pDCLInfo
->
showOpt
;
pShowMsg
->
type
=
pShowInfo
->
showType
;
if
(
pShowInfo
->
showType
!=
TSDB_M
NODE
_TABLE_VNODES
)
{
if
(
pShowInfo
->
showType
!=
TSDB_M
GMT
_TABLE_VNODES
)
{
SSQLToken
*
pPattern
=
&
pShowInfo
->
pattern
;
if
(
pPattern
->
type
>
0
)
{
// only show tables support wildcard query
strncpy
(
pShowMsg
->
payload
,
pPattern
->
z
,
pPattern
->
n
);
...
...
src/common/inc/tglobal.h
浏览文件 @
cf687279
...
...
@@ -100,7 +100,7 @@ extern int32_t tsMaxMgmtConnections;
extern
int32_t
tsBalanceInterval
;
extern
int32_t
tsOfflineThreshold
;
extern
int32_t
tsM
gmt
EqualVnodeNum
;
extern
int32_t
tsM
node
EqualVnodeNum
;
extern
int32_t
tsEnableHttpModule
;
extern
int32_t
tsEnableMqttModule
;
...
...
src/common/src/tglobal.c
浏览文件 @
cf687279
...
...
@@ -117,7 +117,7 @@ int32_t tsMaxVnodeConnections = 10000;
int32_t
tsBalanceInterval
=
300
;
// seconds
int32_t
tsOfflineThreshold
=
86400
*
100
;
// seconds 10days
int32_t
tsM
gmt
EqualVnodeNum
=
4
;
int32_t
tsM
node
EqualVnodeNum
=
4
;
int32_t
tsEnableHttpModule
=
1
;
int32_t
tsEnableMqttModule
=
0
;
// not finished yet, not started it by default
...
...
@@ -874,7 +874,7 @@ static void doInitGlobalConfig() {
// module configs
cfg
.
option
=
"mgmtEqualVnodeNum"
;
cfg
.
ptr
=
&
tsM
gmt
EqualVnodeNum
;
cfg
.
ptr
=
&
tsM
node
EqualVnodeNum
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
0
;
...
...
src/dnode/CMakeLists.txt
浏览文件 @
cf687279
...
...
@@ -16,7 +16,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_EXECUTABLE
(
taosd
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taosd taos_static monitor http mqtt tsdb twal vnode cJson lz4
)
TARGET_LINK_LIBRARIES
(
taosd
mnode
taos_static monitor http mqtt tsdb twal vnode cJson lz4
)
IF
(
TD_ACCOUNT
)
TARGET_LINK_LIBRARIES
(
taosd account
)
...
...
src/dnode/inc/dnodeM
p
eer.h
→
src/dnode/inc/dnodeM
P
eer.h
浏览文件 @
cf687279
...
...
@@ -20,9 +20,9 @@
extern
"C"
{
#endif
int32_t
dnodeInitMnode
Mgmt
();
void
dnodeCleanupMnode
Mgmt
();
void
dnodeDispatchToMnode
Mgmt
Queue
(
SRpcMsg
*
pMsg
);
int32_t
dnodeInitMnode
Peer
();
void
dnodeCleanupMnode
Peer
();
void
dnodeDispatchToMnode
Peer
Queue
(
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeMgmt.h
浏览文件 @
cf687279
...
...
@@ -32,7 +32,9 @@ void* dnodeGetVnodeWal(void *pVnode);
void
*
dnodeGetVnodeTsdb
(
void
*
pVnode
);
void
dnodeReleaseVnode
(
void
*
pVnode
);
void
dnodeSendRediretMsg
(
SRpcMsg
*
pMsg
);
void
dnodeSendRedirectMsg
(
int32_t
msgType
,
void
*
thandle
,
bool
forShell
);
void
dnodeGetMnodeIpSetForPeer
(
void
*
ipSet
);
void
dnodeGetMnodeIpSetForShell
(
void
*
ipSe
);
#ifdef __cplusplus
}
...
...
src/dnode/src/dnodeM
p
eer.c
→
src/dnode/src/dnodeM
P
eer.c
浏览文件 @
cf687279
...
...
@@ -25,51 +25,51 @@
#include "mnode.h"
#include "dnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeMWrite.h"
typedef
struct
{
pthread_t
thread
;
int32_t
workerId
;
}
SM
Mgmt
Worker
;
}
SM
Peer
Worker
;
typedef
struct
{
int32_t
num
;
SM
MgmtWorker
*
mgmt
Worker
;
}
SM
Mgmt
WorkerPool
;
SM
PeerWorker
*
peer
Worker
;
}
SM
Peer
WorkerPool
;
static
SM
MgmtWorkerPool
tsMMgmt
Pool
;
static
taos_qset
tsM
Mgmt
Qset
;
static
taos_queue
tsM
Mgmt
Queue
;
static
SM
PeerWorkerPool
tsMPeer
Pool
;
static
taos_qset
tsM
Peer
Qset
;
static
taos_queue
tsM
Peer
Queue
;
static
void
*
dnodeProcessMnode
Mgmt
Queue
(
void
*
param
);
static
void
*
dnodeProcessMnode
Peer
Queue
(
void
*
param
);
int32_t
dnodeInitMnode
Mgmt
()
{
tsM
Mgmt
Qset
=
taosOpenQset
();
int32_t
dnodeInitMnode
Peer
()
{
tsM
Peer
Qset
=
taosOpenQset
();
tsM
Mgmt
Pool
.
num
=
1
;
tsM
MgmtPool
.
mgmtWorker
=
(
SMMgmtWorker
*
)
calloc
(
sizeof
(
SMMgmtWorker
),
tsMMgmt
Pool
.
num
);
tsM
Peer
Pool
.
num
=
1
;
tsM
PeerPool
.
peerWorker
=
(
SMPeerWorker
*
)
calloc
(
sizeof
(
SMPeerWorker
),
tsMPeer
Pool
.
num
);
if
(
tsM
MgmtPool
.
mgmt
Worker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsM
Mgmt
Pool
.
num
;
++
i
)
{
SM
MgmtWorker
*
pWorker
=
tsMMgmtPool
.
mgmt
Worker
+
i
;
if
(
tsM
PeerPool
.
peer
Worker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsM
Peer
Pool
.
num
;
++
i
)
{
SM
PeerWorker
*
pWorker
=
tsMPeerPool
.
peer
Worker
+
i
;
pWorker
->
workerId
=
i
;
}
dPrint
(
"dnode m
mgmt
is opened"
);
dPrint
(
"dnode m
peer
is opened"
);
return
0
;
}
void
dnodeCleanupMnode
Mgmt
()
{
for
(
int32_t
i
=
0
;
i
<
tsM
Mgmt
Pool
.
num
;
++
i
)
{
SM
MgmtWorker
*
pWorker
=
tsMMgmtPool
.
mgmt
Worker
+
i
;
void
dnodeCleanupMnode
Peer
()
{
for
(
int32_t
i
=
0
;
i
<
tsM
Peer
Pool
.
num
;
++
i
)
{
SM
PeerWorker
*
pWorker
=
tsMPeerPool
.
peer
Worker
+
i
;
if
(
pWorker
->
thread
)
{
taosQsetThreadResume
(
tsM
Mgmt
Qset
);
taosQsetThreadResume
(
tsM
Peer
Qset
);
}
}
for
(
int32_t
i
=
0
;
i
<
tsM
Mgmt
Pool
.
num
;
++
i
)
{
SM
MgmtWorker
*
pWorker
=
tsMMgmtPool
.
mgmt
Worker
+
i
;
for
(
int32_t
i
=
0
;
i
<
tsM
Peer
Pool
.
num
;
++
i
)
{
SM
PeerWorker
*
pWorker
=
tsMPeerPool
.
peer
Worker
+
i
;
if
(
pWorker
->
thread
)
{
pthread_join
(
pWorker
->
thread
,
NULL
);
}
...
...
@@ -78,77 +78,77 @@ void dnodeCleanupMnodeMgmt() {
dPrint
(
"dnode mmgmt is closed"
);
}
int32_t
dnodeAllocateMnode
M
queue
()
{
tsM
Mgmt
Queue
=
taosOpenQueue
();
if
(
tsM
Mgmt
Queue
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
int32_t
dnodeAllocateMnode
P
queue
()
{
tsM
Peer
Queue
=
taosOpenQueue
();
if
(
tsM
Peer
Queue
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
taosAddIntoQset
(
tsM
MgmtQset
,
tsMMgmt
Queue
,
NULL
);
taosAddIntoQset
(
tsM
PeerQset
,
tsMPeer
Queue
,
NULL
);
for
(
int32_t
i
=
0
;
i
<
tsM
Mgmt
Pool
.
num
;
++
i
)
{
SM
MgmtWorker
*
pWorker
=
tsMMgmtPool
.
mgmt
Worker
+
i
;
for
(
int32_t
i
=
0
;
i
<
tsM
Peer
Pool
.
num
;
++
i
)
{
SM
PeerWorker
*
pWorker
=
tsMPeerPool
.
peer
Worker
+
i
;
pWorker
->
workerId
=
i
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessMnode
Mgmt
Queue
,
pWorker
)
!=
0
)
{
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessMnode
Peer
Queue
,
pWorker
)
!=
0
)
{
dError
(
"failed to create thread to process mmgmt queue, reason:%s"
,
strerror
(
errno
));
}
pthread_attr_destroy
(
&
thAttr
);
dTrace
(
"dnode mmgmt worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsM
Mgmt
Pool
.
num
);
dTrace
(
"dnode mmgmt worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsM
Peer
Pool
.
num
);
}
dTrace
(
"dnode mmgmt queue:%p is allocated"
,
tsM
Mgmt
Queue
);
dTrace
(
"dnode mmgmt queue:%p is allocated"
,
tsM
Peer
Queue
);
return
TSDB_CODE_SUCCESS
;
}
void
dnodeFreeMnode
R
queue
()
{
taosCloseQueue
(
tsM
Mgmt
Queue
);
tsM
Mgmt
Queue
=
NULL
;
void
dnodeFreeMnode
P
queue
()
{
taosCloseQueue
(
tsM
Peer
Queue
);
tsM
Peer
Queue
=
NULL
;
}
void
dnodeDispatchToMnode
Mgmt
Queue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsM
Mgmt
Queue
==
NULL
)
{
dnodeSendRedire
tMsg
(
pMsg
);
void
dnodeDispatchToMnode
Peer
Queue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsM
Peer
Queue
==
NULL
)
{
dnodeSendRedire
ctMsg
(
pMsg
->
msgType
,
pMsg
->
handle
,
false
);
return
;
}
SMnodeMsg
*
p
Mgmt
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
pMgmt
->
rpcMsg
=
*
pMsg
;
taosWriteQitem
(
tsM
MgmtQueue
,
TAOS_QTYPE_RPC
,
pMgmt
);
SMnodeMsg
*
p
Peer
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
mnodeCreateMsg
(
pPeer
,
pMsg
)
;
taosWriteQitem
(
tsM
PeerQueue
,
TAOS_QTYPE_RPC
,
pPeer
);
}
static
void
dnodeSendRpcMnode
MgmtRsp
(
SMnodeMsg
*
pMgmt
,
int32_t
code
)
{
static
void
dnodeSendRpcMnode
PeerRsp
(
SMnodeMsg
*
pPeer
,
int32_t
code
)
{
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
SRpcMsg
rpcRsp
=
{
.
handle
=
p
Mgmt
->
rpcMsg
.
handle
,
.
pCont
=
p
Mgmt
->
rspRet
.
rsp
,
.
contLen
=
p
Mgmt
->
rspRet
.
len
,
.
code
=
pMgmt
->
rspRet
.
code
,
.
handle
=
p
Peer
->
t
handle
,
.
pCont
=
p
Peer
->
rpcRsp
.
rsp
,
.
contLen
=
p
Peer
->
rpcRsp
.
len
,
.
code
=
code
,
};
rpcSendResponse
(
&
rpcRsp
);
rpcFreeCont
(
pMgmt
->
rpcMsg
.
pCont
);
mnodeCleanupMsg
(
pPeer
);
}
static
void
*
dnodeProcessMnode
Mgmt
Queue
(
void
*
param
)
{
SMnodeMsg
*
p
Mgmt
Msg
;
static
void
*
dnodeProcessMnode
Peer
Queue
(
void
*
param
)
{
SMnodeMsg
*
p
Peer
Msg
;
int32_t
type
;
void
*
unUsed
;
while
(
1
)
{
if
(
taosReadQitemFromQset
(
tsM
MgmtQset
,
&
type
,
(
void
**
)
&
pMgmt
Msg
,
&
unUsed
)
==
0
)
{
dTrace
(
"dnodeProcessMnode
Mgmt
Queue: got no message from qset, exiting..."
);
if
(
taosReadQitemFromQset
(
tsM
PeerQset
,
&
type
,
(
void
**
)
&
pPeer
Msg
,
&
unUsed
)
==
0
)
{
dTrace
(
"dnodeProcessMnode
Peer
Queue: got no message from qset, exiting..."
);
break
;
}
dTrace
(
"%p, msg:%s will be processed"
,
p
MgmtMsg
->
rpcMsg
.
ahandle
,
taosMsg
[
pMgmtMsg
->
rpcMsg
.
msgType
]);
int32_t
code
=
mnodeProcess
Mgmt
(
pMgmt
Msg
);
dnodeSendRpcMnode
MgmtRsp
(
pMgmt
Msg
,
code
);
taosFreeQitem
(
p
Mgmt
Msg
);
dTrace
(
"%p, msg:%s will be processed"
,
p
PeerMsg
->
ahandle
,
taosMsg
[
pPeerMsg
->
msgType
]);
int32_t
code
=
mnodeProcess
PeerReq
(
pPeer
Msg
);
dnodeSendRpcMnode
PeerRsp
(
pPeer
Msg
,
code
);
taosFreeQitem
(
p
Peer
Msg
);
}
return
NULL
;
...
...
src/dnode/src/dnodeMRead.c
浏览文件 @
cf687279
...
...
@@ -25,7 +25,7 @@
#include "mnode.h"
#include "dnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeMRead.h"
typedef
struct
{
...
...
@@ -116,12 +116,12 @@ void dnodeFreeMnodeRqueue() {
void
dnodeDispatchToMnodeReadQueue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsMReadQueue
==
NULL
)
{
dnodeSendRedire
tMsg
(
pMsg
);
dnodeSendRedire
ctMsg
(
pMsg
->
msgType
,
pMsg
->
handle
,
true
);
return
;
}
SMnodeMsg
*
pRead
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
pRead
->
rpcMsg
=
*
pMsg
;
mnodeCreateMsg
(
pRead
,
pMsg
)
;
taosWriteQitem
(
tsMReadQueue
,
TAOS_QTYPE_RPC
,
pRead
);
}
...
...
@@ -129,14 +129,14 @@ static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) {
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
SRpcMsg
rpcRsp
=
{
.
handle
=
pRead
->
rpcMsg
.
handle
,
.
pCont
=
pRead
->
r
spRet
.
rsp
,
.
contLen
=
pRead
->
r
spRet
.
len
,
.
code
=
pRead
->
rspRet
.
code
,
.
handle
=
pRead
->
t
handle
,
.
pCont
=
pRead
->
r
pcRsp
.
rsp
,
.
contLen
=
pRead
->
r
pcRsp
.
len
,
.
code
=
code
,
};
rpcSendResponse
(
&
rpcRsp
);
rpcFreeCont
(
pRead
->
rpcMsg
.
pCont
);
mnodeCleanupMsg
(
pRead
);
}
static
void
*
dnodeProcessMnodeReadQueue
(
void
*
param
)
{
...
...
@@ -150,7 +150,7 @@ static void *dnodeProcessMnodeReadQueue(void *param) {
break
;
}
dTrace
(
"%p, msg:%s will be processed"
,
pReadMsg
->
rpcMsg
.
ahandle
,
taosMsg
[
pReadMsg
->
rpcMsg
.
msgType
]);
dTrace
(
"%p, msg:%s will be processed"
,
pReadMsg
->
ahandle
,
taosMsg
[
pReadMsg
->
msgType
]);
int32_t
code
=
mnodeProcessRead
(
pReadMsg
);
dnodeSendRpcMnodeReadRsp
(
pReadMsg
,
code
);
taosFreeQitem
(
pReadMsg
);
...
...
src/dnode/src/dnodeMWrite.c
浏览文件 @
cf687279
...
...
@@ -18,6 +18,7 @@
#include "taoserror.h"
#include "taosmsg.h"
#include "tutil.h"
#include "ttimer.h"
#include "tqueue.h"
#include "trpc.h"
#include "twal.h"
...
...
@@ -25,7 +26,7 @@
#include "mnode.h"
#include "dnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeMWrite.h"
typedef
struct
{
...
...
@@ -41,6 +42,7 @@ typedef struct {
static
SMWriteWorkerPool
tsMWritePool
;
static
taos_qset
tsMWriteQset
;
static
taos_queue
tsMWriteQueue
;
extern
void
*
tsDnodeTmr
;
static
void
*
dnodeProcessMnodeWriteQueue
(
void
*
param
);
...
...
@@ -78,7 +80,7 @@ void dnodeCleanupMnodeWrite() {
dPrint
(
"dnode mwrite is closed"
);
}
int32_t
dnodeAllocateMnode
R
queue
()
{
int32_t
dnodeAllocateMnode
W
queue
()
{
tsMWriteQueue
=
taosOpenQueue
();
if
(
tsMWriteQueue
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -104,34 +106,35 @@ int32_t dnodeAllocateMnodeRqueue() {
return
TSDB_CODE_SUCCESS
;
}
void
dnodeFreeMnode
R
queue
()
{
void
dnodeFreeMnode
W
queue
()
{
taosCloseQueue
(
tsMWriteQueue
);
tsMWriteQueue
=
NULL
;
}
void
dnodeDispatchToMnodeWriteQueue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsMWriteQueue
==
NULL
)
{
dnodeSendRedire
tMsg
(
pMsg
);
dnodeSendRedire
ctMsg
(
pMsg
->
msgType
,
pMsg
->
handle
,
true
);
return
;
}
SMnodeMsg
*
pWrite
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
pWrite
->
rpcMsg
=
*
pMsg
;
mnodeCreateMsg
(
pWrite
,
pMsg
)
;
taosWriteQitem
(
tsMWriteQueue
,
TAOS_QTYPE_RPC
,
pWrite
);
}
static
void
dnodeSendRpcMnodeWriteRsp
(
SMnodeMsg
*
pWrite
,
int32_t
code
)
{
void
dnodeSendRpcMnodeWriteRsp
(
void
*
pRaw
,
int32_t
code
)
{
SMnodeMsg
*
pWrite
=
pRaw
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
SRpcMsg
rpcRsp
=
{
.
handle
=
pWrite
->
rpcMsg
.
handle
,
.
pCont
=
pWrite
->
r
spRet
.
rsp
,
.
contLen
=
pWrite
->
r
spRet
.
len
,
.
code
=
pWrite
->
rspRet
.
code
,
.
handle
=
pWrite
->
t
handle
,
.
pCont
=
pWrite
->
r
pcRsp
.
rsp
,
.
contLen
=
pWrite
->
r
pcRsp
.
len
,
.
code
=
code
,
};
rpcSendResponse
(
&
rpcRsp
);
rpcFreeCont
(
pWrite
->
rpcMsg
.
pCont
);
mnodeCleanupMsg
(
pWrite
);
}
static
void
*
dnodeProcessMnodeWriteQueue
(
void
*
param
)
{
...
...
@@ -145,7 +148,7 @@ static void *dnodeProcessMnodeWriteQueue(void *param) {
break
;
}
dTrace
(
"%p, msg:%s will be processed"
,
pWriteMsg
->
rpcMsg
.
ahandle
,
taosMsg
[
pWriteMsg
->
rpcMsg
.
msgType
]);
dTrace
(
"%p, msg:%s will be processed"
,
pWriteMsg
->
ahandle
,
taosMsg
[
pWriteMsg
->
msgType
]);
int32_t
code
=
mnodeProcessWrite
(
pWriteMsg
);
dnodeSendRpcMnodeWriteRsp
(
pWriteMsg
,
code
);
taosFreeQitem
(
pWriteMsg
);
...
...
@@ -153,3 +156,30 @@ static void *dnodeProcessMnodeWriteQueue(void *param) {
return
NULL
;
}
static
void
dnodeFreeMnodeWriteMsg
(
void
*
pMsg
)
{
SMnodeMsg
*
pWrite
=
pMsg
;
mnodeCleanupMsg
(
pWrite
);
taosFreeQitem
(
pWrite
);
}
void
dnodeReprocessMnodeWriteMsg
(
void
*
pMsg
)
{
SMnodeMsg
*
pWrite
=
pMsg
;
if
(
!
mnodeIsRunning
()
||
tsMWriteQueue
==
NULL
)
{
dnodeSendRedirectMsg
(
pWrite
->
msgType
,
pWrite
->
thandle
,
true
);
dnodeFreeMnodeWriteMsg
(
pWrite
);
}
else
{
taosWriteQitem
(
tsMWriteQueue
,
TAOS_QTYPE_RPC
,
pWrite
);
}
}
static
void
dnodeDoDelayReprocessMnodeWriteMsg
(
void
*
param
,
void
*
tmrId
)
{
dnodeReprocessMnodeWriteMsg
(
param
);
}
void
dnodeDelayReprocessMnodeWriteMsg
(
void
*
pMsg
)
{
SMnodeMsg
*
mnodeMsg
=
pMsg
;
void
*
unUsed
=
NULL
;
taosTmrReset
(
dnodeDoDelayReprocessMnodeWriteMsg
,
300
,
mnodeMsg
,
tsDnodeTmr
,
&
unUsed
);
}
\ No newline at end of file
src/dnode/src/dnodeMain.c
浏览文件 @
cf687279
...
...
@@ -21,14 +21,14 @@
#include "tglobal.h"
#include "dnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodePeer.h"
#include "dnodeModule.h"
#include "dnodeVRead.h"
#include "dnodeVWrite.h"
#include "dnodeMRead.h"
#include "dnodeMWrite.h"
#include "dnodeM
Mgmt
.h"
#include "dnodeM
Peer
.h"
#include "dnodeShell.h"
static
int32_t
dnodeInitStorage
();
...
...
@@ -72,7 +72,7 @@ int32_t dnodeInitSystem() {
if
(
dnodeInitVnodeWrite
()
!=
0
)
return
-
1
;
if
(
dnodeInitMnodeRead
()
!=
0
)
return
-
1
;
if
(
dnodeInitMnodeWrite
()
!=
0
)
return
-
1
;
if
(
dnodeInitMnode
Mgmt
()
!=
0
)
return
-
1
;
if
(
dnodeInitMnode
Peer
()
!=
0
)
return
-
1
;
if
(
dnodeInitClient
()
!=
0
)
return
-
1
;
if
(
dnodeInitServer
()
!=
0
)
return
-
1
;
if
(
dnodeInitMgmt
()
!=
0
)
return
-
1
;
...
...
@@ -95,7 +95,7 @@ void dnodeCleanUpSystem() {
dnodeCleanupMgmt
();
dnodeCleanupServer
();
dnodeCleanupClient
();
dnodeCleanupMnode
Mgmt
();
dnodeCleanupMnode
Peer
();
dnodeCleanupMnodeWrite
();
dnodeCleanupMnodeRead
();
dnodeCleanupVnodeWrite
();
...
...
src/dnode/src/dnodeMgmt.c
浏览文件 @
cf687279
...
...
@@ -32,13 +32,22 @@
#include "vnode.h"
#include "mnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeVRead.h"
#include "dnodeVWrite.h"
#include "dnodeModule.h"
#define MPEER_CONTENT_LEN 2000
void
*
tsDnodeTmr
=
NULL
;
static
void
*
tsStatusTimer
=
NULL
;
static
uint32_t
tsRebootTime
;
static
SRpcIpSet
tsDMnodeIpSetForPeer
=
{
0
};
static
SRpcIpSet
tsDMnodeIpSetForShell
=
{
0
};
static
SDMMnodeInfos
tsDMnodeInfos
=
{
0
};
static
SDMDnodeCfg
tsDnodeCfg
=
{
0
};
static
void
dnodeUpdateMnodeInfos
(
SDMMnodeInfos
*
pMnodes
);
static
bool
dnodeReadMnodeInfos
();
static
void
dnodeSaveMnodeInfos
();
...
...
@@ -48,14 +57,6 @@ static void dnodeSaveDnodeCfg();
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
);
static
void
dnodeSendStatusMsg
(
void
*
handle
,
void
*
tmrId
);
static
void
*
tsDnodeTmr
=
NULL
;
static
void
*
tsStatusTimer
=
NULL
;
static
uint32_t
tsRebootTime
;
static
SRpcIpSet
tsMnodeIpSet
=
{
0
};
static
SDMMnodeInfos
tsMnodeInfos
=
{
0
};
static
SDMDnodeCfg
tsDnodeCfg
=
{
0
};
static
int32_t
dnodeOpenVnodes
();
static
void
dnodeCloseVnodes
();
static
int32_t
dnodeProcessCreateVnodeMsg
(
SRpcMsg
*
pMsg
);
...
...
@@ -81,22 +82,40 @@ int32_t dnodeInitMgmt() {
}
if
(
!
dnodeReadMnodeInfos
())
{
memset
(
&
tsMnodeIpSet
,
0
,
sizeof
(
SRpcIpSet
));
memset
(
&
tsMnodeInfos
,
0
,
sizeof
(
SDMMnodeInfos
));
tsMnodeIpSet
.
numOfIps
=
1
;
taosGetFqdnPortFromEp
(
tsFirst
,
tsMnodeIpSet
.
fqdn
[
0
],
&
tsMnodeIpSet
.
port
[
0
]);
tsMnodeIpSet
.
port
[
0
]
+=
TSDB_PORT_DNODEDNODE
;
memset
(
&
tsDMnodeIpSetForPeer
,
0
,
sizeof
(
SRpcIpSet
));
memset
(
&
tsDMnodeIpSetForShell
,
0
,
sizeof
(
SRpcIpSet
));
memset
(
&
tsDMnodeInfos
,
0
,
sizeof
(
SDMMnodeInfos
));
tsDMnodeIpSetForPeer
.
numOfIps
=
1
;
taosGetFqdnPortFromEp
(
tsFirst
,
tsDMnodeIpSetForPeer
.
fqdn
[
0
],
&
tsDMnodeIpSetForPeer
.
port
[
0
]);
tsDMnodeIpSetForPeer
.
port
[
0
]
+=
TSDB_PORT_DNODEDNODE
;
tsDMnodeIpSetForShell
.
numOfIps
=
1
;
taosGetFqdnPortFromEp
(
tsFirst
,
tsDMnodeIpSetForShell
.
fqdn
[
0
],
&
tsDMnodeIpSetForShell
.
port
[
0
]);
tsDMnodeIpSetForShell
.
port
[
0
]
+=
TSDB_PORT_DNODESHELL
;
if
(
strcmp
(
tsSecond
,
tsFirst
)
!=
0
)
{
tsMnodeIpSet
.
numOfIps
=
2
;
taosGetFqdnPortFromEp
(
tsSecond
,
tsMnodeIpSet
.
fqdn
[
1
],
&
tsMnodeIpSet
.
port
[
1
]);
tsMnodeIpSet
.
port
[
1
]
+=
TSDB_PORT_DNODEDNODE
;
tsDMnodeIpSetForPeer
.
numOfIps
=
2
;
taosGetFqdnPortFromEp
(
tsSecond
,
tsDMnodeIpSetForPeer
.
fqdn
[
1
],
&
tsDMnodeIpSetForPeer
.
port
[
1
]);
tsDMnodeIpSetForPeer
.
port
[
1
]
+=
TSDB_PORT_DNODEDNODE
;
tsDMnodeIpSetForShell
.
numOfIps
=
2
;
taosGetFqdnPortFromEp
(
tsSecond
,
tsDMnodeIpSetForShell
.
fqdn
[
1
],
&
tsDMnodeIpSetForShell
.
port
[
1
]);
tsDMnodeIpSetForShell
.
port
[
1
]
+=
TSDB_PORT_DNODESHELL
;
}
}
else
{
tsMnodeIpSet
.
inUse
=
tsMnodeInfos
.
inUse
;
tsMnodeIpSet
.
numOfIps
=
tsMnodeInfos
.
nodeNum
;
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
i
++
)
{
taosGetFqdnPortFromEp
(
tsMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
tsMnodeIpSet
.
fqdn
[
i
],
&
tsMnodeIpSet
.
port
[
i
]);
tsMnodeIpSet
.
port
[
i
]
+=
TSDB_PORT_DNODEDNODE
;
tsDMnodeIpSetForPeer
.
inUse
=
tsDMnodeInfos
.
inUse
;
tsDMnodeIpSetForPeer
.
numOfIps
=
tsDMnodeInfos
.
nodeNum
;
for
(
int32_t
i
=
0
;
i
<
tsDMnodeInfos
.
nodeNum
;
i
++
)
{
taosGetFqdnPortFromEp
(
tsDMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
tsDMnodeIpSetForPeer
.
fqdn
[
i
],
&
tsDMnodeIpSetForPeer
.
port
[
i
]);
tsDMnodeIpSetForPeer
.
port
[
i
]
+=
TSDB_PORT_DNODEDNODE
;
}
tsDMnodeIpSetForShell
.
inUse
=
tsDMnodeInfos
.
inUse
;
tsDMnodeIpSetForShell
.
numOfIps
=
tsDMnodeInfos
.
nodeNum
;
for
(
int32_t
i
=
0
;
i
<
tsDMnodeInfos
.
nodeNum
;
i
++
)
{
taosGetFqdnPortFromEp
(
tsDMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
tsDMnodeIpSetForShell
.
fqdn
[
i
],
&
tsDMnodeIpSetForShell
.
port
[
i
]);
tsDMnodeIpSetForShell
.
port
[
i
]
+=
TSDB_PORT_DNODESHELL
;
}
}
...
...
@@ -265,26 +284,23 @@ static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg) {
return
taosCfgDynamicOptions
(
pCfg
->
config
);
}
void
dnodeUpdate
IpSet
(
SRpcIpSet
*
pIpSet
)
{
void
dnodeUpdate
MnodeIpSetForPeer
(
SRpcIpSet
*
pIpSet
)
{
dPrint
(
"mnode IP list is changed, numOfIps:%d inUse:%d"
,
pIpSet
->
numOfIps
,
pIpSet
->
inUse
);
for
(
int
i
=
0
;
i
<
pIpSet
->
numOfIps
;
++
i
)
{
dPrint
(
"mnode index:%d %s:%u"
,
i
,
pIpSet
->
fqdn
[
i
],
pIpSet
->
port
[
i
])
}
ts
MnodeIpSet
=
*
pIpSet
;
ts
DMnodeIpSetForPeer
=
*
pIpSet
;
}
void
dnodeGetMnode
DnodeIpSet
(
void
*
ipSetRaw
,
bool
encode
)
{
void
dnodeGetMnode
IpSetForPeer
(
void
*
ipSetRaw
)
{
SRpcIpSet
*
ipSet
=
ipSetRaw
;
ipSet
->
numOfIps
=
tsMnodeInfos
.
nodeNum
;
ipSet
->
inUse
=
tsMnodeInfos
.
inUse
;
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
++
i
)
{
taosGetFqdnPortFromEp
(
tsMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
ipSet
->
fqdn
[
i
],
&
ipSet
->
port
[
i
]);
ipSet
->
port
[
i
]
+=
TSDB_PORT_DNODEDNODE
;
if
(
encode
)
{
ipSet
->
port
[
i
]
=
htons
(
ipSet
->
port
[
i
]);
}
}
*
ipSet
=
tsDMnodeIpSetForPeer
;
}
void
dnodeGetMnodeIpSetForShell
(
void
*
ipSetRaw
)
{
SRpcIpSet
*
ipSet
=
ipSetRaw
;
*
ipSet
=
tsDMnodeIpSetForShell
;
}
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
)
{
...
...
@@ -324,22 +340,22 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
}
static
void
dnodeUpdateMnodeInfos
(
SDMMnodeInfos
*
pMnodes
)
{
bool
mnodesChanged
=
(
memcmp
(
&
tsMnodeInfos
,
pMnodes
,
sizeof
(
SDMMnodeInfos
))
!=
0
);
bool
mnodesNotInit
=
(
tsMnodeInfos
.
nodeNum
==
0
);
bool
mnodesChanged
=
(
memcmp
(
&
ts
D
MnodeInfos
,
pMnodes
,
sizeof
(
SDMMnodeInfos
))
!=
0
);
bool
mnodesNotInit
=
(
ts
D
MnodeInfos
.
nodeNum
==
0
);
if
(
!
(
mnodesChanged
||
mnodesNotInit
))
return
;
memcpy
(
&
tsMnodeInfos
,
pMnodes
,
sizeof
(
SDMMnodeInfos
));
memcpy
(
&
ts
D
MnodeInfos
,
pMnodes
,
sizeof
(
SDMMnodeInfos
));
ts
MnodeIpSet
.
inUse
=
ts
MnodeInfos
.
inUse
;
ts
MnodeIpSet
.
numOfIps
=
ts
MnodeInfos
.
nodeNum
;
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
i
++
)
{
taosGetFqdnPortFromEp
(
ts
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
tsMnodeIpSet
.
fqdn
[
i
],
&
tsMnodeIpSet
.
port
[
i
]);
ts
MnodeIpSet
.
port
[
i
]
+=
TSDB_PORT_DNODEDNODE
;
ts
DMnodeIpSetForPeer
.
inUse
=
tsD
MnodeInfos
.
inUse
;
ts
DMnodeIpSetForPeer
.
numOfIps
=
tsD
MnodeInfos
.
nodeNum
;
for
(
int32_t
i
=
0
;
i
<
ts
D
MnodeInfos
.
nodeNum
;
i
++
)
{
taosGetFqdnPortFromEp
(
ts
DMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
tsDMnodeIpSetForPeer
.
fqdn
[
i
],
&
tsDMnodeIpSetForPeer
.
port
[
i
]);
ts
DMnodeIpSetForPeer
.
port
[
i
]
+=
TSDB_PORT_DNODEDNODE
;
}
dPrint
(
"mnodes is changed, nodeNum:%d inUse:%d"
,
ts
MnodeInfos
.
nodeNum
,
ts
MnodeInfos
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
i
++
)
{
dPrint
(
"mnode:%d, %s"
,
ts
MnodeInfos
.
nodeInfos
[
i
].
nodeId
,
ts
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
dPrint
(
"mnodes is changed, nodeNum:%d inUse:%d"
,
ts
DMnodeInfos
.
nodeNum
,
tsD
MnodeInfos
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
ts
D
MnodeInfos
.
nodeNum
;
i
++
)
{
dPrint
(
"mnode:%d, %s"
,
ts
DMnodeInfos
.
nodeInfos
[
i
].
nodeId
,
tsD
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
}
dnodeSaveMnodeInfos
();
...
...
@@ -377,14 +393,14 @@ static bool dnodeReadMnodeInfos() {
dError
(
"failed to read mnode mgmtIpList.json, inUse not found"
);
goto
PARSE_OVER
;
}
tsMnodeInfos
.
inUse
=
inUse
->
valueint
;
ts
D
MnodeInfos
.
inUse
=
inUse
->
valueint
;
cJSON
*
nodeNum
=
cJSON_GetObjectItem
(
root
,
"nodeNum"
);
if
(
!
nodeNum
||
nodeNum
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read mnode mgmtIpList.json, nodeNum not found"
);
goto
PARSE_OVER
;
}
tsMnodeInfos
.
nodeNum
=
nodeNum
->
valueint
;
ts
D
MnodeInfos
.
nodeNum
=
nodeNum
->
valueint
;
cJSON
*
nodeInfos
=
cJSON_GetObjectItem
(
root
,
"nodeInfos"
);
if
(
!
nodeInfos
||
nodeInfos
->
type
!=
cJSON_Array
)
{
...
...
@@ -393,7 +409,7 @@ static bool dnodeReadMnodeInfos() {
}
int
size
=
cJSON_GetArraySize
(
nodeInfos
);
if
(
size
!=
tsMnodeInfos
.
nodeNum
)
{
if
(
size
!=
ts
D
MnodeInfos
.
nodeNum
)
{
dError
(
"failed to read mnode mgmtIpList.json, nodeInfos size not matched"
);
goto
PARSE_OVER
;
}
...
...
@@ -407,21 +423,21 @@ static bool dnodeReadMnodeInfos() {
dError
(
"failed to read mnode mgmtIpList.json, nodeId not found"
);
goto
PARSE_OVER
;
}
tsMnodeInfos
.
nodeInfos
[
i
].
nodeId
=
nodeId
->
valueint
;
ts
D
MnodeInfos
.
nodeInfos
[
i
].
nodeId
=
nodeId
->
valueint
;
cJSON
*
nodeEp
=
cJSON_GetObjectItem
(
nodeInfo
,
"nodeEp"
);
if
(
!
nodeEp
||
nodeEp
->
type
!=
cJSON_String
||
nodeEp
->
valuestring
==
NULL
)
{
dError
(
"failed to read mnode mgmtIpList.json, nodeName not found"
);
goto
PARSE_OVER
;
}
strncpy
(
tsMnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
nodeEp
->
valuestring
,
TSDB_EP_LEN
);
strncpy
(
ts
D
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
,
nodeEp
->
valuestring
,
TSDB_EP_LEN
);
}
ret
=
true
;
dPrint
(
"read mnode iplist successed, numOfIps:%d inUse:%d"
,
ts
MnodeInfos
.
nodeNum
,
ts
MnodeInfos
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
i
++
)
{
dPrint
(
"mnode:%d, %s"
,
ts
MnodeInfos
.
nodeInfos
[
i
].
nodeId
,
ts
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
dPrint
(
"read mnode iplist successed, numOfIps:%d inUse:%d"
,
ts
DMnodeInfos
.
nodeNum
,
tsD
MnodeInfos
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
ts
D
MnodeInfos
.
nodeNum
;
i
++
)
{
dPrint
(
"mnode:%d, %s"
,
ts
DMnodeInfos
.
nodeInfos
[
i
].
nodeId
,
tsD
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
}
PARSE_OVER:
...
...
@@ -442,13 +458,13 @@ static void dnodeSaveMnodeInfos() {
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
inUse
\"
: %d,
\n
"
,
tsMnodeInfos
.
inUse
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeNum
\"
: %d,
\n
"
,
tsMnodeInfos
.
nodeNum
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
inUse
\"
: %d,
\n
"
,
ts
D
MnodeInfos
.
inUse
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeNum
\"
: %d,
\n
"
,
ts
D
MnodeInfos
.
nodeNum
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeInfos
\"
: [{
\n
"
);
for
(
int32_t
i
=
0
;
i
<
tsMnodeInfos
.
nodeNum
;
i
++
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeId
\"
: %d,
\n
"
,
tsMnodeInfos
.
nodeInfos
[
i
].
nodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeEp
\"
:
\"
%s
\"\n
"
,
tsMnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
if
(
i
<
tsMnodeInfos
.
nodeNum
-
1
)
{
for
(
int32_t
i
=
0
;
i
<
ts
D
MnodeInfos
.
nodeNum
;
i
++
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeId
\"
: %d,
\n
"
,
ts
D
MnodeInfos
.
nodeInfos
[
i
].
nodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
nodeEp
\"
:
\"
%s
\"\n
"
,
ts
D
MnodeInfos
.
nodeInfos
[
i
].
nodeEp
);
if
(
i
<
ts
D
MnodeInfos
.
nodeNum
-
1
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },{
\n
"
);
}
else
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }]
\n
"
);
...
...
@@ -464,11 +480,11 @@ static void dnodeSaveMnodeInfos() {
}
char
*
dnodeGetMnodeMasterEp
()
{
return
ts
MnodeInfos
.
nodeInfos
[
tsMnodeIpSet
.
inUse
].
nodeEp
;
return
ts
DMnodeInfos
.
nodeInfos
[
tsDMnodeIpSetForPeer
.
inUse
].
nodeEp
;
}
void
*
dnodeGetMnodeInfos
()
{
return
&
tsMnodeInfos
;
return
&
ts
D
MnodeInfos
;
}
static
void
dnodeSendStatusMsg
(
void
*
handle
,
void
*
tmrId
)
{
...
...
@@ -511,7 +527,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
.
msgType
=
TSDB_MSG_TYPE_DM_STATUS
};
dnodeSendMsgToDnode
(
&
ts
MnodeIpSet
,
&
rpcMsg
);
dnodeSendMsgToDnode
(
&
ts
DMnodeIpSetForPeer
,
&
rpcMsg
);
}
static
bool
dnodeReadDnodeCfg
()
{
...
...
@@ -593,14 +609,18 @@ int32_t dnodeGetDnodeId() {
return
tsDnodeCfg
.
dnodeId
;
}
void
dnodeSendRedire
tMsg
(
SRpcMsg
*
rpcMsg
)
{
void
dnodeSendRedire
ctMsg
(
int32_t
msgType
,
void
*
thandle
,
bool
forShell
)
{
SRpcConnInfo
connInfo
;
rpcGetConnInfo
(
rpcMsg
->
handle
,
&
connInfo
);
rpcGetConnInfo
(
t
handle
,
&
connInfo
);
SRpcIpSet
ipSet
=
{
0
};
dnodeGetMnodeDnodeIpSet
(
&
ipSet
);
dTrace
(
"msg:%s will be redirected, dnodeIp:%s user:%s, numOfIps:%d inUse:%d"
,
taosMsg
[
rpcMsg
->
msgType
],
if
(
forShell
)
{
dnodeGetMnodeIpSetForShell
(
&
ipSet
);
}
else
{
dnodeGetMnodeIpSetForPeer
(
&
ipSet
);
}
dTrace
(
"msg:%s will be redirected, dnodeIp:%s user:%s, numOfIps:%d inUse:%d"
,
taosMsg
[
msgType
],
taosIpStr
(
connInfo
.
clientIp
),
connInfo
.
user
,
ipSet
.
numOfIps
,
ipSet
.
inUse
);
for
(
int
i
=
0
;
i
<
ipSet
.
numOfIps
;
++
i
)
{
...
...
@@ -608,5 +628,5 @@ void dnodeSendRediretMsg(SRpcMsg *rpcMsg) {
ipSet
.
port
[
i
]
=
htons
(
ipSet
.
port
[
i
]);
}
rpcSendRedirectRsp
(
rpcMsg
->
handle
,
&
ipSet
);
}
\ No newline at end of file
rpcSendRedirectRsp
(
thandle
,
&
ipSet
);
}
src/dnode/src/dnodeModule.c
浏览文件 @
cf687279
...
...
@@ -48,9 +48,9 @@ static void dnodeUnSetModuleStatus(int32_t module) {
static
void
dnodeAllocModules
()
{
tsModule
[
TSDB_MOD_MGMT
].
enable
=
false
;
tsModule
[
TSDB_MOD_MGMT
].
name
=
"mgmt"
;
tsModule
[
TSDB_MOD_MGMT
].
initFp
=
m
gmt
InitSystem
;
tsModule
[
TSDB_MOD_MGMT
].
cleanUpFp
=
m
gmtCleanU
pSystem
;
tsModule
[
TSDB_MOD_MGMT
].
startFp
=
m
gmt
StartSystem
;
tsModule
[
TSDB_MOD_MGMT
].
initFp
=
m
node
InitSystem
;
tsModule
[
TSDB_MOD_MGMT
].
cleanUpFp
=
m
nodeCleanu
pSystem
;
tsModule
[
TSDB_MOD_MGMT
].
startFp
=
m
node
StartSystem
;
tsModule
[
TSDB_MOD_MGMT
].
stopFp
=
mgmtStopSystem
;
tsModule
[
TSDB_MOD_HTTP
].
enable
=
(
tsEnableHttpModule
==
1
);
...
...
src/dnode/src/dnodePeer.c
浏览文件 @
cf687279
...
...
@@ -23,15 +23,15 @@
#include "taosmsg.h"
#include "tglobal.h"
#include "trpc.h"
#include "mnode.h"
#include "dnode.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeVWrite.h"
#include "dnodeMRead.h"
#include "dnodeMWrite.h"
#include "mnode.h"
extern
void
dnodeUpdate
IpSet
(
SRpcIpSet
*
pIpSet
);
extern
void
dnodeUpdate
MnodeIpSetForPeer
(
SRpcIpSet
*
pIpSet
);
static
void
(
*
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessReqMsgFromDnode
(
SRpcMsg
*
pMsg
,
SRpcIpSet
*
);
static
void
(
*
dnodeProcessRspMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
rpcMsg
);
...
...
@@ -148,9 +148,10 @@ void dnodeCleanupClient() {
}
static
void
dnodeProcessRspFromDnode
(
SRpcMsg
*
pMsg
,
SRpcIpSet
*
pIpSet
)
{
if
(
dnodeProcessRspMsgFp
[
pMsg
->
msgType
])
{
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_DM_STATUS_RSP
&&
pIpSet
)
dnodeUpdateIpSet
(
pIpSet
);
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_DM_STATUS_RSP
&&
pIpSet
)
{
dnodeUpdateMnodeIpSetForPeer
(
pIpSet
);
}
(
*
dnodeProcessRspMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
dError
(
"RPC %p, msg:%s is not processed"
,
pMsg
->
handle
,
taosMsg
[
pMsg
->
msgType
]);
...
...
@@ -169,6 +170,6 @@ void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg) {
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
)
{
SRpcIpSet
ipSet
=
{
0
};
dnodeGetMnode
DnodeIpSet
(
&
ipSet
,
false
);
dnodeGetMnode
IpSetForPeer
(
&
ipSet
);
rpcSendRecv
(
tsDnodeClientRpc
,
&
ipSet
,
rpcMsg
,
rpcRsp
);
}
src/dnode/src/dnodeShell.c
浏览文件 @
cf687279
...
...
@@ -37,8 +37,6 @@ static void * tsDnodeShellRpc = NULL;
static
int32_t
tsDnodeQueryReqNum
=
0
;
static
int32_t
tsDnodeSubmitReqNum
=
0
;
void
mgmtProcessMsgFromShell
(
SRpcMsg
*
rpcMsg
);
int32_t
dnodeInitShell
()
{
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_SUBMIT
]
=
dnodeDispatchToVnodeWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_QUERY
]
=
dnodeDispatchToVnodeReadQueue
;
...
...
@@ -141,7 +139,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
}
static
int
dnodeRetrieveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int
code
=
m
gmt
RetriveAuth
(
user
,
spi
,
encrypt
,
secret
,
ckey
);
int
code
=
m
node
RetriveAuth
(
user
,
spi
,
encrypt
,
secret
,
ckey
);
if
(
code
!=
TSDB_CODE_NOT_READY
)
return
code
;
SDMAuthMsg
*
pMsg
=
rpcMallocCont
(
sizeof
(
SDMAuthMsg
));
...
...
src/dnode/src/dnodeVRead.c
浏览文件 @
cf687279
...
...
@@ -23,7 +23,7 @@
#include "twal.h"
#include "tglobal.h"
#include "dnodeInt.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
#include "dnodeVRead.h"
#include "vnode.h"
...
...
@@ -93,7 +93,7 @@ void dnodeCleanupVnodeRead() {
}
void
dnodeDispatchToVnodeReadQueue
(
SRpcMsg
*
pMsg
)
{
int32_t
queued
MsgNum
=
0
;
int32_t
mnode
MsgNum
=
0
;
int32_t
leftLen
=
pMsg
->
contLen
;
char
*
pCont
=
(
char
*
)
pMsg
->
pCont
;
void
*
pVnode
;
...
...
@@ -125,12 +125,12 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) {
// next vnode
leftLen
-=
pHead
->
contLen
;
pCont
-=
pHead
->
contLen
;
queued
MsgNum
++
;
mnode
MsgNum
++
;
taosWriteQitem
(
queue
,
TAOS_QTYPE_RPC
,
pRead
);
}
if
(
queued
MsgNum
==
0
)
{
if
(
mnode
MsgNum
==
0
)
{
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
...
...
src/dnode/src/dnodeVWrite.c
浏览文件 @
cf687279
...
...
@@ -27,7 +27,7 @@
#include "tdataformat.h"
#include "dnodeInt.h"
#include "dnodeVWrite.h"
#include "dnode
V
Mgmt.h"
#include "dnodeMgmt.h"
typedef
struct
{
taos_qall
qall
;
...
...
src/inc/dnode.h
浏览文件 @
cf687279
...
...
@@ -43,16 +43,21 @@ void *dnodeAllocateRqueue(void *pVnode);
void
dnodeFreeRqueue
(
void
*
rqueue
);
void
dnodeSendRpcWriteRsp
(
void
*
pVnode
,
void
*
param
,
int32_t
code
);
bool
dnodeIsFirstDeploy
();
char
*
dnodeGetMnodeMasterEp
();
void
dnodeGetMnodeDnodeIpSet
(
void
*
ipSet
,
bool
encode
);
void
*
dnodeGetMnodeInfos
();
int32_t
dnodeGetDnodeId
();
void
dnodeAddClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
dnodeAddServerMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
dnodeSendMsgToDnode
(
SRpcIpSet
*
ipSet
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
);
bool
dnodeIsFirstDeploy
();
char
*
dnodeGetMnodeMasterEp
();
void
dnodeGetMnodeIpSetForPeer
(
void
*
ipSet
);
void
dnodeGetMnodeIpSetForShell
(
void
*
ipSet
);
void
*
dnodeGetMnodeInfos
();
int32_t
dnodeGetDnodeId
();
void
dnodeAddClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
dnodeAddServerMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
dnodeSendMsgToDnode
(
SRpcIpSet
*
ipSet
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
);
void
dnodeSendRpcMnodeWriteRsp
(
void
*
pMsg
,
int32_t
code
);
void
dnodeReprocessMnodeWriteMsg
(
void
*
pMsg
);
void
dnodeDelayReprocessMnodeWriteMsg
(
void
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/inc/mnode.h
浏览文件 @
cf687279
...
...
@@ -13,44 +13,62 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_H
#define TDENGINE_M
GMT
_H
#ifndef TDENGINE_M
NODE
_H
#define TDENGINE_M
NODE
_H
#ifdef __cplusplus
extern
"C"
{
#endif
struct
SAcctObj
;
struct
SDnodeObj
;
struct
SUserObj
;
struct
SDbObj
;
struct
SVgObj
;
struct
STableObj
;
struct
SRpcMsg
;
typedef
struct
{
int
len
;
int
code
;
void
*
rsp
;
}
SMnodeRsp
;
typedef
struct
{
SRpcMsg
rpcMsg
;
typedef
struct
SMnodeMsg
{
SMnodeRsp
rpcRsp
;
uint8_t
msgType
;
int8_t
received
;
int8_t
successed
;
int8_t
expected
;
int8_t
retry
;
int8_t
maxRetry
;
int32_t
contLen
;
int32_t
code
;
void
*
ahandle
;
void
*
thandle
;
void
*
pCont
;
struct
SAcctObj
*
pAcct
;
struct
SDnodeObj
*
pDnode
;
struct
SUserObj
*
pUser
;
struct
SDbObj
*
pDb
;
struct
SVgObj
*
pVgroup
;
struct
STableObj
*
pTable
;
}
SMnodeMsg
;
SMnodeMsg
*
mnodeCreateMsg
(
SRpcMsg
*
rpcMsg
);
bool
mnodeInitMsg
(
SMnodeMsg
*
pMsg
);
void
mnodeRlease
Msg
(
SMnodeMsg
*
pMsg
);
void
mnodeCreateMsg
(
SMnodeMsg
*
pMsg
,
struct
SRpcMsg
*
rpcMsg
);
int32_t
mnodeInitMsg
(
SMnodeMsg
*
pMsg
);
void
mnodeCleanup
Msg
(
SMnodeMsg
*
pMsg
);
int32_t
m
gmt
InitSystem
();
int32_t
m
gmt
StartSystem
();
void
m
gmtCleanU
pSystem
();
int32_t
m
node
InitSystem
();
int32_t
m
node
StartSystem
();
void
m
nodeCleanu
pSystem
();
void
mgmtStopSystem
();
void
sdbUpdateSync
();
void
*
mnodeGetRqueue
(
void
*
);
void
*
mnodeGetWqueue
(
int32_t
vgId
);
bool
mnodeIsRunning
();
int32_t
mnodeProcessRead
(
SMnodeMsg
*
pMsg
);
int32_t
mnodeProcessWrite
(
SMnodeMsg
*
pMsg
);
int32_t
mnodeProcessMgmt
(
SMnodeMsg
*
pMsg
);
int32_t
mgmtRetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
void
mgmtProcessMsgFromShell
(
SRpcMsg
*
rpcMsg
);
void
mgmtProcessReqMsgFromDnode
(
SRpcMsg
*
rpcMsg
);
int32_t
mnodeProcessPeerReq
(
SMnodeMsg
*
pMsg
);
void
mnodeProcessPeerRsp
(
struct
SRpcMsg
*
pMsg
);
int32_t
mnodeRetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
#ifdef __cplusplus
}
...
...
src/inc/taosmsg.h
浏览文件 @
cf687279
...
...
@@ -121,23 +121,23 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY14, "dummy14" )
#define TSDB_IE_TYPE_DNODE_STATE 7
enum
_mgmt_table
{
TSDB_M
NODE
_TABLE_ACCT
,
TSDB_M
NODE
_TABLE_USER
,
TSDB_M
NODE
_TABLE_DB
,
TSDB_M
NODE
_TABLE_TABLE
,
TSDB_M
NODE
_TABLE_DNODE
,
TSDB_M
NODE
_TABLE_MNODE
,
TSDB_M
NODE
_TABLE_VGROUP
,
TSDB_M
NODE
_TABLE_METRIC
,
TSDB_M
NODE
_TABLE_MODULE
,
TSDB_M
NODE
_TABLE_QUERIES
,
TSDB_M
NODE
_TABLE_STREAMS
,
TSDB_M
NODE
_TABLE_CONFIGS
,
TSDB_M
NODE
_TABLE_CONNS
,
TSDB_M
NODE
_TABLE_SCORES
,
TSDB_M
NODE
_TABLE_GRANTS
,
TSDB_M
NODE
_TABLE_VNODES
,
TSDB_M
NODE
_TABLE_MAX
,
TSDB_M
GMT
_TABLE_ACCT
,
TSDB_M
GMT
_TABLE_USER
,
TSDB_M
GMT
_TABLE_DB
,
TSDB_M
GMT
_TABLE_TABLE
,
TSDB_M
GMT
_TABLE_DNODE
,
TSDB_M
GMT
_TABLE_MNODE
,
TSDB_M
GMT
_TABLE_VGROUP
,
TSDB_M
GMT
_TABLE_METRIC
,
TSDB_M
GMT
_TABLE_MODULE
,
TSDB_M
GMT
_TABLE_QUERIES
,
TSDB_M
GMT
_TABLE_STREAMS
,
TSDB_M
GMT
_TABLE_CONFIGS
,
TSDB_M
GMT
_TABLE_CONNS
,
TSDB_M
GMT
_TABLE_SCORES
,
TSDB_M
GMT
_TABLE_GRANTS
,
TSDB_M
GMT
_TABLE_VNODES
,
TSDB_M
GMT
_TABLE_MAX
,
};
#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1
...
...
src/inc/tbalance.h
浏览文件 @
cf687279
...
...
@@ -26,7 +26,7 @@ struct SDnodeObj;
int32_t
balanceInit
();
void
balanceCleanUp
();
void
balanceNotify
();
void
balanceUpdateM
gmt
();
void
balanceUpdateM
node
();
void
balanceReset
();
int32_t
balanceAllocVnodes
(
struct
SVgObj
*
pVgroup
);
int32_t
balanceDropDnode
(
struct
SDnodeObj
*
pDnode
);
...
...
src/inc/trpc.h
浏览文件 @
cf687279
...
...
@@ -28,21 +28,21 @@ extern "C" {
extern
int
tsRpcHeadSize
;
typedef
struct
{
typedef
struct
SRpcIpSet
{
int8_t
inUse
;
int8_t
numOfIps
;
uint16_t
port
[
TSDB_MAX_REPLICA
];
char
fqdn
[
TSDB_MAX_REPLICA
][
TSDB_FQDN_LEN
];
}
SRpcIpSet
;
typedef
struct
{
typedef
struct
SRpcConnInfo
{
uint32_t
clientIp
;
uint16_t
clientPort
;
uint32_t
serverIp
;
char
user
[
TSDB_USER_LEN
];
}
SRpcConnInfo
;
typedef
struct
{
typedef
struct
SRpcMsg
{
uint8_t
msgType
;
void
*
pCont
;
int
contLen
;
...
...
@@ -51,7 +51,7 @@ typedef struct {
void
*
ahandle
;
//app handle set by client, for debug purpose
}
SRpcMsg
;
typedef
struct
{
typedef
struct
SRpcInit
{
uint16_t
localPort
;
// local port
char
*
label
;
// for debug purpose
int
numOfThreads
;
// number of threads to handle connections
...
...
src/mnode/inc/mnodeAcct.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_ACCT_H
#define TDENGINE_M
GMT
_ACCT_H
#ifndef TDENGINE_M
NODE
_ACCT_H
#define TDENGINE_M
NODE
_ACCT_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -22,16 +22,16 @@ extern "C" {
#include "tacct.h"
int32_t
m
gmt
InitAccts
();
void
m
gmtCleanU
pAccts
();
void
*
m
gmt
GetAcct
(
char
*
acctName
);
void
*
m
gmt
GetNextAcct
(
void
*
pIter
,
SAcctObj
**
pAcct
);
void
m
gmt
IncAcctRef
(
SAcctObj
*
pAcct
);
void
m
gmt
DecAcctRef
(
SAcctObj
*
pAcct
);
void
m
gmt
AddDbToAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
void
m
gmt
DropDbFromAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
void
m
gmt
AddUserToAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
);
void
m
gmt
DropUserFromAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
);
int32_t
m
node
InitAccts
();
void
m
nodeCleanu
pAccts
();
void
*
m
node
GetAcct
(
char
*
acctName
);
void
*
m
node
GetNextAcct
(
void
*
pIter
,
SAcctObj
**
pAcct
);
void
m
node
IncAcctRef
(
SAcctObj
*
pAcct
);
void
m
node
DecAcctRef
(
SAcctObj
*
pAcct
);
void
m
node
AddDbToAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
void
m
node
DropDbFromAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
void
m
node
AddUserToAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
);
void
m
node
DropUserFromAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodeDb.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_DB_H
#define TDENGINE_M
GMT
_DB_H
#ifndef TDENGINE_M
NODE
_DB_H
#define TDENGINE_M
NODE
_DB_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -28,26 +28,26 @@ enum _TSDB_DB_STATUS {
};
// api
int32_t
m
gmt
InitDbs
();
void
m
gmtCleanU
pDbs
();
SDbObj
*
m
gmt
GetDb
(
char
*
db
);
SDbObj
*
m
gmt
GetDbByTableId
(
char
*
db
);
void
*
m
gmt
GetNextDb
(
void
*
pIter
,
SDbObj
**
pDb
);
void
m
gmt
IncDbRef
(
SDbObj
*
pDb
);
void
m
gmt
DecDbRef
(
SDbObj
*
pDb
);
bool
m
gmt
CheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
);
void
m
gmt
DropAllDbs
(
SAcctObj
*
pAcct
);
int32_t
m
node
InitDbs
();
void
m
nodeCleanu
pDbs
();
SDbObj
*
m
node
GetDb
(
char
*
db
);
SDbObj
*
m
node
GetDbByTableId
(
char
*
db
);
void
*
m
node
GetNextDb
(
void
*
pIter
,
SDbObj
**
pDb
);
void
m
node
IncDbRef
(
SDbObj
*
pDb
);
void
m
node
DecDbRef
(
SDbObj
*
pDb
);
bool
m
node
CheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
);
void
m
node
DropAllDbs
(
SAcctObj
*
pAcct
);
// util func
void
m
gmt
AddSuperTableIntoDb
(
SDbObj
*
pDb
);
void
m
gmt
RemoveSuperTableFromDb
(
SDbObj
*
pDb
);
void
m
gmt
AddTableIntoDb
(
SDbObj
*
pDb
);
void
m
gmt
RemoveTableFromDb
(
SDbObj
*
pDb
);
void
m
gmt
AddVgroupIntoDb
(
SVgObj
*
pVgroup
);
void
m
gmt
AddVgroupIntoDbTail
(
SVgObj
*
pVgroup
);
void
m
gmt
RemoveVgroupFromDb
(
SVgObj
*
pVgroup
);
void
m
gmt
MoveVgroupToTail
(
SVgObj
*
pVgroup
);
void
m
gmt
MoveVgroupToHead
(
SVgObj
*
pVgroup
);
void
m
node
AddSuperTableIntoDb
(
SDbObj
*
pDb
);
void
m
node
RemoveSuperTableFromDb
(
SDbObj
*
pDb
);
void
m
node
AddTableIntoDb
(
SDbObj
*
pDb
);
void
m
node
RemoveTableFromDb
(
SDbObj
*
pDb
);
void
m
node
AddVgroupIntoDb
(
SVgObj
*
pVgroup
);
void
m
node
AddVgroupIntoDbTail
(
SVgObj
*
pVgroup
);
void
m
node
RemoveVgroupFromDb
(
SVgObj
*
pVgroup
);
void
m
node
MoveVgroupToTail
(
SVgObj
*
pVgroup
);
void
m
node
MoveVgroupToHead
(
SVgObj
*
pVgroup
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodeDef.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_DEF_H
#define TDENGINE_M
GMT
_DEF_H
#ifndef TDENGINE_M
NODE
_DEF_H
#define TDENGINE_M
NODE
_DEF_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -65,7 +65,7 @@ typedef struct SMnodeObj {
int8_t
role
;
}
SMnodeObj
;
typedef
struct
{
typedef
struct
STableObj
{
char
*
tableId
;
int8_t
type
;
}
STableObj
;
...
...
@@ -233,26 +233,6 @@ typedef struct {
char
payload
[];
}
SShowObj
;
typedef
struct
{
uint8_t
msgType
;
int8_t
received
;
int8_t
successed
;
int8_t
expected
;
int8_t
retry
;
int8_t
maxRetry
;
int32_t
contLen
;
int32_t
code
;
void
*
ahandle
;
void
*
thandle
;
void
*
pCont
;
SAcctObj
*
pAcct
;
SDnodeObj
*
pDnode
;
SUserObj
*
pUser
;
SDbObj
*
pDb
;
SVgObj
*
pVgroup
;
STableObj
*
pTable
;
}
SMnodeMsg
;
#ifdef __cplusplus
}
#endif
...
...
src/mnode/inc/mnodeDnode.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_
CLUSTER
_H
#define TDENGINE_
CLUSTER
_H
#ifndef TDENGINE_
MNODE_DNODE
_H
#define TDENGINE_
MNODE_DNODE
_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -27,21 +27,21 @@ typedef enum {
TAOS_DN_STATUS_READY
}
EDnodeStatus
;
int32_t
m
gmt
InitDnodes
();
int32_t
m
node
InitDnodes
();
void
mgmtCleanupDnodes
();
char
*
m
gmt
GetDnodeStatusStr
(
int32_t
dnodeStatus
);
char
*
m
node
GetDnodeStatusStr
(
int32_t
dnodeStatus
);
void
mgmtMonitorDnodeModule
();
int32_t
m
gmt
GetDnodesNum
();
int32_t
m
gmt
GetOnlinDnodesNum
();
void
*
m
gmt
GetNextDnode
(
void
*
pIter
,
SDnodeObj
**
pDnode
);
void
m
gmt
IncDnodeRef
(
SDnodeObj
*
pDnode
);
void
m
gmt
DecDnodeRef
(
SDnodeObj
*
pDnode
);
void
*
m
gmt
GetDnode
(
int32_t
dnodeId
);
void
*
m
gmt
GetDnodeByEp
(
char
*
ep
);
void
m
gmt
UpdateDnode
(
SDnodeObj
*
pDnode
);
int32_t
m
gmt
DropDnode
(
SDnodeObj
*
pDnode
);
int32_t
m
node
GetDnodesNum
();
int32_t
m
node
GetOnlinDnodesNum
();
void
*
m
node
GetNextDnode
(
void
*
pIter
,
SDnodeObj
**
pDnode
);
void
m
node
IncDnodeRef
(
SDnodeObj
*
pDnode
);
void
m
node
DecDnodeRef
(
SDnodeObj
*
pDnode
);
void
*
m
node
GetDnode
(
int32_t
dnodeId
);
void
*
m
node
GetDnodeByEp
(
char
*
ep
);
void
m
node
UpdateDnode
(
SDnodeObj
*
pDnode
);
int32_t
m
node
DropDnode
(
SDnodeObj
*
pDnode
);
extern
int32_t
tsAccessSquence
;
...
...
src/mnode/inc/mnodeInt.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_LOG_H
#define TDENGINE_M
GMT
_LOG_H
#ifndef TDENGINE_M
NODE
_LOG_H
#define TDENGINE_M
NODE
_LOG_H
#ifdef __cplusplus
extern
"C"
{
...
...
src/mnode/inc/mnodeMnode.h
浏览文件 @
cf687279
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_MNODE_H
#define TDENGINE_M
GMT
_MNODE_H
#ifndef TDENGINE_M
NODE
_MNODE_H
#define TDENGINE_M
NODE
_MNODE_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -28,25 +28,25 @@ typedef enum {
TAOS_MN_STATUS_READY
}
EMnodeStatus
;
int32_t
m
gmt
InitMnodes
();
int32_t
m
node
InitMnodes
();
void
mgmtCleanupMnodes
();
int32_t
m
gmt
AddMnode
(
int32_t
dnodeId
);
int32_t
m
gmt
DropMnode
(
int32_t
dnodeId
);
void
m
gmt
DropMnodeLocal
(
int32_t
dnodeId
);
int32_t
m
node
AddMnode
(
int32_t
dnodeId
);
int32_t
m
node
DropMnode
(
int32_t
dnodeId
);
void
m
node
DropMnodeLocal
(
int32_t
dnodeId
);
void
*
m
gmt
GetMnode
(
int32_t
mnodeId
);
int32_t
m
gmt
GetMnodesNum
();
void
*
m
gmt
GetNextMnode
(
void
*
pIter
,
struct
SMnodeObj
**
pMnode
);
void
m
gmt
IncMnodeRef
(
struct
SMnodeObj
*
pMnode
);
void
m
gmt
DecMnodeRef
(
struct
SMnodeObj
*
pMnode
);
void
*
m
node
GetMnode
(
int32_t
mnodeId
);
int32_t
m
node
GetMnodesNum
();
void
*
m
node
GetNextMnode
(
void
*
pIter
,
struct
SMnodeObj
**
pMnode
);
void
m
node
IncMnodeRef
(
struct
SMnodeObj
*
pMnode
);
void
m
node
DecMnodeRef
(
struct
SMnodeObj
*
pMnode
);
char
*
m
gmt
GetMnodeRoleStr
();
void
m
gmt
GetMnodeIpSetForPeer
(
SRpcIpSet
*
ipSet
);
void
m
gmt
GetMnodeIpSetForShell
(
SRpcIpSet
*
ipSet
);
char
*
m
node
GetMnodeRoleStr
();
void
m
node
GetMnodeIpSetForPeer
(
SRpcIpSet
*
ipSet
);
void
m
node
GetMnodeIpSetForShell
(
SRpcIpSet
*
ipSet
);
void
m
gmt
GetMnodeInfos
(
void
*
mnodes
);
void
m
gmt
UpdateMnodeIpSet
();
void
m
node
GetMnodeInfos
(
void
*
mnodes
);
void
m
node
UpdateMnodeIpSet
();
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodePeer.h
0 → 100644
浏览文件 @
cf687279
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_MNODE_PEER_H
#define TDENGINE_MNODE_PEER_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
void
mnodeAddPeerRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
mnodeAddPeerMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
mnodeMsg
));
int32_t
mnodeProcessPeerReq
(
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
#endif
#endif
src/mnode/inc/mnodeProfile.h
浏览文件 @
cf687279
...
...
@@ -13,16 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_PROFILE_H
#define TDENGINE_M
GMT
_PROFILE_H
#ifndef TDENGINE_M
NODE
_PROFILE_H
#define TDENGINE_M
NODE
_PROFILE_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
m
gmt
InitProfile
();
void
m
gmtCleanU
pProfile
();
int32_t
m
node
InitProfile
();
void
m
nodeCleanu
pProfile
();
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnode
Server
.h
→
src/mnode/inc/mnode
Read
.h
浏览文件 @
cf687279
...
...
@@ -13,15 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT_DSERVER
_H
#define TDENGINE_M
GMT_DSERVER
_H
#ifndef TDENGINE_M
NODE_READ
_H
#define TDENGINE_M
NODE_READ
_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
mnodeInitMgmt
(
);
void
mgmtCleanupMgmt
(
);
void
mnodeAddReadMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
mnodeMsg
)
);
int32_t
mnodeProcessRead
(
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodeSh
ell
.h
→
src/mnode/inc/mnodeSh
ow
.h
浏览文件 @
cf687279
...
...
@@ -13,35 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_SHELL_H
#define TDENGINE_M
GMT
_SHELL_H
#ifndef TDENGINE_M
NODE
_SHELL_H
#define TDENGINE_M
NODE
_SHELL_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
mgmtInitShell
();
void
mgmtCleanUpShell
();
void
mgmtAddShellMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SMnodeMsg
*
queuedMsg
));
int32_t
mnodeInitShow
();
void
mnodeCleanUpShow
();
typedef
int32_t
(
*
SShowMetaFp
)(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
typedef
int32_t
(
*
SShowRetrieveFp
)(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
void
mnodeAddShowMetaHandle
(
uint8_t
showType
,
SShowMetaFp
fp
);
void
mnodeAddShowRetrieveHandle
(
uint8_t
showType
,
SShowRetrieveFp
fp
);
void
mgmtAddToShellQueue
(
SMnodeMsg
*
queuedMsg
);
void
mgmtDealyedAddToShellQueue
(
SMnodeMsg
*
queuedMsg
);
void
mgmtSendSimpleResp
(
void
*
thandle
,
int32_t
code
);
bool
mgmtCheckQhandle
(
uint64_t
qhandle
);
void
*
mgmtSaveQhandle
(
void
*
qhandle
,
int32_t
size
);
void
mgmtFreeQhandle
(
void
*
qhandle
,
bool
forceRemove
);
void
*
mgmtMallocQueuedMsg
(
SRpcMsg
*
rpcMsg
);
void
*
mgmtCloneQueuedMsg
(
SMnodeMsg
*
pSrcMsg
);
void
mgmtFreeQueuedMsg
(
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
src/mnode/inc/mnodeTable.h
浏览文件 @
cf687279
...
...
@@ -22,16 +22,16 @@ extern "C" {
#include "mnodeDef.h"
int32_t
m
gmt
InitTables
();
void
m
gmtCleanU
pTables
();
void
*
m
gmt
GetTable
(
char
*
tableId
);
void
m
gmt
IncTableRef
(
void
*
pTable
);
void
m
gmt
DecTableRef
(
void
*
pTable
);
void
*
m
gmt
GetNextChildTable
(
void
*
pIter
,
SChildTableObj
**
pTable
);
void
*
m
gmt
GetNextSuperTable
(
void
*
pIter
,
SSuperTableObj
**
pTable
);
void
m
gmt
DropAllChildTables
(
SDbObj
*
pDropDb
);
void
m
gmt
DropAllSuperTables
(
SDbObj
*
pDropDb
);
void
m
gmt
DropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
);
int32_t
m
node
InitTables
();
void
m
nodeCleanu
pTables
();
void
*
m
node
GetTable
(
char
*
tableId
);
void
m
node
IncTableRef
(
void
*
pTable
);
void
m
node
DecTableRef
(
void
*
pTable
);
void
*
m
node
GetNextChildTable
(
void
*
pIter
,
SChildTableObj
**
pTable
);
void
*
m
node
GetNextSuperTable
(
void
*
pIter
,
SSuperTableObj
**
pTable
);
void
m
node
DropAllChildTables
(
SDbObj
*
pDropDb
);
void
m
node
DropAllSuperTables
(
SDbObj
*
pDropDb
);
void
m
node
DropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodeUser.h
浏览文件 @
cf687279
...
...
@@ -13,23 +13,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_USER_H
#define TDENGINE_M
GMT
_USER_H
#ifndef TDENGINE_M
NODE
_USER_H
#define TDENGINE_M
NODE
_USER_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
m
gmt
InitUsers
();
void
m
gmtCleanU
pUsers
();
SUserObj
*
m
gmt
GetUser
(
char
*
name
);
void
*
m
gmt
GetNextUser
(
void
*
pIter
,
SUserObj
**
pUser
);
void
m
gmt
IncUserRef
(
SUserObj
*
pUser
);
void
m
gmt
DecUserRef
(
SUserObj
*
pUser
);
SUserObj
*
m
gmt
GetUserFromConn
(
void
*
pConn
);
int32_t
m
gmt
CreateUser
(
SAcctObj
*
pAcct
,
char
*
name
,
char
*
pass
);
void
m
gmt
DropAllUsers
(
SAcctObj
*
pAcct
);
int32_t
m
node
InitUsers
();
void
m
nodeCleanu
pUsers
();
SUserObj
*
m
node
GetUser
(
char
*
name
);
void
*
m
node
GetNextUser
(
void
*
pIter
,
SUserObj
**
pUser
);
void
m
node
IncUserRef
(
SUserObj
*
pUser
);
void
m
node
DecUserRef
(
SUserObj
*
pUser
);
SUserObj
*
m
node
GetUserFromConn
(
void
*
pConn
);
int32_t
m
node
CreateUser
(
SAcctObj
*
pAcct
,
char
*
name
,
char
*
pass
);
void
m
node
DropAllUsers
(
SAcctObj
*
pAcct
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnodeVgroup.h
浏览文件 @
cf687279
...
...
@@ -13,41 +13,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT
_VGROUP_H
#define TDENGINE_M
GMT
_VGROUP_H
#ifndef TDENGINE_M
NODE
_VGROUP_H
#define TDENGINE_M
NODE
_VGROUP_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
m
gmt
InitVgroups
();
void
m
gmtCleanU
pVgroups
();
SVgObj
*
m
gmt
GetVgroup
(
int32_t
vgId
);
void
m
gmt
IncVgroupRef
(
SVgObj
*
pVgroup
);
void
m
gmt
DecVgroupRef
(
SVgObj
*
pVgroup
);
void
m
gmt
DropAllDbVgroups
(
SDbObj
*
pDropDb
,
bool
sendMsg
);
void
m
gmt
DropAllDnodeVgroups
(
SDnodeObj
*
pDropDnode
);
void
m
gmt
UpdateAllDbVgroups
(
SDbObj
*
pAlterDb
);
void
*
m
gmt
GetNextVgroup
(
void
*
pIter
,
SVgObj
**
pVgroup
);
void
m
gmt
UpdateVgroup
(
SVgObj
*
pVgroup
);
void
m
gmt
UpdateVgroupStatus
(
SVgObj
*
pVgroup
,
SDnodeObj
*
dnodeId
,
SVnodeLoad
*
pVload
);
void
mgmtCreateVgroup
(
SMnodeMsg
*
pMsg
,
SDbObj
*
pDb
);
void
m
gmt
DropVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
void
m
gmt
AlterVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
SVgObj
*
m
gmt
GetAvailableVgroup
(
SDbObj
*
pDb
);
void
m
gmt
AddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
);
void
m
gmt
RemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
);
void
m
gmt
SendCreateVnodeMsg
(
SVgObj
*
pVgroup
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
void
m
gmt
SendDropVnodeMsg
(
int32_t
vgId
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
void
m
gmt
SendCreateVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
SRpcIpSet
m
gmt
GetIpSetFromVgroup
(
SVgObj
*
pVgroup
);
SRpcIpSet
m
gmt
GetIpSetFromIp
(
char
*
ep
);
struct
SMnodeMsg
;
int32_t
m
node
InitVgroups
();
void
m
nodeCleanu
pVgroups
();
SVgObj
*
m
node
GetVgroup
(
int32_t
vgId
);
void
m
node
IncVgroupRef
(
SVgObj
*
pVgroup
);
void
m
node
DecVgroupRef
(
SVgObj
*
pVgroup
);
void
m
node
DropAllDbVgroups
(
SDbObj
*
pDropDb
,
bool
sendMsg
);
void
m
node
DropAllDnodeVgroups
(
SDnodeObj
*
pDropDnode
);
void
m
node
UpdateAllDbVgroups
(
SDbObj
*
pAlterDb
);
void
*
m
node
GetNextVgroup
(
void
*
pIter
,
SVgObj
**
pVgroup
);
void
m
node
UpdateVgroup
(
SVgObj
*
pVgroup
);
void
m
node
UpdateVgroupStatus
(
SVgObj
*
pVgroup
,
SDnodeObj
*
dnodeId
,
SVnodeLoad
*
pVload
);
int32_t
mnodeCreateVgroup
(
struct
SMnodeMsg
*
pMsg
,
SDbObj
*
pDb
);
void
m
node
DropVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
void
m
node
AlterVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
SVgObj
*
m
node
GetAvailableVgroup
(
SDbObj
*
pDb
);
void
m
node
AddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
);
void
m
node
RemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
);
void
m
node
SendCreateVnodeMsg
(
SVgObj
*
pVgroup
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
void
m
node
SendDropVnodeMsg
(
int32_t
vgId
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
void
m
node
SendCreateVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
SRpcIpSet
m
node
GetIpSetFromVgroup
(
SVgObj
*
pVgroup
);
SRpcIpSet
m
node
GetIpSetFromIp
(
char
*
ep
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mnode
DClient
.h
→
src/mnode/inc/mnode
Write
.h
浏览文件 @
cf687279
...
...
@@ -13,17 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_M
GMT_DCLIENT
_H
#define TDENGINE_M
GMT_DCLIENT
_H
#ifndef TDENGINE_M
NODE_WRITE
_H
#define TDENGINE_M
NODE_WRITE
_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
mgmtInitDClient
();
void
mgmtCleanupDClient
();
void
mgmtAddDClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
mgmtSendMsgToDnode
(
SRpcIpSet
*
ipSet
,
SRpcMsg
*
rpcMsg
);
void
mnodeAddWriteMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
mnodeMsg
));
int32_t
mnodeProcessRead
(
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/mnode/src/mnodeAcct.c
浏览文件 @
cf687279
...
...
@@ -17,7 +17,6 @@
#include "os.h"
#include "taoserror.h"
#include "ttime.h"
#include "tutil.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
...
...
@@ -28,48 +27,48 @@
void
*
tsAcctSdb
=
NULL
;
static
int32_t
tsAcctUpdateSize
;
static
void
m
gmt
CreateRootAcct
();
static
void
m
node
CreateRootAcct
();
static
int32_t
m
gmtActionAcct
Destroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
nodeAcctAction
Destroy
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
pthread_mutex_destroy
(
&
pAcct
->
mutex
);
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
AcctActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
AcctActionInsert
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
memset
(
&
pAcct
->
acctInfo
,
0
,
sizeof
(
SAcctInfo
));
pthread_mutex_init
(
&
pAcct
->
mutex
,
NULL
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmtActionAcct
Delete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
nodeAcctAction
Delete
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
m
gmt
DropAllUsers
(
pAcct
);
m
gmt
DropAllDbs
(
pAcct
);
m
node
DropAllUsers
(
pAcct
);
m
node
DropAllDbs
(
pAcct
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmtActionAcct
Update
(
SSdbOper
*
pOper
)
{
static
int32_t
m
nodeAcctAction
Update
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
SAcctObj
*
pSaved
=
m
gmt
GetAcct
(
pAcct
->
user
);
SAcctObj
*
pSaved
=
m
node
GetAcct
(
pAcct
->
user
);
if
(
pAcct
!=
pSaved
)
{
memcpy
(
pSaved
,
pAcct
,
tsAcctUpdateSize
);
free
(
pAcct
);
}
m
gmt
DecAcctRef
(
pSaved
);
m
node
DecAcctRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ActionActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ActionActionEncode
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pAcct
,
tsAcctUpdateSize
);
pOper
->
rowSize
=
tsAcctUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmtActionAcct
Decode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
nodeAcctAction
Decode
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
(
SAcctObj
*
)
calloc
(
1
,
sizeof
(
SAcctObj
));
if
(
pAcct
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -78,16 +77,16 @@ static int32_t mgmtActionAcctDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmtActionAcct
Restored
()
{
static
int32_t
m
nodeAcctAction
Restored
()
{
if
(
dnodeIsFirstDeploy
())
{
m
gmt
CreateRootAcct
();
m
node
CreateRootAcct
();
}
acctInit
();
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
InitAccts
()
{
int32_t
m
node
InitAccts
()
{
SAcctObj
tObj
;
tsAcctUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -98,13 +97,13 @@ int32_t mgmtInitAccts() {
.
maxRowSize
=
tsAcctUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
m
gmt
AcctActionInsert
,
.
deleteFp
=
m
gmtActionAcct
Delete
,
.
updateFp
=
m
gmtActionAcct
Update
,
.
encodeFp
=
m
gmt
ActionActionEncode
,
.
decodeFp
=
m
gmtActionAcct
Decode
,
.
destroyFp
=
m
gmtActionAcct
Destroy
,
.
restoredFp
=
m
gmtActionAcct
Restored
.
insertFp
=
m
node
AcctActionInsert
,
.
deleteFp
=
m
nodeAcctAction
Delete
,
.
updateFp
=
m
nodeAcctAction
Update
,
.
encodeFp
=
m
node
ActionActionEncode
,
.
decodeFp
=
m
nodeAcctAction
Decode
,
.
destroyFp
=
m
nodeAcctAction
Destroy
,
.
restoredFp
=
m
nodeAcctAction
Restored
};
tsAcctSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -117,52 +116,52 @@ int32_t mgmtInitAccts() {
return
TSDB_CODE_SUCCESS
;
}
void
m
gmtCleanU
pAccts
()
{
void
m
nodeCleanu
pAccts
()
{
sdbCloseTable
(
tsAcctSdb
);
acctCleanUp
();
}
void
*
m
gmt
GetAcct
(
char
*
name
)
{
void
*
m
node
GetAcct
(
char
*
name
)
{
return
sdbGetRow
(
tsAcctSdb
,
name
);
}
void
*
m
gmt
GetNextAcct
(
void
*
pIter
,
SAcctObj
**
pAcct
)
{
void
*
m
node
GetNextAcct
(
void
*
pIter
,
SAcctObj
**
pAcct
)
{
return
sdbFetchRow
(
tsAcctSdb
,
pIter
,
(
void
**
)
pAcct
);
}
void
m
gmt
IncAcctRef
(
SAcctObj
*
pAcct
)
{
void
m
node
IncAcctRef
(
SAcctObj
*
pAcct
)
{
sdbIncRef
(
tsAcctSdb
,
pAcct
);
}
void
m
gmt
DecAcctRef
(
SAcctObj
*
pAcct
)
{
void
m
node
DecAcctRef
(
SAcctObj
*
pAcct
)
{
sdbDecRef
(
tsAcctSdb
,
pAcct
);
}
void
m
gmt
AddDbToAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
void
m
node
AddDbToAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pAcct
->
acctInfo
.
numOfDbs
,
1
);
pDb
->
pAcct
=
pAcct
;
m
gmt
IncAcctRef
(
pAcct
);
m
node
IncAcctRef
(
pAcct
);
}
void
m
gmt
DropDbFromAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
void
m
node
DropDbFromAcct
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
atomic_sub_fetch_32
(
&
pAcct
->
acctInfo
.
numOfDbs
,
1
);
pDb
->
pAcct
=
NULL
;
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
void
m
gmt
AddUserToAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
void
m
node
AddUserToAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
atomic_add_fetch_32
(
&
pAcct
->
acctInfo
.
numOfUsers
,
1
);
pUser
->
pAcct
=
pAcct
;
m
gmt
IncAcctRef
(
pAcct
);
m
node
IncAcctRef
(
pAcct
);
}
void
m
gmt
DropUserFromAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
void
m
node
DropUserFromAcct
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
atomic_sub_fetch_32
(
&
pAcct
->
acctInfo
.
numOfUsers
,
1
);
pUser
->
pAcct
=
NULL
;
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
static
void
m
gmt
CreateRootAcct
()
{
static
void
m
node
CreateRootAcct
()
{
int32_t
numOfAccts
=
sdbGetNumOfRows
(
tsAcctSdb
);
if
(
numOfAccts
!=
0
)
return
;
...
...
src/mnode/src/mnodeBalance.c
浏览文件 @
cf687279
...
...
@@ -15,22 +15,18 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "trpc.h"
#include "tbalance.h"
#include "tglobal.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeMnode.h"
#include "mnodeDnode.h"
#include "mnodeSdb.h"
#include "mnodeVgroup.h"
#ifndef _SYNC
int32_t
balanceInit
()
{
return
TSDB_CODE_SUCCESS
;
}
void
balanceCleanUp
()
{}
void
balanceNotify
()
{}
void
balanceUpdateM
gmt
()
{}
void
balanceUpdateM
node
()
{}
void
balanceReset
()
{}
int32_t
balanceAllocVnodes
(
SVgObj
*
pVgroup
)
{
...
...
@@ -40,12 +36,12 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
float
vnodeUsage
=
1000
.
0
;
while
(
1
)
{
pIter
=
m
gmt
GetNextDnode
(
pIter
,
&
pDnode
);
pIter
=
m
node
GetNextDnode
(
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
->
totalVnodes
>
0
&&
pDnode
->
openVnodes
<
pDnode
->
totalVnodes
)
{
float
openVnodes
=
pDnode
->
openVnodes
;
if
(
pDnode
->
isMgmt
)
openVnodes
+=
tsM
gmt
EqualVnodeNum
;
if
(
pDnode
->
isMgmt
)
openVnodes
+=
tsM
node
EqualVnodeNum
;
float
usage
=
openVnodes
/
pDnode
->
totalVnodes
;
if
(
usage
<=
vnodeUsage
)
{
...
...
@@ -53,7 +49,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
vnodeUsage
=
usage
;
}
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
sdbFreeIter
(
pIter
);
...
...
src/mnode/src/mnodeDb.c
浏览文件 @
cf687279
此差异已折叠。
点击以展开。
src/mnode/src/mnodeDnode.c
浏览文件 @
cf687279
此差异已折叠。
点击以展开。
src/mnode/src/mnodeInt.c
0 → 100644
浏览文件 @
cf687279
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosmsg.h"
#include "taoserror.h"
#include "trpc.h"
#include "tcache.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "mnodeDb.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
#include "mnodeProfile.h"
#include "mnodeSdb.h"
#include "mnodeShow.h"
#include "mnodeTable.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
void
mnodeCreateMsg
(
SMnodeMsg
*
pMsg
,
SRpcMsg
*
rpcMsg
)
{
pMsg
->
thandle
=
rpcMsg
->
handle
;
pMsg
->
msgType
=
rpcMsg
->
msgType
;
pMsg
->
contLen
=
rpcMsg
->
contLen
;
pMsg
->
pCont
=
rpcMsg
->
pCont
;
}
int32_t
mnodeInitMsg
(
SMnodeMsg
*
pMsg
)
{
pMsg
->
pUser
=
mnodeGetUserFromConn
(
pMsg
->
thandle
);
if
(
pMsg
->
pUser
==
NULL
)
{
return
TSDB_CODE_INVALID_USER
;
}
return
TSDB_CODE_SUCCESS
;
}
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
if
(
pMsg
->
pCont
)
rpcFreeCont
(
pMsg
->
pCont
);
if
(
pMsg
->
pUser
)
mnodeDecUserRef
(
pMsg
->
pUser
);
if
(
pMsg
->
pDb
)
mnodeDecDbRef
(
pMsg
->
pDb
);
if
(
pMsg
->
pVgroup
)
mnodeDecVgroupRef
(
pMsg
->
pVgroup
);
if
(
pMsg
->
pTable
)
mnodeDecTableRef
(
pMsg
->
pTable
);
if
(
pMsg
->
pAcct
)
mnodeDecAcctRef
(
pMsg
->
pAcct
);
if
(
pMsg
->
pDnode
)
mnodeDecDnodeRef
(
pMsg
->
pDnode
);
}
}
src/mnode/src/mnodeMain.c
浏览文件 @
cf687279
...
...
@@ -24,7 +24,6 @@
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeServer.h"
#include "mnodeAcct.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
...
...
@@ -33,16 +32,16 @@
#include "mnodeVgroup.h"
#include "mnodeUser.h"
#include "mnodeTable.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
static
void
*
tsMgmt
Tmr
;
void
*
tsMnode
Tmr
;
static
bool
tsMgmtIsRunning
=
false
;
static
void
mnodeInitTimer
();
static
void
mnodeCleanupTimer
();
static
bool
mnodeNeedStart
()
;
int32_t
m
gmt
StartSystem
()
{
int32_t
m
node
StartSystem
()
{
if
(
tsMgmtIsRunning
)
{
mPrint
(
"TDengine mgmt module already started..."
);
return
0
;
...
...
@@ -54,37 +53,37 @@ int32_t mgmtStartSystem() {
mkdir
(
tsMnodeDir
,
0755
);
}
if
(
m
gmt
InitAccts
()
<
0
)
{
if
(
m
node
InitAccts
()
<
0
)
{
mError
(
"failed to init accts"
);
return
-
1
;
}
if
(
m
gmt
InitUsers
()
<
0
)
{
if
(
m
node
InitUsers
()
<
0
)
{
mError
(
"failed to init users"
);
return
-
1
;
}
if
(
m
gmt
InitDnodes
()
<
0
)
{
if
(
m
node
InitDnodes
()
<
0
)
{
mError
(
"failed to init dnodes"
);
return
-
1
;
}
if
(
m
gmt
InitDbs
()
<
0
)
{
if
(
m
node
InitDbs
()
<
0
)
{
mError
(
"failed to init dbs"
);
return
-
1
;
}
if
(
m
gmt
InitVgroups
()
<
0
)
{
if
(
m
node
InitVgroups
()
<
0
)
{
mError
(
"failed to init vgroups"
);
return
-
1
;
}
if
(
m
gmt
InitTables
()
<
0
)
{
if
(
m
node
InitTables
()
<
0
)
{
mError
(
"failed to init tables"
);
return
-
1
;
}
if
(
m
gmt
InitMnodes
()
<
0
)
{
if
(
m
node
InitMnodes
()
<
0
)
{
mError
(
"failed to init mnodes"
);
return
-
1
;
}
...
...
@@ -103,7 +102,8 @@ int32_t mgmtStartSystem() {
return
-
1
;
}
if
(
mnodeInitMgmt
()
<
0
)
{
if
(
mnodeInitShow
()
<
0
)
{
mError
(
"failed to init show"
);
return
-
1
;
}
...
...
@@ -115,39 +115,28 @@ int32_t mgmtStartSystem() {
return
0
;
}
int32_t
m
gmt
InitSystem
()
{
int32_t
m
node
InitSystem
()
{
mnodeInitTimer
();
mnodeInitRead
();
mnodeInitWrite
();
if
(
mnodeNeedStart
())
{
if
(
mgmtStartSystem
()
!=
0
)
{
return
-
1
;
}
}
return
0
;
if
(
!
mnodeNeedStart
())
return
0
;
return
mnodeStartSystem
();
}
void
m
gmtCleanU
pSystem
()
{
void
m
nodeCleanu
pSystem
()
{
mPrint
(
"starting to clean up mgmt"
);
tsMgmtIsRunning
=
false
;
mnodeCleanupTimer
();
mnodeCleanupRead
();
mnodeCleanupWrite
();
mgmtCleanupMgmt
();
mnodeCleanUpShow
();
grantCleanUp
();
balanceCleanUp
();
sdbCleanUp
();
mgmtCleanupMnodes
();
m
gmtCleanU
pTables
();
m
gmtCleanU
pVgroups
();
m
gmtCleanU
pDbs
();
m
nodeCleanu
pTables
();
m
nodeCleanu
pVgroups
();
m
nodeCleanu
pDbs
();
mgmtCleanupDnodes
();
m
gmtCleanU
pUsers
();
m
gmtCleanU
pAccts
();
m
nodeCleanu
pUsers
();
m
nodeCleanu
pAccts
();
mPrint
(
"mgmt is cleaned up"
);
}
...
...
@@ -157,31 +146,21 @@ void mgmtStopSystem() {
return
;
}
mgmtCleanUpSystem
();
mnodeCleanupSystem
();
mPrint
(
"mgmt file is removed"
);
remove
(
tsMnodeDir
);
}
void
*
mnodeGetWqueue
(
int32_t
vgId
)
{
}
static
void
mnodeInitTimer
()
{
if
(
tsM
gmt
Tmr
!=
NULL
)
{
tsM
gmt
Tmr
=
taosTmrInit
((
tsMaxShellConns
)
*
3
,
200
,
3600000
,
"MND"
);
if
(
tsM
node
Tmr
!=
NULL
)
{
tsM
node
Tmr
=
taosTmrInit
((
tsMaxShellConns
)
*
3
,
200
,
3600000
,
"MND"
);
}
}
static
void
mnodeCleanupTimer
()
{
if
(
tsM
gmt
Tmr
!=
NULL
)
{
taosTmrCleanUp
(
tsM
gmt
Tmr
);
tsM
gmt
Tmr
=
NULL
;
if
(
tsM
node
Tmr
!=
NULL
)
{
taosTmrCleanUp
(
tsM
node
Tmr
);
tsM
node
Tmr
=
NULL
;
}
}
...
...
@@ -196,3 +175,7 @@ static bool mnodeNeedStart() {
return
false
;
}
bool
mnodeIsRunning
()
{
return
tsMgmtIsRunning
;
}
\ No newline at end of file
src/mnode/src/mnodeMnode.c
浏览文件 @
cf687279
...
...
@@ -28,80 +28,80 @@
#include "mnodeMnode.h"
#include "mnodeDnode.h"
#include "mnodeSdb.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeUser.h"
static
void
*
tsMnodeSdb
=
NULL
;
static
int32_t
tsMnodeUpdateSize
=
0
;
static
int32_t
mgmtGetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
SRpcIpSet
tsMnodeRpcIpSet
;
static
void
*
tsMnodeSdb
=
NULL
;
static
int32_t
tsMnodeUpdateSize
=
0
;
static
SRpcIpSet
tsMnodeRpcIpSetForShell
;
static
SRpcIpSet
tsMnodeRpcIpSetForPeer
;
static
SDMMnodeInfos
tsMnodeInfos
;
static
int32_t
mnodeGetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
#if defined(LINUX)
static
pthread_rwlock_t
tsMnodeLock
;
#define m
gmt
MnodeWrLock() pthread_rwlock_wrlock(&tsMnodeLock)
#define m
gmt
MnodeRdLock() pthread_rwlock_rdlock(&tsMnodeLock)
#define m
gmt
MnodeUnLock() pthread_rwlock_unlock(&tsMnodeLock)
#define m
gmt
MnodeInitLock() pthread_rwlock_init(&tsMnodeLock, NULL)
#define m
gmt
MnodeDestroyLock() pthread_rwlock_destroy(&tsMnodeLock)
static
pthread_rwlock_t
tsMnodeLock
;
#define m
node
MnodeWrLock() pthread_rwlock_wrlock(&tsMnodeLock)
#define m
node
MnodeRdLock() pthread_rwlock_rdlock(&tsMnodeLock)
#define m
node
MnodeUnLock() pthread_rwlock_unlock(&tsMnodeLock)
#define m
node
MnodeInitLock() pthread_rwlock_init(&tsMnodeLock, NULL)
#define m
node
MnodeDestroyLock() pthread_rwlock_destroy(&tsMnodeLock)
#else
static
pthread_mutex_t
tsMnodeLock
;
#define m
gmt
MnodeWrLock() pthread_mutex_lock(&tsMnodeLock)
#define m
gmt
MnodeRdLock() pthread_mutex_lock(&tsMnodeLock)
#define m
gmt
MnodeUnLock() pthread_mutex_unlock(&tsMnodeLock)
#define m
gmt
MnodeInitLock() pthread_mutex_init(&tsMnodeLock, NULL)
#define m
gmt
MnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
static
pthread_mutex_t
tsMnodeLock
;
#define m
node
MnodeWrLock() pthread_mutex_lock(&tsMnodeLock)
#define m
node
MnodeRdLock() pthread_mutex_lock(&tsMnodeLock)
#define m
node
MnodeUnLock() pthread_mutex_unlock(&tsMnodeLock)
#define m
node
MnodeInitLock() pthread_mutex_init(&tsMnodeLock, NULL)
#define m
node
MnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
#endif
static
int32_t
m
gmt
MnodeActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionDestroy
(
SSdbOper
*
pOper
)
{
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionInsert
(
SSdbOper
*
pOper
)
{
SMnodeObj
*
pMnode
=
pOper
->
pObj
;
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
==
NULL
)
return
TSDB_CODE_DNODE_NOT_EXIST
;
pDnode
->
isMgmt
=
true
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionDelete
(
SSdbOper
*
pOper
)
{
SMnodeObj
*
pMnode
=
pOper
->
pObj
;
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
==
NULL
)
return
TSDB_CODE_DNODE_NOT_EXIST
;
pDnode
->
isMgmt
=
false
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
mTrace
(
"mnode:%d, is dropped from sdb"
,
pMnode
->
mnodeId
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionUpdate
(
SSdbOper
*
pOper
)
{
SMnodeObj
*
pMnode
=
pOper
->
pObj
;
SMnodeObj
*
pSaved
=
m
gmt
GetMnode
(
pMnode
->
mnodeId
);
SMnodeObj
*
pSaved
=
m
node
GetMnode
(
pMnode
->
mnodeId
);
if
(
pMnode
!=
pSaved
)
{
memcpy
(
pSaved
,
pMnode
,
pOper
->
rowSize
);
free
(
pMnode
);
}
m
gmt
DecMnodeRef
(
pSaved
);
m
node
DecMnodeRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionEncode
(
SSdbOper
*
pOper
)
{
SMnodeObj
*
pMnode
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pMnode
,
tsMnodeUpdateSize
);
pOper
->
rowSize
=
tsMnodeUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
MnodeActionDecode
(
SSdbOper
*
pOper
)
{
SMnodeObj
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnodeObj
));
if
(
pMnode
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -110,24 +110,24 @@ static int32_t mgmtMnodeActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
MnodeActionRestored
()
{
if
(
m
gmt
GetMnodesNum
()
==
1
)
{
static
int32_t
m
node
MnodeActionRestored
()
{
if
(
m
node
GetMnodesNum
()
==
1
)
{
SMnodeObj
*
pMnode
=
NULL
;
void
*
pIter
=
m
gmt
GetNextMnode
(
NULL
,
&
pMnode
);
void
*
pIter
=
m
node
GetNextMnode
(
NULL
,
&
pMnode
);
if
(
pMnode
!=
NULL
)
{
pMnode
->
role
=
TAOS_SYNC_ROLE_MASTER
;
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecMnodeRef
(
pMnode
);
}
sdbFreeIter
(
pIter
);
}
m
gmt
UpdateMnodeIpSet
();
m
node
UpdateMnodeIpSet
();
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
InitMnodes
()
{
m
gmt
MnodeInitLock
();
int32_t
m
node
InitMnodes
()
{
m
node
MnodeInitLock
();
SMnodeObj
tObj
;
tsMnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -139,13 +139,13 @@ int32_t mgmtInitMnodes() {
.
maxRowSize
=
tsMnodeUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_INT
,
.
insertFp
=
m
gmt
MnodeActionInsert
,
.
deleteFp
=
m
gmt
MnodeActionDelete
,
.
updateFp
=
m
gmt
MnodeActionUpdate
,
.
encodeFp
=
m
gmt
MnodeActionEncode
,
.
decodeFp
=
m
gmt
MnodeActionDecode
,
.
destroyFp
=
m
gmt
MnodeActionDestroy
,
.
restoredFp
=
m
gmt
MnodeActionRestored
.
insertFp
=
m
node
MnodeActionInsert
,
.
deleteFp
=
m
node
MnodeActionDelete
,
.
updateFp
=
m
node
MnodeActionUpdate
,
.
encodeFp
=
m
node
MnodeActionEncode
,
.
decodeFp
=
m
node
MnodeActionDecode
,
.
destroyFp
=
m
node
MnodeActionDestroy
,
.
restoredFp
=
m
node
MnodeActionRestored
};
tsMnodeSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -154,8 +154,8 @@ int32_t mgmtInitMnodes() {
return
-
1
;
}
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_MNODE
,
mgmt
GetMnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_MNODE
,
mgmt
RetrieveMnodes
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_MNODE
,
mnode
GetMnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_MNODE
,
mnode
RetrieveMnodes
);
mTrace
(
"table:mnodes table is created"
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -163,30 +163,30 @@ int32_t mgmtInitMnodes() {
void
mgmtCleanupMnodes
()
{
sdbCloseTable
(
tsMnodeSdb
);
m
gmt
MnodeDestroyLock
();
m
node
MnodeDestroyLock
();
}
int32_t
m
gmt
GetMnodesNum
()
{
int32_t
m
node
GetMnodesNum
()
{
return
sdbGetNumOfRows
(
tsMnodeSdb
);
}
void
*
m
gmt
GetMnode
(
int32_t
mnodeId
)
{
void
*
m
node
GetMnode
(
int32_t
mnodeId
)
{
return
sdbGetRow
(
tsMnodeSdb
,
&
mnodeId
);
}
void
m
gmt
IncMnodeRef
(
SMnodeObj
*
pMnode
)
{
void
m
node
IncMnodeRef
(
SMnodeObj
*
pMnode
)
{
sdbIncRef
(
tsMnodeSdb
,
pMnode
);
}
void
m
gmt
DecMnodeRef
(
SMnodeObj
*
pMnode
)
{
void
m
node
DecMnodeRef
(
SMnodeObj
*
pMnode
)
{
sdbDecRef
(
tsMnodeSdb
,
pMnode
);
}
void
*
m
gmt
GetNextMnode
(
void
*
pIter
,
SMnodeObj
**
pMnode
)
{
void
*
m
node
GetNextMnode
(
void
*
pIter
,
SMnodeObj
**
pMnode
)
{
return
sdbFetchRow
(
tsMnodeSdb
,
pIter
,
(
void
**
)
pMnode
);
}
char
*
m
gmt
GetMnodeRoleStr
(
int32_t
role
)
{
char
*
m
node
GetMnodeRoleStr
(
int32_t
role
)
{
switch
(
role
)
{
case
TAOS_SYNC_ROLE_OFFLINE
:
return
"offline"
;
...
...
@@ -201,68 +201,79 @@ char *mgmtGetMnodeRoleStr(int32_t role) {
}
}
void
mgmtUpdateMnodeIpSet
()
{
SRpcIpSet
*
ipSet
=
&
tsMnodeRpcIpSet
;
void
mnodeUpdateMnodeIpSet
()
{
SRpcIpSet
*
ipSetForShell
=
&
tsMnodeRpcIpSetForShell
;
SRpcIpSet
*
ipSetForPeer
=
&
tsMnodeRpcIpSetForPeer
;
SDMMnodeInfos
*
mnodes
=
&
tsMnodeInfos
;
mPrint
(
"update mnodes ipset, numOfIps:%d "
,
m
gmt
GetMnodesNum
());
mPrint
(
"update mnodes ipset, numOfIps:%d "
,
m
node
GetMnodesNum
());
m
gmt
MnodeWrLock
();
m
node
MnodeWrLock
();
memset
(
ipSet
,
0
,
sizeof
(
tsMnodeRpcIpSet
));
memset
(
ipSetForShell
,
0
,
sizeof
(
SRpcIpSet
));
memset
(
ipSetForPeer
,
0
,
sizeof
(
SRpcIpSet
));
memset
(
mnodes
,
0
,
sizeof
(
SDMMnodeInfos
));
int32_t
index
=
0
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SMnodeObj
*
pMnode
=
NULL
;
pIter
=
m
gmt
GetNextMnode
(
pIter
,
&
pMnode
);
pIter
=
m
node
GetNextMnode
(
pIter
,
&
pMnode
);
if
(
pMnode
==
NULL
)
break
;
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
!=
NULL
)
{
strcpy
(
ipSet
->
fqdn
[
ipSet
->
numOfIps
],
pDnode
->
dnodeFqdn
);
ipSet
->
port
[
ipSet
->
numOfIps
]
=
htons
(
pDnode
->
dnodePort
);
strcpy
(
ipSetForShell
->
fqdn
[
ipSetForShell
->
numOfIps
],
pDnode
->
dnodeFqdn
);
ipSetForShell
->
port
[
ipSetForShell
->
numOfIps
]
=
htons
(
pDnode
->
dnodePort
);
strcpy
(
ipSetForPeer
->
fqdn
[
ipSetForPeer
->
numOfIps
],
pDnode
->
dnodeFqdn
);
ipSetForPeer
->
port
[
ipSetForPeer
->
numOfIps
]
=
htons
(
pDnode
->
dnodePort
+
TSDB_PORT_DNODEDNODE
);
mnodes
->
nodeInfos
[
index
].
nodeId
=
htonl
(
pMnode
->
mnodeId
);
strcpy
(
mnodes
->
nodeInfos
[
index
].
nodeEp
,
pDnode
->
dnodeEp
);
if
(
pMnode
->
role
==
TAOS_SYNC_ROLE_MASTER
)
{
ipSet
->
inUse
=
ipSet
->
numOfIps
;
ipSetForShell
->
inUse
=
index
;
ipSetForPeer
->
inUse
=
index
;
mnodes
->
inUse
=
index
;
}
mPrint
(
"mnode:%d, ep:%s %s"
,
index
,
pDnode
->
dnodeEp
,
pMnode
->
role
==
TAOS_SYNC_ROLE_MASTER
?
"master"
:
""
);
ipSet
->
numOfIps
++
;
mPrint
(
"mnode:%d, ep:%s %s"
,
index
,
pDnode
->
dnodeEp
,
pMnode
->
role
==
TAOS_SYNC_ROLE_MASTER
?
"master"
:
""
);
index
++
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecDnodeRef
(
pDnode
);
m
node
DecMnodeRef
(
pMnode
);
}
mnodes
->
nodeNum
=
index
;
ipSetForPeer
->
numOfIps
=
index
;
ipSetForPeer
->
numOfIps
=
index
;
sdbFreeIter
(
pIter
);
mgmtMnodeUnLock
();
mnodeMnodeUnLock
();
}
void
mnodeGetMnodeIpSetForPeer
(
SRpcIpSet
*
ipSet
)
{
mnodeMnodeRdLock
();
*
ipSet
=
tsMnodeRpcIpSetForShell
;
mnodeMnodeUnLock
();
}
void
m
gmtGetMnodeIpSet
(
SRpcIpSet
*
ipSet
)
{
m
gmt
MnodeRdLock
();
*
ipSet
=
tsMnodeRpcIpSet
;
m
gmt
MnodeUnLock
();
void
m
nodeGetMnodeIpSetForShell
(
SRpcIpSet
*
ipSet
)
{
m
node
MnodeRdLock
();
*
ipSet
=
tsMnodeRpcIpSet
ForShell
;
m
node
MnodeUnLock
();
}
void
m
gmt
GetMnodeInfos
(
void
*
mnodeInfos
)
{
m
gmt
MnodeRdLock
();
void
m
node
GetMnodeInfos
(
void
*
mnodeInfos
)
{
m
node
MnodeRdLock
();
*
(
SDMMnodeInfos
*
)
mnodeInfos
=
tsMnodeInfos
;
m
gmt
MnodeUnLock
();
m
node
MnodeUnLock
();
}
int32_t
m
gmt
AddMnode
(
int32_t
dnodeId
)
{
int32_t
m
node
AddMnode
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnodeObj
));
pMnode
->
mnodeId
=
dnodeId
;
pMnode
->
createdTime
=
taosGetTimestampMs
();
...
...
@@ -279,24 +290,24 @@ int32_t mgmtAddMnode(int32_t dnodeId) {
code
=
TSDB_CODE_SDB_ERROR
;
}
m
gmt
UpdateMnodeIpSet
();
m
node
UpdateMnodeIpSet
();
return
code
;
}
void
m
gmt
DropMnodeLocal
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
m
gmt
GetMnode
(
dnodeId
);
void
m
node
DropMnodeLocal
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
m
node
GetMnode
(
dnodeId
);
if
(
pMnode
!=
NULL
)
{
SSdbOper
oper
=
{.
type
=
SDB_OPER_LOCAL
,
.
table
=
tsMnodeSdb
,
.
pObj
=
pMnode
};
sdbDeleteRow
(
&
oper
);
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecMnodeRef
(
pMnode
);
}
m
gmt
UpdateMnodeIpSet
();
m
node
UpdateMnodeIpSet
();
}
int32_t
m
gmt
DropMnode
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
m
gmt
GetMnode
(
dnodeId
);
int32_t
m
node
DropMnode
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
m
node
GetMnode
(
dnodeId
);
if
(
pMnode
==
NULL
)
{
return
TSDB_CODE_DNODE_NOT_EXIST
;
}
...
...
@@ -314,18 +325,18 @@ int32_t mgmtDropMnode(int32_t dnodeId) {
sdbDecRef
(
tsMnodeSdb
,
pMnode
);
m
gmt
UpdateMnodeIpSet
();
m
node
UpdateMnodeIpSet
();
return
code
;
}
static
int32_t
m
gmt
GetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
static
int32_t
m
node
GetMnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
sdbUpdateMnodeRoles
();
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
{
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
...
...
@@ -364,22 +375,22 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
m
gmt
GetMnodesNum
();
pShow
->
numOfRows
=
m
node
GetMnodesNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
NULL
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
0
;
}
static
int32_t
m
gmt
RetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveMnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SMnodeObj
*
pMnode
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextMnode
(
pShow
->
pIter
,
&
pMnode
);
pShow
->
pIter
=
m
node
GetNextMnode
(
pShow
->
pIter
,
&
pMnode
);
if
(
pMnode
==
NULL
)
break
;
cols
=
0
;
...
...
@@ -390,18 +401,18 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
!=
NULL
)
{
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pDnode
->
dnodeEp
,
pShow
->
bytes
[
cols
]
-
VARSTR_HEADER_SIZE
);
}
else
{
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
"invalid ep"
,
pShow
->
bytes
[
cols
]
-
VARSTR_HEADER_SIZE
);
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
roles
=
m
gmt
GetMnodeRoleStr
(
pMnode
->
role
);
char
*
roles
=
m
node
GetMnodeRoleStr
(
pMnode
->
role
);
STR_TO_VARSTR
(
pWrite
,
roles
);
cols
++
;
...
...
@@ -411,7 +422,7 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
numOfRows
++
;
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecMnodeRef
(
pMnode
);
}
pShow
->
numOfReads
+=
numOfRows
;
...
...
src/mnode/src/mnode
Mgmt
.c
→
src/mnode/src/mnode
Peer
.c
浏览文件 @
cf687279
...
...
@@ -23,38 +23,43 @@
#include "tgrant.h"
#include "tbalance.h"
#include "tglobal.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeDb.h"
#include "mnodeMnode.h"
#include "mnodeProfile.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeSdb.h"
#include "mnodeTable.h"
#include "mnodeVgroup.h"
static
void
(
*
tsMnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
static
int32_t
(
*
tsMnodeProcessPeerMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
static
void
(
*
tsMnodeProcessPeerRspFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
void
mnodeAdd
MgmtMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SMnodeMsg
*
p
Msg
))
{
tsMnodeProcess
Mgmt
MsgFp
[
msgType
]
=
fp
;
void
mnodeAdd
PeerMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
mnode
Msg
))
{
tsMnodeProcess
Peer
MsgFp
[
msgType
]
=
fp
;
}
int32_t
mnodeProcessMgmt
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
*
rpcMsg
=
&
pMsg
->
rpcMsg
;
if
(
rpcMsg
->
pCont
==
NULL
)
{
mError
(
"%p, msg:%s content is null"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
void
mnodeAddPeerRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
))
{
tsMnodeProcessPeerRspFp
[
msgType
]
=
fp
;
}
int32_t
mnodeProcessPeerReq
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
->
pCont
==
NULL
)
{
mError
(
"msg:%s content is null"
,
taosMsg
[
pMsg
->
msgType
]);
return
TSDB_CODE_INVALID_MSG_LEN
;
}
if
(
!
sdbIsMaster
())
{
SMnodeRsp
*
rpcRsp
=
&
pMsg
->
rpcRsp
;
SRpcIpSet
*
ipSet
=
rpcMallocCont
(
sizeof
(
SRpcIpSet
));
m
gmt
GetMnodeIpSetForPeer
(
ipSet
);
m
node
GetMnodeIpSetForPeer
(
ipSet
);
rpcRsp
->
rsp
=
ipSet
;
rpcRsp
->
len
=
sizeof
(
SRpcIpSet
);
mTrace
(
"
%p, msg:%s will be redireced, inUse:%d"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
],
ipSet
->
inUse
);
mTrace
(
"
msg:%s will be redireced, inUse:%d"
,
taosMsg
[
p
Msg
->
msgType
],
ipSet
->
inUse
);
for
(
int32_t
i
=
0
;
i
<
ipSet
->
numOfIps
;
++
i
)
{
mTrace
(
"mnode index:%d ip:%s:%d"
,
i
,
ipSet
->
fqdn
[
i
],
htons
(
ipSet
->
port
[
i
]));
}
...
...
@@ -62,10 +67,20 @@ int32_t mnodeProcessMgmt(SMnodeMsg *pMsg) {
return
TSDB_CODE_REDIRECT
;
}
if
(
tsMnodeProcess
MgmtMsgFp
[
rpc
Msg
->
msgType
]
==
NULL
)
{
mError
(
"
%p, msg:%s not processed, no handle exist"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
]);
if
(
tsMnodeProcess
PeerMsgFp
[
p
Msg
->
msgType
]
==
NULL
)
{
mError
(
"
msg:%s not processed, no handle exist"
,
taosMsg
[
p
Msg
->
msgType
]);
return
TSDB_CODE_MSG_NOT_PROCESSED
;
}
return
(
*
tsMnodeProcessMgmtMsgFp
[
rpcMsg
->
msgType
])(
rpcMsg
,
);
return
(
*
tsMnodeProcessPeerMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
void
mnodeProcessPeerRsp
(
SRpcMsg
*
pMsg
)
{
if
(
tsMnodeProcessPeerRspFp
[
pMsg
->
msgType
])
{
(
*
tsMnodeProcessPeerRspFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
mError
(
"msg:%s is not processed"
,
pMsg
->
handle
,
taosMsg
[
pMsg
->
msgType
]);
}
rpcFreeCont
(
pMsg
->
pCont
);
}
src/mnode/src/mnodeProfile.c
浏览文件 @
cf687279
...
...
@@ -18,6 +18,7 @@
#include "taosmsg.h"
#include "taoserror.h"
#include "tutil.h"
#include "mnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
...
...
@@ -25,16 +26,17 @@
#include "mnodeDb.h"
#include "mnodeMnode.h"
#include "mnodeProfile.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeTable.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeWrite.h"
int32_t
m
gmt
SaveQueryStreamList
(
SCMHeartBeatMsg
*
pHBMsg
);
int32_t
m
node
SaveQueryStreamList
(
SCMHeartBeatMsg
*
pHBMsg
);
int32_t
m
gmt
KillQuery
(
char
*
qidstr
,
void
*
pConn
);
int32_t
m
gmt
KillStream
(
char
*
qidstr
,
void
*
pConn
);
int32_t
m
gmt
KillConnection
(
char
*
qidstr
,
void
*
pConn
);
int32_t
m
node
KillQuery
(
char
*
qidstr
,
void
*
pConn
);
int32_t
m
node
KillStream
(
char
*
qidstr
,
void
*
pConn
);
int32_t
m
node
KillConnection
(
char
*
qidstr
,
void
*
pConn
);
typedef
struct
{
char
user
[
TSDB_TABLE_ID_LEN
+
1
];
...
...
@@ -98,7 +100,7 @@ int32_t mgmtSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
GetQueries
(
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
m
node
GetQueries
(
SShowObj
*
pShow
,
void
*
pConn
)
{
// SAcctObj * pAcct = pConn->pAcct;
// SQueryShow *pQueryShow;
//
...
...
@@ -145,7 +147,7 @@ int32_t mgmtGetQueries(SShowObj *pShow, void *pConn) {
return
0
;
}
int32_t
m
gmt
GetQueryMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
m
node
GetQueryMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
...
...
@@ -190,11 +192,11 @@ int32_t mgmtGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow
->
pIter
=
NULL
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
GetQueries
(
pShow
,
pConn
);
m
node
GetQueries
(
pShow
,
pConn
);
return
0
;
}
int32_t
m
gmt
KillQuery
(
char
*
qidstr
,
void
*
pConn
)
{
int32_t
m
node
KillQuery
(
char
*
qidstr
,
void
*
pConn
)
{
// char *temp, *chr, idstr[64];
// strcpy(idstr, qidstr);
//
...
...
@@ -247,7 +249,7 @@ int32_t mgmtKillQuery(char *qidstr, void *pConn) {
return
TSDB_CODE_INVALID_QUERY_ID
;
}
int32_t
m
gmt
RetrieveQueries
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveQueries
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
...
...
@@ -297,7 +299,7 @@ int32_t mgmtRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pCo
return
numOfRows
;
}
int32_t
m
gmt
GetStreams
(
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
m
node
GetStreams
(
SShowObj
*
pShow
,
void
*
pConn
)
{
// SAcctObj * pAcct = pConn->pAcct;
// SStreamShow *pStreamShow;
//
...
...
@@ -344,7 +346,7 @@ int32_t mgmtGetStreams(SShowObj *pShow, void *pConn) {
return
0
;
}
int32_t
m
gmt
GetStreamMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
m
node
GetStreamMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
...
...
@@ -400,11 +402,11 @@ int32_t mgmtGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow
->
pIter
=
NULL
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
GetStreams
(
pShow
,
pConn
);
m
node
GetStreams
(
pShow
,
pConn
);
return
0
;
}
int32_t
m
gmt
RetrieveStreams
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveStreams
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
...
...
@@ -462,7 +464,7 @@ int32_t mgmtRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pCo
return
numOfRows
;
}
int32_t
m
gmt
KillStream
(
char
*
qidstr
,
void
*
pConn
)
{
int32_t
m
node
KillStream
(
char
*
qidstr
,
void
*
pConn
)
{
// char *temp, *chr, idstr[64];
// strcpy(idstr, qidstr);
//
...
...
@@ -515,7 +517,7 @@ int32_t mgmtKillStream(char *qidstr, void *pConn) {
return
TSDB_CODE_INVALID_STREAM_ID
;
}
int32_t
m
gmt
KillConnection
(
char
*
qidstr
,
void
*
pConn
)
{
int32_t
m
node
KillConnection
(
char
*
qidstr
,
void
*
pConn
)
{
// void *pConn1 = NULL;
// char * temp, *chr, idstr[64];
// strcpy(idstr, qidstr);
...
...
@@ -562,7 +564,7 @@ int32_t mgmtKillConnection(char *qidstr, void *pConn) {
}
int
m
gmt
GetConns
(
SShowObj
*
pShow
,
void
*
pConn
)
{
int
m
node
GetConns
(
SShowObj
*
pShow
,
void
*
pConn
)
{
// SAcctObj * pAcct = pConn->pAcct;
// SConnShow *pConnShow;
//
...
...
@@ -597,7 +599,7 @@ int mgmtGetConns(SShowObj *pShow, void *pConn) {
return
0
;
}
int32_t
m
gmt
GetConnsMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
m
node
GetConnsMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
pShow
->
bytes
[
cols
]
=
TSDB_TABLE_NAME_LEN
;
...
...
@@ -630,11 +632,11 @@ int32_t mgmtGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow
->
pIter
=
NULL
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
GetConns
(
pShow
,
pConn
);
m
node
GetConns
(
pShow
,
pConn
);
return
0
;
}
int32_t
m
gmt
RetrieveConns
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveConns
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
...
...
@@ -672,91 +674,94 @@ int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn
return
numOfRows
;
}
void
mgmt
ProcessKillQueryMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
int32_t
mnode
ProcessKillQueryMsg
(
SMnodeMsg
*
pMsg
)
{
//
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCMKillQueryMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillQuery
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
// if (pUser == NULL) {
// rpcRsp.code = TSDB_CODE_INVALID_USER;
// rpcSendResponse(&rpcRsp);
// return;
// }
// SCMKillQueryMsg *pKill = pMsg->pCont;
// int32_t code;
// if (!pUser->writeAuth) {
// code = TSDB_CODE_NO_RIGHTS;
// } else {
// code = mgmtKillQuery(pKill->queryId, pMsg->thandle);
// }
// rpcRsp.code = code;
// rpcSendResponse(&rpcRsp);
// mnodeDecUserRef(pUser);
return
TSDB_CODE_SUCCESS
;
}
void
mgmt
ProcessKillStreamMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
int32_t
mnode
ProcessKillStreamMsg
(
SMnodeMsg
*
pMsg
)
{
//
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCMKillStreamMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillStream
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
// if (pUser == NULL) {
// rpcRsp.code = TSDB_CODE_INVALID_USER;
// rpcSendResponse(&rpcRsp);
// return;
// }
// SCMKillStreamMsg *pKill = pMsg->pCont;
// int32_t code;
// if (!pUser->writeAuth) {
// code = TSDB_CODE_NO_RIGHTS;
// } else {
// code = mgmtKillStream(pKill->queryId, pMsg->thandle);
// }
// rpcRsp.code = code;
// rpcSendResponse(&rpcRsp);
// mnodeDecUserRef(pUser);
return
TSDB_CODE_SUCCESS
;
}
void
mgmt
ProcessKillConnectionMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
int32_t
mnode
ProcessKillConnectionMsg
(
SMnodeMsg
*
pMsg
)
{
//
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCMKillConnMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillConnection
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
// if (pUser == NULL) {
// rpcRsp.code = TSDB_CODE_INVALID_USER;
// rpcSendResponse(&rpcRsp);
// return;
// }
// SCMKillConnMsg *pKill = pMsg->pCont;
// int32_t code;
// if (!pUser->writeAuth) {
// code = TSDB_CODE_NO_RIGHTS;
// } else {
// code = mgmtKillConnection(pKill->queryId, pMsg->thandle);
// }
// rpcRsp.code = code;
// rpcSendResponse(&rpcRsp);
// mnodeDecUserRef(pUser);
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
InitProfile
()
{
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_QUERIES
,
mgmt
GetQueryMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_QUERIES
,
mgmt
RetrieveQueries
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_CONNS
,
mgmt
GetConnsMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_CONNS
,
mgmt
RetrieveConns
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_STREAMS
,
mgmt
GetStreamMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_STREAMS
,
mgmt
RetrieveStreams
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_QUERY
,
mgmt
ProcessKillQueryMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_STREAM
,
mgmt
ProcessKillStreamMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_CONN
,
mgmt
ProcessKillConnectionMsg
);
int32_t
m
node
InitProfile
()
{
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_QUERIES
,
mnode
GetQueryMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_QUERIES
,
mnode
RetrieveQueries
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_CONNS
,
mnode
GetConnsMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_CONNS
,
mnode
RetrieveConns
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_STREAMS
,
mnode
GetStreamMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_STREAMS
,
mnode
RetrieveStreams
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_QUERY
,
mnode
ProcessKillQueryMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_STREAM
,
mnode
ProcessKillStreamMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_CONN
,
mnode
ProcessKillConnectionMsg
);
return
0
;
}
void
m
gmtCleanU
pProfile
()
{
void
m
nodeCleanu
pProfile
()
{
}
src/mnode/src/mnodeRead.c
浏览文件 @
cf687279
...
...
@@ -24,39 +24,37 @@
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mgmtInt.h"
#include "mgmtServer.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "m
gmt
Dnode.h"
#include "m
gmt
Mnode.h"
#include "m
node
Dnode.h"
#include "m
node
Mnode.h"
#include "mnodeDb.h"
#include "m
gmt
Sdb.h"
#include "m
gmt
Vgroup.h"
#include "m
gmt
User.h"
#include "m
gmt
Table.h"
#include "m
gmtShell
.h"
#include "m
node
Sdb.h"
#include "m
node
Vgroup.h"
#include "m
node
User.h"
#include "m
node
Table.h"
#include "m
nodeShow
.h"
static
void
(
*
tsMnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
static
int32_t
(
*
tsMnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
void
mnodeAddReadMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SMnodeMsg
*
pMsg
))
{
void
mnodeAddReadMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
pMsg
))
{
tsMnodeProcessReadMsgFp
[
msgType
]
=
fp
;
}
int32_t
mnodeProcessRead
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
*
rpcMsg
=
&
pMsg
->
rpcMsg
;
if
(
rpcMsg
->
pCont
==
NULL
)
{
mError
(
"%p, msg:%s content is null"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
if
(
pMsg
->
pCont
==
NULL
)
{
mError
(
"msg:%s content is null"
,
taosMsg
[
pMsg
->
msgType
]);
return
TSDB_CODE_INVALID_MSG_LEN
;
}
if
(
!
sdbIsMaster
())
{
SMnodeRsp
*
rpcRsp
=
&
pMsg
->
rpcRsp
;
SRpcIpSet
*
ipSet
=
rpcMallocCont
(
sizeof
(
SRpcIpSet
));
m
gmt
GetMnodeIpSetForShell
(
ipSet
);
m
node
GetMnodeIpSetForShell
(
ipSet
);
rpcRsp
->
rsp
=
ipSet
;
rpcRsp
->
len
=
sizeof
(
SRpcIpSet
);
mTrace
(
"
%p, msg:%s will be redireced, inUse:%d"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
],
ipSet
->
inUse
);
mTrace
(
"
msg:%s will be redireced, inUse:%d"
,
taosMsg
[
p
Msg
->
msgType
],
ipSet
->
inUse
);
for
(
int32_t
i
=
0
;
i
<
ipSet
->
numOfIps
;
++
i
)
{
mTrace
(
"mnode index:%d ip:%s:%d"
,
i
,
ipSet
->
fqdn
[
i
],
htons
(
ipSet
->
port
[
i
]));
}
...
...
@@ -64,20 +62,15 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
return
TSDB_CODE_REDIRECT
;
}
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"%p, msg:%s not processed, grant time expired"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
return
TSDB_CODE_GRANT_EXPIRED
;
}
if
(
tsMnodeProcessReadMsgFp
[
rpcMsg
->
msgType
]
==
NULL
)
{
mError
(
"%p, msg:%s not processed, no handle exist"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
if
(
tsMnodeProcessReadMsgFp
[
pMsg
->
msgType
]
==
NULL
)
{
mError
(
"msg:%s not processed, no handle exist"
,
taosMsg
[
pMsg
->
msgType
]);
return
TSDB_CODE_MSG_NOT_PROCESSED
;
}
if
(
!
mnodeInitMsg
(
pMsg
))
{
mError
(
"
%p, msg:%s not processed, reason:%s"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
],
tstrerror
(
terrno
));
mError
(
"
msg:%s not processed, reason:%s"
,
taosMsg
[
p
Msg
->
msgType
],
tstrerror
(
terrno
));
return
terrno
;
}
return
(
*
tsM
gmtProcessShellMsgFp
[
rpc
Msg
->
msgType
])(
pMsg
);
return
(
*
tsM
nodeProcessReadMsgFp
[
p
Msg
->
msgType
])(
pMsg
);
}
src/mnode/src/mnodeSdb.c
浏览文件 @
cf687279
...
...
@@ -189,16 +189,16 @@ void sdbUpdateMnodeRoles() {
sdbPrint
(
"update mnodes:%d sync roles"
,
tsSdbObj
.
cfg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
tsSdbObj
.
cfg
.
replica
;
++
i
)
{
SMnodeObj
*
pMnode
=
m
gmt
GetMnode
(
roles
.
nodeId
[
i
]);
SMnodeObj
*
pMnode
=
m
node
GetMnode
(
roles
.
nodeId
[
i
]);
if
(
pMnode
!=
NULL
)
{
pMnode
->
role
=
roles
.
role
[
i
];
sdbPrint
(
"mnode:%d, role:%s"
,
pMnode
->
mnodeId
,
m
gmt
GetMnodeRoleStr
(
pMnode
->
role
));
sdbPrint
(
"mnode:%d, role:%s"
,
pMnode
->
mnodeId
,
m
node
GetMnodeRoleStr
(
pMnode
->
role
));
if
(
pMnode
->
mnodeId
==
dnodeGetDnodeId
())
tsSdbObj
.
role
=
pMnode
->
role
;
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecMnodeRef
(
pMnode
);
}
}
m
gmt
UpdateMnodeIpSet
();
m
node
UpdateMnodeIpSet
();
}
static
uint32_t
sdbGetFileInfo
(
void
*
ahandle
,
char
*
name
,
uint32_t
*
index
,
int32_t
*
size
,
uint64_t
*
fversion
)
{
...
...
@@ -211,7 +211,7 @@ static int sdbGetWalInfo(void *ahandle, char *name, uint32_t *index) {
}
static
void
sdbNotifyRole
(
void
*
ahandle
,
int8_t
role
)
{
sdbPrint
(
"mnode role changed from %s to %s"
,
m
gmtGetMnodeRoleStr
(
tsSdbObj
.
role
),
mgmt
GetMnodeRoleStr
(
role
));
sdbPrint
(
"mnode role changed from %s to %s"
,
m
nodeGetMnodeRoleStr
(
tsSdbObj
.
role
),
mnode
GetMnodeRoleStr
(
role
));
if
(
role
==
TAOS_SYNC_ROLE_MASTER
&&
tsSdbObj
.
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
balanceReset
();
...
...
@@ -256,20 +256,20 @@ void sdbUpdateSync() {
void
*
pIter
=
NULL
;
while
(
1
)
{
SMnodeObj
*
pMnode
=
NULL
;
pIter
=
m
gmt
GetNextMnode
(
pIter
,
&
pMnode
);
pIter
=
m
node
GetNextMnode
(
pIter
,
&
pMnode
);
if
(
pMnode
==
NULL
)
break
;
syncCfg
.
nodeInfo
[
index
].
nodeId
=
pMnode
->
mnodeId
;
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
!=
NULL
)
{
syncCfg
.
nodeInfo
[
index
].
nodePort
=
pDnode
->
dnodePort
+
TSDB_PORT_SYNC
;
strcpy
(
syncCfg
.
nodeInfo
[
index
].
nodeFqdn
,
pDnode
->
dnodeEp
);
index
++
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
gmt
DecMnodeRef
(
pMnode
);
m
node
DecDnodeRef
(
pDnode
);
m
node
DecMnodeRef
(
pMnode
);
}
sdbFreeIter
(
pIter
);
}
...
...
@@ -324,7 +324,7 @@ int32_t sdbInit() {
sdbRestoreTables
();
if
(
m
gmt
GetMnodesNum
()
==
1
)
{
if
(
m
node
GetMnodesNum
()
==
1
)
{
tsSdbObj
.
role
=
TAOS_SYNC_ROLE_MASTER
;
}
...
...
src/mnode/src/mnodeShow.c
浏览文件 @
cf687279
...
...
@@ -24,6 +24,7 @@
#include "tgrant.h"
#include "tglobal.h"
#include "tcache.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
...
...
@@ -33,33 +34,38 @@
#include "mnodeMnode.h"
#include "mnodeProfile.h"
#include "mnodeSdb.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeTable.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeWrite.h"
#include "mnodeRead.h"
typedef
int32_t
(
*
SShowMetaFp
)(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
typedef
int32_t
(
*
SShowRetrieveFp
)(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeProcessShowMsg
(
SMnodeMsg
*
mnodeMsg
);
static
int32_t
mnodeProcessRetrieveMsg
(
SMnodeMsg
*
mnodeMsg
);
static
int32_t
mnodeProcessHeartBeatMsg
(
SMnodeMsg
*
mnodeMsg
);
static
int32_t
mnodeProcessConnectMsg
(
SMnodeMsg
*
mnodeMsg
);
static
int32_t
mnodeProcessUseMsg
(
SMnodeMsg
*
mnodeMsg
);
static
void
mnodeProcessShowMsg
(
SMnodeMsg
*
queuedMsg
);
static
void
mnodeProcessRetrieveMsg
(
SMnodeMsg
*
queuedMsg
);
static
void
mnodeProcessHeartBeatMsg
(
SMnodeMsg
*
queuedMsg
);
static
void
mnodeProcessConnectMsg
(
SMnodeMsg
*
queuedMsg
);
static
void
mnodeProcessUseMsg
(
SMnodeMsg
*
queuedMsg
);
static
void
mnodeFreeShowObj
(
void
*
data
);
static
void
mnodeFreeShowObj
(
void
*
data
);
static
bool
mnodeCheckQhandle
(
uint64_t
qhandle
);
static
void
*
mnodeSaveQhandle
(
void
*
qhandle
,
int32_t
size
);
static
void
mnodeFreeQhandle
(
void
*
qhandle
,
bool
forceRemove
);
extern
void
*
tsMnodeTmr
;
static
void
*
tsQhandleCache
=
NULL
;
static
SShowMetaFp
tsMnodeShowMetaFp
[
TSDB_M
NODE
_TABLE_MAX
]
=
{
0
};
static
SShowRetrieveFp
tsMnodeShowRetrieveFp
[
TSDB_M
NODE
_TABLE_MAX
]
=
{
0
};
static
SShowMetaFp
tsMnodeShowMetaFp
[
TSDB_M
GMT
_TABLE_MAX
]
=
{
0
};
static
SShowRetrieveFp
tsMnodeShowRetrieveFp
[
TSDB_M
GMT
_TABLE_MAX
]
=
{
0
};
void
mnodeInitShow
()
{
int32_t
mnodeInitShow
()
{
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_SHOW
,
mnodeProcessShowMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_RETRIEVE
,
mnodeProcessRetrieveMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_HEARTBEAT
,
mnodeProcessHeartBeatMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_CONNECT
,
mnodeProcessConnectMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_USE_DB
,
mnodeProcessUseMsg
);
tsQhandleCache
=
taosCacheInitWithCb
(
tsMgmtTmr
,
10
,
mnodeFreeShowObj
);
tsQhandleCache
=
taosCacheInitWithCb
(
tsMnodeTmr
,
10
,
mnodeFreeShowObj
);
return
0
;
}
void
mnodeCleanUpShow
()
{
...
...
@@ -77,46 +83,43 @@ void mnodeAddShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
tsMnodeShowRetrieveFp
[
msgType
]
=
fp
;
}
char
*
mnodeGetShowType
(
int32_t
showType
)
{
static
char
*
mnodeGetShowType
(
int32_t
showType
)
{
switch
(
showType
)
{
case
TSDB_M
NODE
_TABLE_ACCT
:
return
"show accounts"
;
case
TSDB_M
NODE
_TABLE_USER
:
return
"show users"
;
case
TSDB_M
NODE
_TABLE_DB
:
return
"show databases"
;
case
TSDB_M
NODE
_TABLE_TABLE
:
return
"show tables"
;
case
TSDB_M
NODE
_TABLE_DNODE
:
return
"show dnodes"
;
case
TSDB_M
NODE
_TABLE_MNODE
:
return
"show mnodes"
;
case
TSDB_M
NODE
_TABLE_VGROUP
:
return
"show vgroups"
;
case
TSDB_M
NODE
_TABLE_METRIC
:
return
"show stables"
;
case
TSDB_M
NODE
_TABLE_MODULE
:
return
"show modules"
;
case
TSDB_M
NODE
_TABLE_QUERIES
:
return
"show queries"
;
case
TSDB_M
NODE
_TABLE_STREAMS
:
return
"show streams"
;
case
TSDB_M
NODE
_TABLE_CONFIGS
:
return
"show configs"
;
case
TSDB_M
NODE
_TABLE_CONNS
:
return
"show connections"
;
case
TSDB_M
NODE
_TABLE_SCORES
:
return
"show scores"
;
case
TSDB_M
NODE
_TABLE_GRANTS
:
return
"show grants"
;
case
TSDB_M
NODE
_TABLE_VNODES
:
return
"show vnodes"
;
case
TSDB_M
GMT
_TABLE_ACCT
:
return
"show accounts"
;
case
TSDB_M
GMT
_TABLE_USER
:
return
"show users"
;
case
TSDB_M
GMT
_TABLE_DB
:
return
"show databases"
;
case
TSDB_M
GMT
_TABLE_TABLE
:
return
"show tables"
;
case
TSDB_M
GMT
_TABLE_DNODE
:
return
"show dnodes"
;
case
TSDB_M
GMT
_TABLE_MNODE
:
return
"show mnodes"
;
case
TSDB_M
GMT
_TABLE_VGROUP
:
return
"show vgroups"
;
case
TSDB_M
GMT
_TABLE_METRIC
:
return
"show stables"
;
case
TSDB_M
GMT
_TABLE_MODULE
:
return
"show modules"
;
case
TSDB_M
GMT
_TABLE_QUERIES
:
return
"show queries"
;
case
TSDB_M
GMT
_TABLE_STREAMS
:
return
"show streams"
;
case
TSDB_M
GMT
_TABLE_CONFIGS
:
return
"show configs"
;
case
TSDB_M
GMT
_TABLE_CONNS
:
return
"show connections"
;
case
TSDB_M
GMT
_TABLE_SCORES
:
return
"show scores"
;
case
TSDB_M
GMT
_TABLE_GRANTS
:
return
"show grants"
;
case
TSDB_M
GMT
_TABLE_VNODES
:
return
"show vnodes"
;
default:
return
"undefined"
;
}
}
static
void
mnodeProcessShowMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnodeProcessShowMsg
(
SMnodeMsg
*
pMsg
)
{
SCMShowMsg
*
pShowMsg
=
pMsg
->
pCont
;
if
(
pShowMsg
->
type
>=
TSDB_MNODE_TABLE_MAX
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_MSG_TYPE
);
return
;
if
(
pShowMsg
->
type
>=
TSDB_MGMT_TABLE_MAX
)
{
return
TSDB_CODE_INVALID_MSG_TYPE
;
}
if
(
!
tsMnodeShowMetaFp
[
pShowMsg
->
type
]
||
!
tsMnodeShowRetrieveFp
[
pShowMsg
->
type
])
{
mError
(
"show type:%s is not support"
,
mnodeGetShowType
(
pShowMsg
->
type
));
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_OPS_NOT_SUPPORT
);
return
;
return
TSDB_CODE_OPS_NOT_SUPPORT
;
}
int32_t
size
=
sizeof
(
SCMShowRsp
)
+
sizeof
(
SSchema
)
*
TSDB_MAX_COLUMNS
+
TSDB_EXTRA_PAYLOAD_SIZE
;
SCMShowRsp
*
pShowRsp
=
rpcMallocCont
(
size
);
if
(
pShowRsp
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
int32_t
showObjSize
=
sizeof
(
SShowObj
)
+
htons
(
pShowMsg
->
payloadLen
);
...
...
@@ -127,31 +130,23 @@ static void mnodeProcessShowMsg(SMnodeMsg *pMsg) {
strcpy
(
pShow
->
db
,
pShowMsg
->
db
);
memcpy
(
pShow
->
payload
,
pShowMsg
->
payload
,
pShow
->
payloadLen
);
pShow
=
m
gmt
SaveQhandle
(
pShow
,
showObjSize
);
pShow
=
m
node
SaveQhandle
(
pShow
,
showObjSize
);
pShowRsp
->
qhandle
=
htobe64
((
uint64_t
)
pShow
);
mTrace
(
"show:%p, type:%s, start to get meta"
,
pShow
,
mnodeGetShowType
(
pShowMsg
->
type
));
int32_t
code
=
(
*
tsMnodeShowMetaFp
[
pShowMsg
->
type
])(
&
pShowRsp
->
tableMeta
,
pShow
,
pMsg
->
thandle
);
if
(
code
==
0
)
{
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pShowRsp
,
.
contLen
=
sizeof
(
SCMShowRsp
)
+
sizeof
(
SSchema
)
*
pShow
->
numOfColumns
,
.
code
=
code
};
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pShowRsp
;
pMsg
->
rpcRsp
.
len
=
sizeof
(
SCMShowRsp
)
+
sizeof
(
SSchema
)
*
pShow
->
numOfColumns
;
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"show:%p, type:%s, failed to get meta, reason:%s"
,
pShow
,
mnodeGetShowType
(
pShowMsg
->
type
),
tstrerror
(
code
));
mgmtFreeQhandle
(
pShow
,
false
);
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
code
=
code
};
rpcSendResponse
(
&
rpcRsp
);
mnodeFreeQhandle
(
pShow
,
true
);
return
code
;
}
}
static
void
mnodeProcessRetrieveMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnodeProcessRetrieveMsg
(
SMnodeMsg
*
pMsg
)
{
int32_t
rowsToRead
=
0
;
int32_t
size
=
0
;
int32_t
rowsRead
=
0
;
...
...
@@ -162,10 +157,9 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
* in case of server restart, apps may hold qhandle created by server before
* restart, which is actually invalid, therefore, signature check is required.
*/
if
(
!
m
gmt
CheckQhandle
(
pRetrieve
->
qhandle
))
{
if
(
!
m
node
CheckQhandle
(
pRetrieve
->
qhandle
))
{
mError
(
"retrieve:%p, qhandle:%p is invalid"
,
pRetrieve
,
pRetrieve
->
qhandle
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_QHANDLE
);
return
;
return
TSDB_CODE_INVALID_QHANDLE
;
}
SShowObj
*
pShow
=
(
SShowObj
*
)
pRetrieve
->
qhandle
;
...
...
@@ -192,41 +186,37 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
if
((
pRetrieve
->
free
&
TSDB_QUERY_TYPE_FREE_RESOURCE
)
!=
TSDB_QUERY_TYPE_FREE_RESOURCE
)
rowsRead
=
(
*
tsMnodeShowRetrieveFp
[
pShow
->
type
])(
pShow
,
pRsp
->
data
,
rowsToRead
,
pMsg
->
thandle
);
if
(
rowsRead
<
0
)
{
// TSDB_CODE_ACTION_IN_PROGRESS;
if
(
rowsRead
<
0
)
{
rpcFreeCont
(
pRsp
);
mgmtFreeQhandle
(
pShow
,
false
);
return
;
mnodeFreeQhandle
(
pShow
,
false
);
assert
(
false
);
return
TSDB_CODE_ACTION_IN_PROGRESS
;
}
pRsp
->
numOfRows
=
htonl
(
rowsRead
);
pRsp
->
precision
=
htonl
(
TSDB_TIME_PRECISION_MILLI
);
// millisecond time precision
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pRsp
,
.
contLen
=
size
,
.
code
=
0
,
.
msgType
=
0
};
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pRsp
;
pMsg
->
rpcRsp
.
len
=
size
;
if
(
rowsToRead
==
0
)
{
m
gmt
FreeQhandle
(
pShow
,
true
);
m
node
FreeQhandle
(
pShow
,
true
);
}
else
{
m
gmt
FreeQhandle
(
pShow
,
false
);
m
node
FreeQhandle
(
pShow
,
false
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
mnodeProcessHeartBeatMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnodeProcessHeartBeatMsg
(
SMnodeMsg
*
pMsg
)
{
SCMHeartBeatRsp
*
pHBRsp
=
(
SCMHeartBeatRsp
*
)
rpcMallocCont
(
sizeof
(
SCMHeartBeatRsp
));
if
(
pHBRsp
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
pHBRsp
->
onlineDnodes
=
htonl
(
m
gmt
GetOnlinDnodesNum
());
pHBRsp
->
totalDnodes
=
htonl
(
m
gmt
GetDnodesNum
());
m
gmtGetMnodeIpSet
(
&
pHBRsp
->
ipList
);
pHBRsp
->
onlineDnodes
=
htonl
(
m
node
GetOnlinDnodesNum
());
pHBRsp
->
totalDnodes
=
htonl
(
m
node
GetDnodesNum
());
m
nodeGetMnodeIpSetForShell
(
&
pHBRsp
->
ipList
);
/*
* TODO
...
...
@@ -236,29 +226,20 @@ static void mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
pHBRsp
->
streamId
=
0
;
pHBRsp
->
killConnection
=
0
;
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pHBRsp
,
.
contLen
=
sizeof
(
SCMHeartBeatRsp
),
.
code
=
0
,
.
msgType
=
0
};
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pHBRsp
;
pMsg
->
rpcRsp
.
len
=
sizeof
(
SCMHeartBeatRsp
);
return
TSDB_CODE_SUCCESS
;
}
static
void
mnodeProcessConnectMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
static
int32_t
mnodeProcessConnectMsg
(
SMnodeMsg
*
pMsg
)
{
SCMConnectMsg
*
pConnectMsg
=
pMsg
->
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRpcConnInfo
connInfo
;
if
(
rpcGetConnInfo
(
pMsg
->
thandle
,
&
connInfo
)
!=
0
)
{
mError
(
"thandle:%p is already released while process connect msg"
,
pMsg
->
thandle
);
return
;
}
int32_t
code
;
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_GRANT_EXPIRED
;
code
=
TSDB_CODE_INVALID_MSG_CONTENT
;
goto
connect_over
;
}
...
...
@@ -273,12 +254,12 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
if
(
pConnectMsg
->
db
[
0
])
{
char
dbName
[
TSDB_TABLE_ID_LEN
*
3
]
=
{
0
};
sprintf
(
dbName
,
"%x%s%s"
,
pAcct
->
acctId
,
TS_PATH_DELIMITER
,
pConnectMsg
->
db
);
SDbObj
*
pDb
=
m
gmt
GetDb
(
dbName
);
SDbObj
*
pDb
=
m
node
GetDb
(
dbName
);
if
(
pDb
==
NULL
)
{
code
=
TSDB_CODE_INVALID_DB
;
goto
connect_over
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
}
SCMConnectRsp
*
pConnectRsp
=
rpcMallocCont
(
sizeof
(
SCMConnectRsp
));
...
...
@@ -292,92 +273,33 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
pConnectRsp
->
writeAuth
=
pUser
->
writeAuth
;
pConnectRsp
->
superAuth
=
pUser
->
superAuth
;
m
gmtGetMnodeIpSet
(
&
pConnectRsp
->
ipList
);
m
nodeGetMnodeIpSetForShell
(
&
pConnectRsp
->
ipList
);
connect_over:
rpcRsp
.
code
=
code
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mLError
(
"user:%s login from %s, result:%s"
,
connInfo
.
user
,
taosIpStr
(
connInfo
.
clientIp
),
tstrerror
(
code
));
}
else
{
mLPrint
(
"user:%s login from %s, result:%s"
,
connInfo
.
user
,
taosIpStr
(
connInfo
.
clientIp
),
tstrerror
(
code
));
rpcRsp
.
pCont
=
pConnectRsp
;
rpcRsp
.
contL
en
=
sizeof
(
SCMConnectRsp
);
pMsg
->
rpcRsp
.
rsp
=
pConnectRsp
;
pMsg
->
rpcRsp
.
l
en
=
sizeof
(
SCMConnectRsp
);
}
rpcSendResponse
(
&
rpcRsp
);
return
code
;
}
static
void
mnodeProcessUseMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
static
int32_t
mnodeProcessUseMsg
(
SMnodeMsg
*
pMsg
)
{
SCMUseDbMsg
*
pUseDbMsg
=
pMsg
->
pCont
;
// todo check for priority of current user
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDb
(
pUseDbMsg
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDb
(
pUseDbMsg
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
{
code
=
TSDB_CODE_INVALID_DB
;
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
/**
* check if we need to add mgmtProcessTableMetaMsg into tranQueue, which will be executed one-by-one.
*/
static
bool
mgmtCheckTableMetaMsgReadOnly
(
SMnodeMsg
*
pMsg
)
{
SCMTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mgmtGetTable
(
pInfo
->
tableId
);
if
(
pMsg
->
pTable
!=
NULL
)
return
true
;
// If table does not exists and autoCreate flag is set, we add the handler into task queue
int16_t
autoCreate
=
htons
(
pInfo
->
createFlag
);
if
(
autoCreate
==
1
)
{
mTrace
(
"table:%s auto created task added"
,
pInfo
->
tableId
);
return
false
;
}
return
true
;
return
code
;
}
static
bool
mgmtCheckMsgReadOnly
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_TABLE_META
)
{
return
mgmtCheckTableMetaMsgReadOnly
(
pMsg
);
}
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_STABLE_VGROUP
||
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_RETRIEVE
||
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_SHOW
||
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_TABLES_META
||
pMsg
->
msgType
==
TSDB_MSG_TYPE_CM_CONNECT
)
{
return
true
;
}
return
false
;
}
static
void
mgmtProcessUnSupportMsg
(
SRpcMsg
*
rpcMsg
)
{
mError
(
"%s is not processed in mnode shell"
,
taosMsg
[
rpcMsg
->
msgType
]);
SRpcMsg
rpcRsp
=
{
.
msgType
=
0
,
.
pCont
=
0
,
.
contLen
=
0
,
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
,
.
handle
=
rpcMsg
->
handle
};
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtSendSimpleResp
(
void
*
thandle
,
int32_t
code
)
{
SRpcMsg
rpcRsp
=
{
.
msgType
=
0
,
.
pCont
=
0
,
.
contLen
=
0
,
.
code
=
code
,
.
handle
=
thandle
};
rpcSendResponse
(
&
rpcRsp
);
}
bool
mgmtCheckQhandle
(
uint64_t
qhandle
)
{
static
bool
mnodeCheckQhandle
(
uint64_t
qhandle
)
{
void
*
pSaved
=
taosCacheAcquireByData
(
tsQhandleCache
,
(
void
*
)
qhandle
);
if
(
pSaved
==
(
void
*
)
qhandle
)
{
mTrace
(
"show:%p, is retrieved"
,
qhandle
);
...
...
@@ -388,17 +310,17 @@ bool mgmtCheckQhandle(uint64_t qhandle) {
}
}
void
*
mgmt
SaveQhandle
(
void
*
qhandle
,
int32_t
size
)
{
static
void
*
mnode
SaveQhandle
(
void
*
qhandle
,
int32_t
size
)
{
if
(
tsQhandleCache
!=
NULL
)
{
char
key
[
24
];
sprintf
(
key
,
"show:%p"
,
qhandle
);
void
*
newQhandle
=
taosCachePut
(
tsQhandleCache
,
key
,
qhandle
,
size
,
60
);
free
(
qhandle
);
mTrace
(
"show:%p, is saved"
,
newQhandle
);
return
newQhandle
;
}
return
NULL
;
}
...
...
@@ -408,60 +330,7 @@ static void mnodeFreeShowObj(void *data) {
mTrace
(
"show:%p, is destroyed"
,
pShow
);
}
void
mgmt
FreeQhandle
(
void
*
qhandle
,
bool
forceRemove
)
{
static
void
mnode
FreeQhandle
(
void
*
qhandle
,
bool
forceRemove
)
{
mTrace
(
"show:%p, is released, force:%s"
,
qhandle
,
forceRemove
?
"true"
:
"false"
);
taosCacheRelease
(
tsQhandleCache
,
&
qhandle
,
forceRemove
);
}
void
*
mgmtMallocQueuedMsg
(
SRpcMsg
*
rpcMsg
,
SRspRet
*
pRet
)
{
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_USER
;
return
NULL
;
}
SMnodeMsg
*
pMsg
=
calloc
(
1
,
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
}
pMsg
->
thandle
=
rpcMsg
->
handle
;
pMsg
->
msgType
=
rpcMsg
->
msgType
;
pMsg
->
contLen
=
rpcMsg
->
contLen
;
pMsg
->
pCont
=
rpcMsg
->
pCont
;
pMsg
->
pUser
=
pUser
;
pMsg
->
pRet
=
pRet
;
return
pMsg
;
}
void
mgmtFreeQueuedMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
rpcFreeCont
(
pMsg
->
pCont
);
if
(
pMsg
->
pUser
)
mgmtDecUserRef
(
pMsg
->
pUser
);
if
(
pMsg
->
pDb
)
mgmtDecDbRef
(
pMsg
->
pDb
);
if
(
pMsg
->
pVgroup
)
mgmtDecVgroupRef
(
pMsg
->
pVgroup
);
if
(
pMsg
->
pTable
)
mgmtDecTableRef
(
pMsg
->
pTable
);
if
(
pMsg
->
pAcct
)
mgmtDecAcctRef
(
pMsg
->
pAcct
);
if
(
pMsg
->
pDnode
)
mgmtDecDnodeRef
(
pMsg
->
pDnode
);
free
(
pMsg
);
}
}
void
*
mgmtCloneQueuedMsg
(
SMnodeMsg
*
pSrcMsg
)
{
SMnodeMsg
*
pDestMsg
=
calloc
(
1
,
sizeof
(
SMnodeMsg
));
pDestMsg
->
thandle
=
pSrcMsg
->
thandle
;
pDestMsg
->
msgType
=
pSrcMsg
->
msgType
;
pDestMsg
->
pCont
=
pSrcMsg
->
pCont
;
pDestMsg
->
contLen
=
pSrcMsg
->
contLen
;
pDestMsg
->
retry
=
pSrcMsg
->
retry
;
pDestMsg
->
maxRetry
=
pSrcMsg
->
maxRetry
;
pDestMsg
->
pUser
=
pSrcMsg
->
pUser
;
pSrcMsg
->
pCont
=
NULL
;
pSrcMsg
->
pUser
=
NULL
;
return
pDestMsg
;
}
src/mnode/src/mnodeTable.c
浏览文件 @
cf687279
此差异已折叠。
点击以展开。
src/mnode/src/mnodeUser.c
浏览文件 @
cf687279
此差异已折叠。
点击以展开。
src/mnode/src/mnodeVgroup.c
浏览文件 @
cf687279
此差异已折叠。
点击以展开。
src/mnode/src/mnodeWrite.c
浏览文件 @
cf687279
...
...
@@ -19,12 +19,11 @@
#include "tsched.h"
#include "tbalance.h"
#include "tgrant.h"
#include "ttimer.h"
#include "tglobal.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeServer.h"
#include "mnodeAcct.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
...
...
@@ -33,29 +32,28 @@
#include "mnodeVgroup.h"
#include "mnodeUser.h"
#include "mnodeTable.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
static
void
(
*
tsMnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
static
int32_t
(
*
tsMnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SMnodeMsg
*
);
void
mnodeAddWriteMsgHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SMnodeMsg
*
p
Msg
))
{
void
mnodeAddWriteMsgHandle
(
uint8_t
msgType
,
int32_t
(
*
fp
)(
SMnodeMsg
*
mnode
Msg
))
{
tsMnodeProcessWriteMsgFp
[
msgType
]
=
fp
;
}
int32_t
mnodeProcessWrite
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
*
rpcMsg
=
&
pMsg
->
rpcMsg
;
if
(
rpcMsg
->
pCont
==
NULL
)
{
mError
(
"%p, msg:%s content is null"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
if
(
pMsg
->
pCont
==
NULL
)
{
mError
(
"msg:%s content is null"
,
taosMsg
[
pMsg
->
msgType
]);
return
TSDB_CODE_INVALID_MSG_LEN
;
}
if
(
!
sdbIsMaster
())
{
SMnodeRsp
*
rpcRsp
=
&
pMsg
->
rpcRsp
;
SRpcIpSet
*
ipSet
=
rpcMallocCont
(
sizeof
(
SRpcIpSet
));
m
gmt
GetMnodeIpSetForShell
(
ipSet
);
m
node
GetMnodeIpSetForShell
(
ipSet
);
rpcRsp
->
rsp
=
ipSet
;
rpcRsp
->
len
=
sizeof
(
SRpcIpSet
);
mTrace
(
"
%p, msg:%s will be redireced, inUse:%d"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
],
ipSet
->
inUse
);
mTrace
(
"
msg:%s will be redireced, inUse:%d"
,
taosMsg
[
p
Msg
->
msgType
],
ipSet
->
inUse
);
for
(
int32_t
i
=
0
;
i
<
ipSet
->
numOfIps
;
++
i
)
{
mTrace
(
"mnode index:%d ip:%s:%d"
,
i
,
ipSet
->
fqdn
[
i
],
htons
(
ipSet
->
port
[
i
]));
}
...
...
@@ -63,34 +61,20 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
return
TSDB_CODE_REDIRECT
;
}
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"%p, msg:%s not processed, grant time expired"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
return
TSDB_CODE_GRANT_EXPIRED
;
}
if
(
tsMnodeProcessReadMsgFp
[
rpcMsg
->
msgType
]
==
NULL
)
{
mError
(
"%p, msg:%s not processed, no handle exist"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpcMsg
->
msgType
]);
if
(
tsMnodeProcessWriteMsgFp
[
pMsg
->
msgType
]
==
NULL
)
{
mError
(
"msg:%s not processed, no handle exist"
,
taosMsg
[
pMsg
->
msgType
]);
return
TSDB_CODE_MSG_NOT_PROCESSED
;
}
if
(
!
mnodeInitMsg
(
pMsg
))
{
mError
(
"
%p, msg:%s not processed, reason:%s"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
],
tstrerror
(
terrno
));
mError
(
"
msg:%s not processed, reason:%s"
,
taosMsg
[
p
Msg
->
msgType
],
tstrerror
(
terrno
));
return
terrno
;
}
if
(
!
pMsg
->
pUser
->
writeAuth
)
{
mError
(
"%p, msg:%s not processed, no rights"
,
rpcMsg
->
ahandle
,
taosMsg
[
rpc
Msg
->
msgType
]);
mError
(
"%p, msg:%s not processed, no rights"
,
taosMsg
[
p
Msg
->
msgType
]);
return
TSDB_CODE_NO_RIGHTS
;
}
return
(
*
tsMnodeProcessWriteMsgFp
[
rpc
Msg
->
msgType
])(
pMsg
);
return
(
*
tsMnodeProcessWriteMsgFp
[
p
Msg
->
msgType
])(
pMsg
);
}
static
void
mgmtDoDealyedAddToShellQueue
(
void
*
param
,
void
*
tmrId
)
{
mgmtAddToShellQueue
(
param
);
}
void
mgmtDealyedAddToShellQueue
(
SMnodeMsg
*
queuedMsg
)
{
void
*
unUsed
=
NULL
;
taosTmrReset
(
mgmtDoDealyedAddToShellQueue
,
300
,
queuedMsg
,
tsMgmtTmr
,
&
unUsed
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录