Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cf687279
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
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
);
if
(
forShell
)
{
dnodeGetMnodeIpSetForShell
(
&
ipSet
);
}
else
{
dnodeGetMnodeIpSetForPeer
(
&
ipSet
);
}
dTrace
(
"msg:%s will be redirected, dnodeIp:%s user:%s, numOfIps:%d inUse:%d"
,
taosMsg
[
rpcMsg
->
msgType
],
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
);
rpcSendRedirectRsp
(
t
handle
,
&
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
...
...
@@ -44,8 +44,9 @@ void dnodeFreeRqueue(void *rqueue);
void
dnodeSendRpcWriteRsp
(
void
*
pVnode
,
void
*
param
,
int32_t
code
);
bool
dnodeIsFirstDeploy
();
char
*
dnodeGetMnodeMasterEp
();
void
dnodeGetMnodeDnodeIpSet
(
void
*
ipSet
,
bool
encode
);
char
*
dnodeGetMnodeMasterEp
();
void
dnodeGetMnodeIpSetForPeer
(
void
*
ipSet
);
void
dnodeGetMnodeIpSetForShell
(
void
*
ipSet
);
void
*
dnodeGetMnodeInfos
();
int32_t
dnodeGetDnodeId
();
...
...
@@ -54,6 +55,10 @@ 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
}
#endif
...
...
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
...
...
@@ -15,7 +15,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "tutil.h"
#include "tgrant.h"
...
...
@@ -24,15 +23,17 @@
#include "tname.h"
#include "tbalance.h"
#include "tdataformat.h"
#include "mnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "mnodeDb.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
#include "mnodeShell.h"
#include "mnodeProfile.h"
#include "mnodeWrite.h"
#include "mnodeSdb.h"
#include "mnodeShow.h"
#include "mnodeTable.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
...
...
@@ -40,23 +41,23 @@
static
void
*
tsDbSdb
=
NULL
;
static
int32_t
tsDbUpdateSize
;
static
int32_t
m
gmt
CreateDb
(
SAcctObj
*
pAcct
,
SCMCreateDbMsg
*
pCreate
);
static
void
mgmt
DropDb
(
SMnodeMsg
*
newMsg
);
static
int32_t
m
gmt
SetDbDropping
(
SDbObj
*
pDb
);
static
int32_t
m
gmt
GetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
mgmt
ProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessDropDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
m
node
CreateDb
(
SAcctObj
*
pAcct
,
SCMCreateDbMsg
*
pCreate
);
static
int32_t
mnode
DropDb
(
SMnodeMsg
*
newMsg
);
static
int32_t
m
node
SetDbDropping
(
SDbObj
*
pDb
);
static
int32_t
m
node
GetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnode
ProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessDropDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
m
gmt
DbActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionDestroy
(
SSdbOper
*
pOper
)
{
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionInsert
(
SSdbOper
*
pOper
)
{
SDbObj
*
pDb
=
pOper
->
pObj
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
pDb
->
pHead
=
NULL
;
pDb
->
pTail
=
NULL
;
...
...
@@ -65,8 +66,8 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
pDb
->
numOfSuperTables
=
0
;
if
(
pAcct
!=
NULL
)
{
m
gmt
AddDbToAcct
(
pAcct
,
pDb
);
m
gmt
DecAcctRef
(
pAcct
);
m
node
AddDbToAcct
(
pAcct
,
pDb
);
m
node
DecAcctRef
(
pAcct
);
}
else
{
mError
(
"db:%s, acct:%s info not exist in sdb"
,
pDb
->
name
,
pDb
->
acct
);
...
...
@@ -76,39 +77,39 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionDelete
(
SSdbOper
*
pOper
)
{
SDbObj
*
pDb
=
pOper
->
pObj
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
m
gmt
DropDbFromAcct
(
pAcct
,
pDb
);
m
gmt
DropAllChildTables
(
pDb
);
m
gmt
DropAllSuperTables
(
pDb
);
m
gmt
DropAllDbVgroups
(
pDb
,
false
);
m
gmt
DecAcctRef
(
pAcct
);
m
node
DropDbFromAcct
(
pAcct
,
pDb
);
m
node
DropAllChildTables
(
pDb
);
m
node
DropAllSuperTables
(
pDb
);
m
node
DropAllDbVgroups
(
pDb
,
false
);
m
node
DecAcctRef
(
pAcct
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionUpdate
(
SSdbOper
*
pOper
)
{
SDbObj
*
pDb
=
pOper
->
pObj
;
SDbObj
*
pSaved
=
m
gmt
GetDb
(
pDb
->
name
);
SDbObj
*
pSaved
=
m
node
GetDb
(
pDb
->
name
);
if
(
pDb
!=
pSaved
)
{
memcpy
(
pSaved
,
pDb
,
pOper
->
rowSize
);
free
(
pDb
);
}
m
gmt
UpdateAllDbVgroups
(
pSaved
);
m
gmt
DecDbRef
(
pSaved
);
m
node
UpdateAllDbVgroups
(
pSaved
);
m
node
DecDbRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionEncode
(
SSdbOper
*
pOper
)
{
SDbObj
*
pDb
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pDb
,
tsDbUpdateSize
);
pOper
->
rowSize
=
tsDbUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DbActionDecode
(
SSdbOper
*
pOper
)
{
SDbObj
*
pDb
=
(
SDbObj
*
)
calloc
(
1
,
sizeof
(
SDbObj
));
if
(
pDb
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -117,11 +118,11 @@ static int32_t mgmtDbActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DbActionRestored
()
{
static
int32_t
m
node
DbActionRestored
()
{
return
0
;
}
int32_t
m
gmt
InitDbs
()
{
int32_t
m
node
InitDbs
()
{
SDbObj
tObj
;
tsDbUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -132,13 +133,13 @@ int32_t mgmtInitDbs() {
.
maxRowSize
=
tsDbUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
m
gmt
DbActionInsert
,
.
deleteFp
=
m
gmt
DbActionDelete
,
.
updateFp
=
m
gmt
DbActionUpdate
,
.
encodeFp
=
m
gmt
DbActionEncode
,
.
decodeFp
=
m
gmt
DbActionDecode
,
.
destroyFp
=
m
gmt
DbActionDestroy
,
.
restoredFp
=
m
gmt
DbActionRestored
.
insertFp
=
m
node
DbActionInsert
,
.
deleteFp
=
m
node
DbActionDelete
,
.
updateFp
=
m
node
DbActionUpdate
,
.
encodeFp
=
m
node
DbActionEncode
,
.
decodeFp
=
m
node
DbActionDecode
,
.
destroyFp
=
m
node
DbActionDestroy
,
.
restoredFp
=
m
node
DbActionRestored
};
tsDbSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -147,33 +148,33 @@ int32_t mgmtInitDbs() {
return
-
1
;
}
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DB
,
mgmt
ProcessCreateDbMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_DB
,
mgmt
ProcessAlterDbMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DB
,
mgmt
ProcessDropDbMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_DB
,
mgmt
GetDbMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_DB
,
mgmt
RetrieveDbs
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DB
,
mnode
ProcessCreateDbMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_DB
,
mnode
ProcessAlterDbMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DB
,
mnode
ProcessDropDbMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_DB
,
mnode
GetDbMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_DB
,
mnode
RetrieveDbs
);
mTrace
(
"table:dbs table is created"
);
return
0
;
}
void
*
m
gmt
GetNextDb
(
void
*
pIter
,
SDbObj
**
pDb
)
{
void
*
m
node
GetNextDb
(
void
*
pIter
,
SDbObj
**
pDb
)
{
return
sdbFetchRow
(
tsDbSdb
,
pIter
,
(
void
**
)
pDb
);
}
SDbObj
*
m
gmt
GetDb
(
char
*
db
)
{
SDbObj
*
m
node
GetDb
(
char
*
db
)
{
return
(
SDbObj
*
)
sdbGetRow
(
tsDbSdb
,
db
);
}
void
m
gmt
IncDbRef
(
SDbObj
*
pDb
)
{
void
m
node
IncDbRef
(
SDbObj
*
pDb
)
{
return
sdbIncRef
(
tsDbSdb
,
pDb
);
}
void
m
gmt
DecDbRef
(
SDbObj
*
pDb
)
{
void
m
node
DecDbRef
(
SDbObj
*
pDb
)
{
return
sdbDecRef
(
tsDbSdb
,
pDb
);
}
SDbObj
*
m
gmt
GetDbByTableId
(
char
*
tableId
)
{
SDbObj
*
m
node
GetDbByTableId
(
char
*
tableId
)
{
char
db
[
TSDB_TABLE_ID_LEN
],
*
pos
;
pos
=
strstr
(
tableId
,
TS_PATH_DELIMITER
);
...
...
@@ -181,10 +182,10 @@ SDbObj *mgmtGetDbByTableId(char *tableId) {
memset
(
db
,
0
,
sizeof
(
db
));
strncpy
(
db
,
tableId
,
pos
-
tableId
);
return
m
gmt
GetDb
(
db
);
return
m
node
GetDb
(
db
);
}
static
int32_t
m
gmt
CheckDbCfg
(
SDbCfg
*
pCfg
)
{
static
int32_t
m
node
CheckDbCfg
(
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
cacheBlockSize
<
TSDB_MIN_CACHE_BLOCK_SIZE
||
pCfg
->
cacheBlockSize
>
TSDB_MAX_CACHE_BLOCK_SIZE
)
{
mError
(
"invalid db option cacheBlockSize:%d valid range: [%d, %d]"
,
pCfg
->
cacheBlockSize
,
TSDB_MIN_CACHE_BLOCK_SIZE
,
TSDB_MAX_CACHE_BLOCK_SIZE
);
...
...
@@ -290,7 +291,7 @@ static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) {
return
TSDB_CODE_SUCCESS
;
}
static
void
m
gmt
SetDefaultDbCfg
(
SDbCfg
*
pCfg
)
{
static
void
m
node
SetDefaultDbCfg
(
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
cacheBlockSize
<
0
)
pCfg
->
cacheBlockSize
=
tsCacheBlockSize
;
if
(
pCfg
->
totalBlocks
<
0
)
pCfg
->
totalBlocks
=
tsBlocksPerVnode
;
if
(
pCfg
->
maxTables
<
0
)
pCfg
->
maxTables
=
tsMaxTablePerVnode
;
...
...
@@ -307,13 +308,13 @@ static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) {
if
(
pCfg
->
replications
<
0
)
pCfg
->
replications
=
tsReplications
;
}
static
int32_t
m
gmt
CreateDb
(
SAcctObj
*
pAcct
,
SCMCreateDbMsg
*
pCreate
)
{
static
int32_t
m
node
CreateDb
(
SAcctObj
*
pAcct
,
SCMCreateDbMsg
*
pCreate
)
{
int32_t
code
=
acctCheck
(
pAcct
,
ACCT_GRANT_DB
);
if
(
code
!=
0
)
return
code
;
SDbObj
*
pDb
=
m
gmt
GetDb
(
pCreate
->
db
);
SDbObj
*
pDb
=
m
node
GetDb
(
pCreate
->
db
);
if
(
pDb
!=
NULL
)
{
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
if
(
pCreate
->
ignoreExist
)
{
mTrace
(
"db:%s, already exist, ignore exist is set"
,
pCreate
->
db
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -347,9 +348,9 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
.
replications
=
pCreate
->
replications
};
m
gmt
SetDefaultDbCfg
(
&
pDb
->
cfg
);
m
node
SetDefaultDbCfg
(
&
pDb
->
cfg
);
code
=
m
gmt
CheckDbCfg
(
&
pDb
->
cfg
);
code
=
m
node
CheckDbCfg
(
&
pDb
->
cfg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pDb
);
return
code
;
...
...
@@ -371,7 +372,7 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
return
code
;
}
bool
m
gmt
CheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
)
{
bool
m
node
CheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
)
{
char
dbName
[
TSDB_DB_NAME_LEN
+
1
]
=
{
0
};
extractDBName
(
db
,
dbName
);
...
...
@@ -397,7 +398,7 @@ void mgmtPrintVgroups(SDbObj *pDb, char *oper) {
}
#endif
void
m
gmt
AddVgroupIntoDb
(
SVgObj
*
pVgroup
)
{
void
m
node
AddVgroupIntoDb
(
SVgObj
*
pVgroup
)
{
SDbObj
*
pDb
=
pVgroup
->
pDb
;
pVgroup
->
next
=
pDb
->
pHead
;
...
...
@@ -410,7 +411,7 @@ void mgmtAddVgroupIntoDb(SVgObj *pVgroup) {
pDb
->
numOfVgroups
++
;
}
void
m
gmt
AddVgroupIntoDbTail
(
SVgObj
*
pVgroup
)
{
void
m
node
AddVgroupIntoDbTail
(
SVgObj
*
pVgroup
)
{
SDbObj
*
pDb
=
pVgroup
->
pDb
;
pVgroup
->
next
=
NULL
;
pVgroup
->
prev
=
pDb
->
pTail
;
...
...
@@ -422,7 +423,7 @@ void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup) {
pDb
->
numOfVgroups
++
;
}
void
m
gmt
RemoveVgroupFromDb
(
SVgObj
*
pVgroup
)
{
void
m
node
RemoveVgroupFromDb
(
SVgObj
*
pVgroup
)
{
SDbObj
*
pDb
=
pVgroup
->
pDb
;
if
(
pVgroup
->
prev
)
pVgroup
->
prev
->
next
=
pVgroup
->
next
;
if
(
pVgroup
->
next
)
pVgroup
->
next
->
prev
=
pVgroup
->
prev
;
...
...
@@ -431,25 +432,25 @@ void mgmtRemoveVgroupFromDb(SVgObj *pVgroup) {
pDb
->
numOfVgroups
--
;
}
void
m
gmt
MoveVgroupToTail
(
SVgObj
*
pVgroup
)
{
m
gmt
RemoveVgroupFromDb
(
pVgroup
);
m
gmt
AddVgroupIntoDbTail
(
pVgroup
);
void
m
node
MoveVgroupToTail
(
SVgObj
*
pVgroup
)
{
m
node
RemoveVgroupFromDb
(
pVgroup
);
m
node
AddVgroupIntoDbTail
(
pVgroup
);
}
void
m
gmt
MoveVgroupToHead
(
SVgObj
*
pVgroup
)
{
m
gmt
RemoveVgroupFromDb
(
pVgroup
);
m
gmt
AddVgroupIntoDb
(
pVgroup
);
void
m
node
MoveVgroupToHead
(
SVgObj
*
pVgroup
)
{
m
node
RemoveVgroupFromDb
(
pVgroup
);
m
node
AddVgroupIntoDb
(
pVgroup
);
}
void
m
gmtCleanU
pDbs
()
{
void
m
nodeCleanu
pDbs
()
{
sdbCloseTable
(
tsDbSdb
);
}
static
int32_t
m
gmt
GetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
static
int32_t
m
node
GetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
pShow
->
bytes
[
cols
]
=
TSDB_DB_NAME_LEN
+
VARSTR_HEADER_SIZE
;
...
...
@@ -583,32 +584,32 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
numOfRows
=
pUser
->
pAcct
->
acctInfo
.
numOfDbs
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
0
;
}
static
char
*
m
gmt
GetDbStr
(
char
*
src
)
{
static
char
*
m
node
GetDbStr
(
char
*
src
)
{
char
*
pos
=
strstr
(
src
,
TS_PATH_DELIMITER
);
return
++
pos
;
}
static
int32_t
m
gmt
RetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDbObj
*
pDb
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextDb
(
pShow
->
pIter
,
&
pDb
);
pShow
->
pIter
=
m
node
GetNextDb
(
pShow
->
pIter
,
&
pDb
);
if
(
pDb
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
name
=
m
gmt
GetDbStr
(
pDb
->
name
);
char
*
name
=
m
node
GetDbStr
(
pDb
->
name
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
name
,
TSDB_DB_NAME_LEN
);
cols
++
;
...
...
@@ -706,31 +707,31 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols
++
;
numOfRows
++
;
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
}
pShow
->
numOfReads
+=
numOfRows
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
numOfRows
;
}
void
m
gmt
AddSuperTableIntoDb
(
SDbObj
*
pDb
)
{
void
m
node
AddSuperTableIntoDb
(
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pDb
->
numOfSuperTables
,
1
);
}
void
m
gmt
RemoveSuperTableFromDb
(
SDbObj
*
pDb
)
{
void
m
node
RemoveSuperTableFromDb
(
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pDb
->
numOfSuperTables
,
-
1
);
}
void
m
gmt
AddTableIntoDb
(
SDbObj
*
pDb
)
{
void
m
node
AddTableIntoDb
(
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pDb
->
numOfTables
,
1
);
}
void
m
gmt
RemoveTableFromDb
(
SDbObj
*
pDb
)
{
void
m
node
RemoveTableFromDb
(
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pDb
->
numOfTables
,
-
1
);
}
static
int32_t
m
gmt
SetDbDropping
(
SDbObj
*
pDb
)
{
static
int32_t
m
node
SetDbDropping
(
SDbObj
*
pDb
)
{
if
(
pDb
->
status
)
return
TSDB_CODE_SUCCESS
;
pDb
->
status
=
true
;
...
...
@@ -748,7 +749,7 @@ static int32_t mgmtSetDbDropping(SDbObj *pDb) {
return
code
;
}
static
void
mgmt
ProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCreateDbMsg
*
pCreate
=
pMsg
->
pCont
;
pCreate
->
maxTables
=
htonl
(
pCreate
->
maxTables
);
...
...
@@ -768,7 +769,7 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) {
}
else
if
(
!
pMsg
->
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
m
gmt
CreateDb
(
pMsg
->
pUser
->
pAcct
,
pCreate
);
code
=
m
node
CreateDb
(
pMsg
->
pUser
->
pAcct
,
pCreate
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"db:%s, is created by %s"
,
pCreate
->
db
,
pMsg
->
pUser
->
user
);
}
else
{
...
...
@@ -776,10 +777,10 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) {
}
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
return
code
;
}
static
SDbCfg
m
gmt
GetAlterDbOption
(
SDbObj
*
pDb
,
SCMAlterDbMsg
*
pAlter
)
{
static
SDbCfg
m
node
GetAlterDbOption
(
SDbObj
*
pDb
,
SCMAlterDbMsg
*
pAlter
)
{
SDbCfg
newCfg
=
pDb
->
cfg
;
int32_t
maxTables
=
htonl
(
pAlter
->
maxTables
);
int32_t
cacheBlockSize
=
htonl
(
pAlter
->
cacheBlockSize
);
...
...
@@ -876,7 +877,7 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
terrno
=
TSDB_CODE_INVALID_OPTION
;
}
if
(
replications
>
m
gmt
GetDnodesNum
())
{
if
(
replications
>
m
node
GetDnodesNum
())
{
mError
(
"db:%s, no enough dnode to change replica:%d"
,
pDb
->
name
,
replications
);
terrno
=
TSDB_CODE_NO_ENOUGH_DNODES
;
}
...
...
@@ -890,13 +891,13 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
return
newCfg
;
}
static
int32_t
m
gmt
AlterDb
(
SDbObj
*
pDb
,
SCMAlterDbMsg
*
pAlter
)
{
SDbCfg
newCfg
=
m
gmt
GetAlterDbOption
(
pDb
,
pAlter
);
static
int32_t
m
node
AlterDb
(
SDbObj
*
pDb
,
SCMAlterDbMsg
*
pAlter
)
{
SDbCfg
newCfg
=
m
node
GetAlterDbOption
(
pDb
,
pAlter
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
return
terrno
;
}
int32_t
code
=
m
gmt
CheckDbCfg
(
&
newCfg
);
int32_t
code
=
m
node
CheckDbCfg
(
&
newCfg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -921,10 +922,10 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
void
*
pIter
=
NULL
;
while
(
1
)
{
SVgObj
*
pVgroup
=
NULL
;
pIter
=
m
gmt
GetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
m
node
GetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
m
gmt
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
m
node
DecVgroupRef
(
pVgroup
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -935,35 +936,27 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
return
TSDB_CODE_SUCCESS
;
}
static
void
mgmt
ProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
)
{
SCMAlterDbMsg
*
pAlter
=
pMsg
->
pCont
;
mTrace
(
"db:%s, alter db msg is received from thandle:%p"
,
pAlter
->
db
,
pMsg
->
thandle
);
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"db:%s, failed to alter, grant expired"
,
pAlter
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_GRANT_EXPIRED
);
return
;
}
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mgmtGetDb
(
pAlter
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDb
(
pAlter
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"db:%s, failed to alter, invalid db"
,
pAlter
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_DB
);
return
;
return
TSDB_CODE_INVALID_DB
;
}
int32_t
code
=
m
gmt
AlterDb
(
pMsg
->
pDb
,
pAlter
);
int32_t
code
=
m
node
AlterDb
(
pMsg
->
pDb
,
pAlter
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"db:%s, failed to alter, invalid db option"
,
pAlter
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
return
code
;
}
mTrace
(
"db:%s, all vgroups is altered"
,
pMsg
->
pDb
->
name
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
)
;
return
TSDB_CODE_SUCCESS
;
}
static
void
mgmt
DropDb
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
DropDb
(
SMnodeMsg
*
pMsg
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
mPrint
(
"db:%s, drop db from sdb"
,
pDb
->
name
);
...
...
@@ -977,64 +970,54 @@ static void mgmtDropDb(SMnodeMsg *pMsg) {
code
=
TSDB_CODE_SDB_ERROR
;
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
return
code
;
}
static
void
mgmt
ProcessDropDbMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessDropDbMsg
(
SMnodeMsg
*
pMsg
)
{
SCMDropDbMsg
*
pDrop
=
pMsg
->
pCont
;
mTrace
(
"db:%s, drop db msg is received from thandle:%p"
,
pDrop
->
db
,
pMsg
->
thandle
);
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"db:%s, failed to drop, grant expired"
,
pDrop
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_GRANT_EXPIRED
);
return
;
}
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mgmtGetDb
(
pDrop
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDb
(
pDrop
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
{
if
(
pDrop
->
ignoreNotExists
)
{
mTrace
(
"db:%s, db is not exist, think drop success"
,
pDrop
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
);
return
;
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"db:%s, failed to drop, invalid db"
,
pDrop
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_DB
);
return
;
return
TSDB_CODE_INVALID_DB
;
}
}
if
(
m
gmt
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
if
(
m
node
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"db:%s, can't drop monitor database"
,
pDrop
->
db
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_MONITOR_DB_FORBIDDEN
);
return
;
return
TSDB_CODE_MONITOR_DB_FORBIDDEN
;
}
int32_t
code
=
m
gmt
SetDbDropping
(
pMsg
->
pDb
);
int32_t
code
=
m
node
SetDbDropping
(
pMsg
->
pDb
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"db:%s, failed to drop, reason:%s"
,
pDrop
->
db
,
tstrerror
(
code
));
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
return
code
;
}
#if 1
m
gmt
DropAllDbVgroups
(
pMsg
->
pDb
,
true
);
m
node
DropAllDbVgroups
(
pMsg
->
pDb
,
true
);
#else
SVgObj
*
pVgroup
=
pMsg
->
pDb
->
pHead
;
if
(
pVgroup
!=
NULL
)
{
mPrint
(
"vgId:%d, will be dropped"
,
pVgroup
->
vgId
);
SMnodeMsg
*
newMsg
=
m
gmtCloneQueued
Msg
(
pMsg
);
SMnodeMsg
*
newMsg
=
m
nodeClone
Msg
(
pMsg
);
newMsg
->
ahandle
=
pVgroup
;
newMsg
->
expected
=
pVgroup
->
numOfVnodes
;
m
gmt
DropVgroup
(
pVgroup
,
newMsg
);
m
node
DropVgroup
(
pVgroup
,
newMsg
);
return
;
}
#endif
mTrace
(
"db:%s, all vgroups is dropped"
,
pMsg
->
pDb
->
name
);
mgmt
DropDb
(
pMsg
);
return
mnode
DropDb
(
pMsg
);
}
void
m
gmt
DropAllDbs
(
SAcctObj
*
pAcct
)
{
void
m
node
DropAllDbs
(
SAcctObj
*
pAcct
)
{
int32_t
numOfDbs
=
0
;
SDbObj
*
pDb
=
NULL
;
void
*
pIter
=
NULL
;
...
...
@@ -1042,7 +1025,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
mPrint
(
"acct:%s, all dbs will be dropped from sdb"
,
pAcct
->
user
);
while
(
1
)
{
pIter
=
m
gmt
GetNextDb
(
pIter
,
&
pDb
);
pIter
=
m
node
GetNextDb
(
pIter
,
&
pDb
);
if
(
pDb
==
NULL
)
break
;
if
(
pDb
->
pAcct
==
pAcct
)
{
...
...
@@ -1056,7 +1039,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
sdbDeleteRow
(
&
oper
);
numOfDbs
++
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
}
sdbFreeIter
(
pIter
);
...
...
src/mnode/src/mnodeDnode.c
浏览文件 @
cf687279
...
...
@@ -25,15 +25,18 @@
#include "tbalance.h"
#include "tsync.h"
#include "tdataformat.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
#include "mnodeSdb.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeWrite.h"
#include "mnodePeer.h"
int32_t
tsAccessSquence
=
0
;
static
void
*
tsDnodeSdb
=
NULL
;
...
...
@@ -41,27 +44,27 @@ static int32_t tsDnodeUpdateSize = 0;
extern
void
*
tsMnodeSdb
;
extern
void
*
tsVgroupSdb
;
static
int32_t
m
gmt
CreateDnode
(
char
*
ep
);
static
void
mgmt
ProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessCfgDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
void
m
gmt
ProcessCfgDnodeMsgRsp
(
SRpcMsg
*
rpcMsg
)
;
static
void
mgmtProcessDnodeStatusMsg
(
SRpc
Msg
*
rpcMsg
);
static
int32_t
m
gmt
GetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
GetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
GetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
GetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
DnodeActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
CreateDnode
(
char
*
ep
);
static
int32_t
mnode
ProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessCfgDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
void
m
node
ProcessCfgDnodeMsgRsp
(
SRpcMsg
*
rpcMsg
)
;
static
int32_t
mnodeProcessDnodeStatusMsg
(
SMnode
Msg
*
rpcMsg
);
static
int32_t
m
node
GetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
GetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
GetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
GetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
DnodeActionDestroy
(
SSdbOper
*
pOper
)
{
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DnodeActionInsert
(
SSdbOper
*
pOper
)
{
SDnodeObj
*
pDnode
=
pOper
->
pObj
;
if
(
pDnode
->
status
!=
TAOS_DN_STATUS_DROPPING
)
{
pDnode
->
status
=
TAOS_DN_STATUS_OFFLINE
;
...
...
@@ -70,38 +73,38 @@ static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DnodeActionDelete
(
SSdbOper
*
pOper
)
{
SDnodeObj
*
pDnode
=
pOper
->
pObj
;
#ifndef _SYNC
m
gmt
DropAllDnodeVgroups
(
pDnode
);
m
node
DropAllDnodeVgroups
(
pDnode
);
#endif
m
gmt
DropMnodeLocal
(
pDnode
->
dnodeId
);
m
node
DropMnodeLocal
(
pDnode
->
dnodeId
);
balanceNotify
();
mTrace
(
"dnode:%d, all vgroups is dropped from sdb"
,
pDnode
->
dnodeId
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DnodeActionUpdate
(
SSdbOper
*
pOper
)
{
SDnodeObj
*
pDnode
=
pOper
->
pObj
;
SDnodeObj
*
pSaved
=
m
gmt
GetDnode
(
pDnode
->
dnodeId
);
SDnodeObj
*
pSaved
=
m
node
GetDnode
(
pDnode
->
dnodeId
);
if
(
pDnode
!=
pSaved
)
{
memcpy
(
pSaved
,
pDnode
,
pOper
->
rowSize
);
free
(
pDnode
);
}
m
gmt
DecDnodeRef
(
pSaved
);
m
node
DecDnodeRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DnodeActionEncode
(
SSdbOper
*
pOper
)
{
SDnodeObj
*
pDnode
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pDnode
,
tsDnodeUpdateSize
);
pOper
->
rowSize
=
tsDnodeUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
DnodeActionDecode
(
SSdbOper
*
pOper
)
{
SDnodeObj
*
pDnode
=
(
SDnodeObj
*
)
calloc
(
1
,
sizeof
(
SDnodeObj
));
if
(
pDnode
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -110,19 +113,19 @@ static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DnodeActionRestored
()
{
static
int32_t
m
node
DnodeActionRestored
()
{
int32_t
numOfRows
=
sdbGetNumOfRows
(
tsDnodeSdb
);
if
(
numOfRows
<=
0
&&
dnodeIsFirstDeploy
())
{
m
gmt
CreateDnode
(
tsLocalEp
);
SDnodeObj
*
pDnode
=
m
gmt
GetDnodeByEp
(
tsLocalEp
);
m
gmt
AddMnode
(
pDnode
->
dnodeId
);
m
gmt
DecDnodeRef
(
pDnode
);
m
node
CreateDnode
(
tsLocalEp
);
SDnodeObj
*
pDnode
=
m
node
GetDnodeByEp
(
tsLocalEp
);
m
node
AddMnode
(
pDnode
->
dnodeId
);
m
node
DecDnodeRef
(
pDnode
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
InitDnodes
()
{
int32_t
m
node
InitDnodes
()
{
SDnodeObj
tObj
;
tsDnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -133,13 +136,13 @@ int32_t mgmtInitDnodes() {
.
maxRowSize
=
tsDnodeUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_AUTO
,
.
insertFp
=
m
gmt
DnodeActionInsert
,
.
deleteFp
=
m
gmt
DnodeActionDelete
,
.
updateFp
=
m
gmt
DnodeActionUpdate
,
.
encodeFp
=
m
gmt
DnodeActionEncode
,
.
decodeFp
=
m
gmt
DnodeActionDecode
,
.
destroyFp
=
m
gmt
DnodeActionDestroy
,
.
restoredFp
=
m
gmt
DnodeActionRestored
.
insertFp
=
m
node
DnodeActionInsert
,
.
deleteFp
=
m
node
DnodeActionDelete
,
.
updateFp
=
m
node
DnodeActionUpdate
,
.
encodeFp
=
m
node
DnodeActionEncode
,
.
decodeFp
=
m
node
DnodeActionDecode
,
.
destroyFp
=
m
node
DnodeActionDestroy
,
.
restoredFp
=
m
node
DnodeActionRestored
};
tsDnodeSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -148,19 +151,19 @@ int32_t mgmtInitDnodes() {
return
-
1
;
}
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DNODE
,
mgmt
ProcessCreateDnodeMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DNODE
,
mgmt
ProcessDropDnodeMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CONFIG_DNODE
,
mgmt
ProcessCfgDnodeMsg
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP
,
mgmt
ProcessCfgDnodeMsgRsp
);
dnodeAddServerMsgHandle
(
TSDB_MSG_TYPE_DM_STATUS
,
mgmt
ProcessDnodeStatusMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_MODULE
,
mgmt
GetModuleMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_MODULE
,
mgmt
RetrieveModules
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_CONFIGS
,
mgmt
GetConfigMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_CONFIGS
,
mgmt
RetrieveConfigs
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_VNODES
,
mgmt
GetVnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_VNODES
,
mgmt
RetrieveVnodes
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_DNODE
,
mgmt
GetDnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_DNODE
,
mgmt
RetrieveDnodes
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DNODE
,
mnode
ProcessCreateDnodeMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DNODE
,
mnode
ProcessDropDnodeMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CONFIG_DNODE
,
mnode
ProcessCfgDnodeMsg
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP
,
mnode
ProcessCfgDnodeMsgRsp
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_STATUS
,
mnode
ProcessDnodeStatusMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_MODULE
,
mnode
GetModuleMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_MODULE
,
mnode
RetrieveModules
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_CONFIGS
,
mnode
GetConfigMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_CONFIGS
,
mnode
RetrieveConfigs
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_VNODES
,
mnode
GetVnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_VNODES
,
mnode
RetrieveVnodes
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_DNODE
,
mnode
GetDnodeMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_DNODE
,
mnode
RetrieveDnodes
);
mTrace
(
"table:dnodes table is created"
);
return
0
;
...
...
@@ -170,24 +173,24 @@ void mgmtCleanupDnodes() {
sdbCloseTable
(
tsDnodeSdb
);
}
void
*
m
gmt
GetNextDnode
(
void
*
pIter
,
SDnodeObj
**
pDnode
)
{
void
*
m
node
GetNextDnode
(
void
*
pIter
,
SDnodeObj
**
pDnode
)
{
return
sdbFetchRow
(
tsDnodeSdb
,
pIter
,
(
void
**
)
pDnode
);
}
int32_t
m
gmt
GetDnodesNum
()
{
int32_t
m
node
GetDnodesNum
()
{
return
sdbGetNumOfRows
(
tsDnodeSdb
);
}
int32_t
m
gmt
GetOnlinDnodesNum
(
char
*
ep
)
{
int32_t
m
node
GetOnlinDnodesNum
(
char
*
ep
)
{
SDnodeObj
*
pDnode
=
NULL
;
void
*
pIter
=
NULL
;
int32_t
onlineDnodes
=
0
;
while
(
1
)
{
pIter
=
m
gmt
GetNextDnode
(
pIter
,
&
pDnode
);
pIter
=
m
node
GetNextDnode
(
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
->
status
!=
TAOS_DN_STATUS_OFFLINE
)
onlineDnodes
++
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -195,22 +198,22 @@ int32_t mgmtGetOnlinDnodesNum(char *ep) {
return
onlineDnodes
;
}
void
*
m
gmt
GetDnode
(
int32_t
dnodeId
)
{
void
*
m
node
GetDnode
(
int32_t
dnodeId
)
{
return
sdbGetRow
(
tsDnodeSdb
,
&
dnodeId
);
}
void
*
m
gmt
GetDnodeByEp
(
char
*
ep
)
{
void
*
m
node
GetDnodeByEp
(
char
*
ep
)
{
SDnodeObj
*
pDnode
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
m
gmt
GetNextDnode
(
pIter
,
&
pDnode
);
pIter
=
m
node
GetNextDnode
(
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
if
(
strcmp
(
ep
,
pDnode
->
dnodeEp
)
==
0
)
{
sdbFreeIter
(
pIter
);
return
pDnode
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -218,15 +221,15 @@ void *mgmtGetDnodeByEp(char *ep) {
return
NULL
;
}
void
m
gmt
IncDnodeRef
(
SDnodeObj
*
pDnode
)
{
void
m
node
IncDnodeRef
(
SDnodeObj
*
pDnode
)
{
sdbIncRef
(
tsDnodeSdb
,
pDnode
);
}
void
m
gmt
DecDnodeRef
(
SDnodeObj
*
pDnode
)
{
void
m
node
DecDnodeRef
(
SDnodeObj
*
pDnode
)
{
sdbDecRef
(
tsDnodeSdb
,
pDnode
);
}
void
m
gmt
UpdateDnode
(
SDnodeObj
*
pDnode
)
{
void
m
node
UpdateDnode
(
SDnodeObj
*
pDnode
)
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsDnodeSdb
,
...
...
@@ -236,9 +239,7 @@ void mgmtUpdateDnode(SDnodeObj *pDnode) {
sdbUpdateRow
(
&
oper
);
}
void
mgmtProcessCfgDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
static
int32_t
mnodeProcessCfgDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCfgDnodeMsg
*
pCmCfgDnode
=
pMsg
->
pCont
;
if
(
pCmCfgDnode
->
ep
[
0
]
==
0
)
{
strcpy
(
pCmCfgDnode
->
ep
,
tsLocalEp
);
...
...
@@ -247,12 +248,14 @@ void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
}
if
(
strcmp
(
pMsg
->
pUser
->
user
,
"root"
)
!=
0
)
{
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
SRpcIpSet
ipSet
=
mgmtGetIpSetFromIp
(
pCmCfgDnode
->
ep
);
return
TSDB_CODE_NO_RIGHTS
;
}
SRpcIpSet
ipSet
=
mnodeGetIpSetFromIp
(
pCmCfgDnode
->
ep
);
SMDCfgDnodeMsg
*
pMdCfgDnode
=
rpcMallocCont
(
sizeof
(
SMDCfgDnodeMsg
));
strcpy
(
pMdCfgDnode
->
ep
,
pCmCfgDnode
->
ep
);
strcpy
(
pMdCfgDnode
->
config
,
pCmCfgDnode
->
config
);
SRpcMsg
rpcMdCfgDnodeMsg
=
{
.
handle
=
0
,
.
code
=
0
,
...
...
@@ -261,22 +264,18 @@ void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
.
contLen
=
sizeof
(
SMDCfgDnodeMsg
)
};
dnodeSendMsgToDnode
(
&
ipSet
,
&
rpcMdCfgDnodeMsg
);
rpcRsp
.
code
=
TSDB_CODE_SUCCESS
;
}
if
(
rpcRsp
.
code
==
TSDB_CODE_SUCCESS
)
{
mPrint
(
"dnode:%s, is configured by %s"
,
pCmCfgDnode
->
ep
,
pMsg
->
pUser
->
user
);
}
r
pcSendResponse
(
&
rpcRsp
)
;
r
eturn
TSDB_CODE_SUCCESS
;
}
static
void
m
gmt
ProcessCfgDnodeMsgRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessCfgDnodeMsgRsp
(
SRpcMsg
*
rpcMsg
)
{
mPrint
(
"cfg dnode rsp is received"
);
}
void
mgmtProcessDnodeStatusMsg
(
SRpcMsg
*
rpc
Msg
)
{
SDMStatusMsg
*
pStatus
=
rpc
Msg
->
pCont
;
static
int32_t
mnodeProcessDnodeStatusMsg
(
SMnodeMsg
*
p
Msg
)
{
SDMStatusMsg
*
pStatus
=
p
Msg
->
pCont
;
pStatus
->
dnodeId
=
htonl
(
pStatus
->
dnodeId
);
pStatus
->
moduleStatus
=
htonl
(
pStatus
->
moduleStatus
);
pStatus
->
lastReboot
=
htonl
(
pStatus
->
lastReboot
);
...
...
@@ -286,24 +285,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
uint32_t
version
=
htonl
(
pStatus
->
version
);
if
(
version
!=
tsVersion
)
{
mError
(
"status msg version:%d not equal with mnode:%d"
,
version
,
tsVersion
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_INVALID_MSG_VERSION
);
return
;
return
TSDB_CODE_INVALID_MSG_VERSION
;
}
SDnodeObj
*
pDnode
=
NULL
;
if
(
pStatus
->
dnodeId
==
0
)
{
pDnode
=
m
gmt
GetDnodeByEp
(
pStatus
->
dnodeEp
);
pDnode
=
m
node
GetDnodeByEp
(
pStatus
->
dnodeEp
);
if
(
pDnode
==
NULL
)
{
mTrace
(
"dnode %s not created"
,
pStatus
->
dnodeEp
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_DNODE_NOT_EXIST
);
return
;
return
TSDB_CODE_DNODE_NOT_EXIST
;
}
}
else
{
pDnode
=
m
gmt
GetDnode
(
pStatus
->
dnodeId
);
pDnode
=
m
node
GetDnode
(
pStatus
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"dnode id:%d, %s not exist"
,
pStatus
->
dnodeId
,
pStatus
->
dnodeEp
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_DNODE_NOT_EXIST
);
return
;
return
TSDB_CODE_DNODE_NOT_EXIST
;
}
}
...
...
@@ -327,34 +323,33 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
pVload
->
vgId
=
htonl
(
pVload
->
vgId
);
pVload
->
cfgVersion
=
htonl
(
pVload
->
cfgVersion
);
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pVload
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pVload
->
vgId
);
if
(
pVgroup
==
NULL
)
{
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
mPrint
(
"dnode:%d, vgId:%d not exist in mnode, drop it"
,
pDnode
->
dnodeId
,
pVload
->
vgId
);
m
gmt
SendDropVnodeMsg
(
pVload
->
vgId
,
&
ipSet
,
NULL
);
m
node
SendDropVnodeMsg
(
pVload
->
vgId
,
&
ipSet
,
NULL
);
}
else
{
m
gmt
UpdateVgroupStatus
(
pVgroup
,
pDnode
,
pVload
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
UpdateVgroupStatus
(
pVgroup
,
pDnode
,
pVload
);
m
node
DecVgroupRef
(
pVgroup
);
}
}
if
(
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
mTrace
(
"dnode:%d, from offline to online"
,
pDnode
->
dnodeId
);
pDnode
->
status
=
TAOS_DN_STATUS_READY
;
balanceUpdateM
gmt
();
balanceUpdateM
node
();
balanceNotify
();
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
int32_t
contLen
=
sizeof
(
SDMStatusRsp
)
+
TSDB_MAX_VNODES
*
sizeof
(
SDMVgroupAccess
);
SDMStatusRsp
*
pRsp
=
rpcMallocCont
(
contLen
);
if
(
pRsp
==
NULL
)
{
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
m
gmt
GetMnodeInfos
(
&
pRsp
->
mnodes
);
m
node
GetMnodeInfos
(
&
pRsp
->
mnodes
);
pRsp
->
dnodeCfg
.
dnodeId
=
htonl
(
pDnode
->
dnodeId
);
pRsp
->
dnodeCfg
.
moduleStatus
=
htonl
((
int32_t
)
pDnode
->
isMgmt
);
...
...
@@ -364,25 +359,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
//TODO: set vnode access
SRpcMsg
rpcRsp
=
{
.
handle
=
rpcMsg
->
handle
,
.
code
=
TSDB_CODE_SUCCESS
,
.
pCont
=
pRsp
,
.
contLen
=
contLen
};
pMsg
->
rpcRsp
.
len
=
contLen
;
pMsg
->
rpcRsp
.
rsp
=
pRsp
;
r
pcSendResponse
(
&
rpcRsp
)
;
r
eturn
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
CreateDnode
(
char
*
ep
)
{
static
int32_t
m
node
CreateDnode
(
char
*
ep
)
{
int32_t
grantCode
=
grantCheck
(
TSDB_GRANT_DNODE
);
if
(
grantCode
!=
TSDB_CODE_SUCCESS
)
{
return
grantCode
;
}
SDnodeObj
*
pDnode
=
m
gmt
GetDnodeByEp
(
ep
);
SDnodeObj
*
pDnode
=
m
node
GetDnodeByEp
(
ep
);
if
(
pDnode
!=
NULL
)
{
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
mError
(
"dnode:%d is alredy exist, %s:%d"
,
pDnode
->
dnodeId
,
pDnode
->
dnodeFqdn
,
pDnode
->
dnodePort
);
return
TSDB_CODE_DNODE_ALREADY_EXIST
;
}
...
...
@@ -413,7 +404,7 @@ static int32_t mgmtCreateDnode(char *ep) {
return
code
;
}
int32_t
m
gmt
DropDnode
(
SDnodeObj
*
pDnode
)
{
int32_t
m
node
DropDnode
(
SDnodeObj
*
pDnode
)
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsDnodeSdb
,
...
...
@@ -429,15 +420,14 @@ int32_t mgmtDropDnode(SDnodeObj *pDnode) {
return
code
;
}
static
int32_t
mgmtDropDnodeByEp
(
char
*
ep
)
{
SDnodeObj
*
pDnode
=
mgmtGetDnodeByEp
(
ep
);
static
int32_t
mnodeDropDnodeByEp
(
char
*
ep
)
{
SDnodeObj
*
pDnode
=
mnodeGetDnodeByEp
(
ep
);
if
(
pDnode
==
NULL
)
{
mError
(
"dnode:%s, is not exist"
,
ep
);
return
TSDB_CODE_DNODE_NOT_EXIST
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
if
(
strcmp
(
pDnode
->
dnodeEp
,
dnodeGetMnodeMasterEp
())
==
0
)
{
mError
(
"dnode:%d, can't drop dnode:%s which is master"
,
pDnode
->
dnodeId
,
ep
);
return
TSDB_CODE_NO_REMOVE_MASTER
;
...
...
@@ -445,58 +435,56 @@ static int32_t mgmtDropDnodeByEp(char *ep) {
mPrint
(
"dnode:%d, start to drop it"
,
pDnode
->
dnodeId
);
#ifndef _SYNC
return
m
gmt
DropDnode
(
pDnode
);
return
m
node
DropDnode
(
pDnode
);
#else
return
balanceDropDnode
(
pDnode
);
#endif
}
static
void
mgmtProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
static
int32_t
mnodeProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCreateDnodeMsg
*
pCreate
=
pMsg
->
pCont
;
if
(
strcmp
(
pMsg
->
pUser
->
user
,
"root"
)
!=
0
)
{
r
pcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
r
eturn
TSDB_CODE_NO_RIGHTS
;
}
else
{
rpcRsp
.
code
=
mgmtCreateDnode
(
pCreate
->
ep
);
if
(
rpcRsp
.
code
==
TSDB_CODE_SUCCESS
)
{
SDnodeObj
*
pDnode
=
mgmtGetDnodeByEp
(
pCreate
->
ep
);
int32_t
code
=
mnodeCreateDnode
(
pCreate
->
ep
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
SDnodeObj
*
pDnode
=
mnodeGetDnodeByEp
(
pCreate
->
ep
);
mLPrint
(
"dnode:%d, %s is created by %s"
,
pDnode
->
dnodeId
,
pCreate
->
ep
,
pMsg
->
pUser
->
user
);
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
else
{
mError
(
"failed to create dnode:%s, reason:%s"
,
pCreate
->
ep
,
tstrerror
(
rpcRsp
.
code
));
mError
(
"failed to create dnode:%s, reason:%s"
,
pCreate
->
ep
,
tstrerror
(
code
));
}
return
code
;
}
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
static
int32_t
mnodeProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SCMDropDnodeMsg
*
pDrop
=
pMsg
->
pCont
;
if
(
strcmp
(
pMsg
->
pUser
->
user
,
"root"
)
!=
0
)
{
r
pcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
r
eturn
TSDB_CODE_NO_RIGHTS
;
}
else
{
rpcRsp
.
code
=
mgmtDropDnodeByEp
(
pDrop
->
ep
);
if
(
rpcRsp
.
code
==
TSDB_CODE_SUCCESS
)
{
int32_t
code
=
mnodeDropDnodeByEp
(
pDrop
->
ep
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"dnode:%s is dropped by %s"
,
pDrop
->
ep
,
pMsg
->
pUser
->
user
);
}
else
{
mError
(
"failed to drop dnode:%s, reason:%s"
,
pDrop
->
ep
,
tstrerror
(
rpcRsp
.
code
));
}
mError
(
"failed to drop dnode:%s, reason:%s"
,
pDrop
->
ep
,
tstrerror
(
code
));
}
rpcSendResponse
(
&
rpcRsp
);
return
code
;
}
}
static
int32_t
m
gmt
GetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
static
int32_t
m
node
GetDnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
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
;
}
...
...
@@ -547,23 +535,23 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
m
gmt
GetDnodesNum
();
pShow
->
numOfRows
=
m
node
GetDnodesNum
();
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
RetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveDnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextDnode
(
pShow
->
pIter
,
&
pDnode
);
pShow
->
pIter
=
m
node
GetNextDnode
(
pShow
->
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
cols
=
0
;
...
...
@@ -586,7 +574,7 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
status
=
m
gmt
GetDnodeStatusStr
(
pDnode
->
status
);
char
*
status
=
m
node
GetDnodeStatusStr
(
pDnode
->
status
);
STR_TO_VARSTR
(
pWrite
,
status
);
cols
++
;
...
...
@@ -596,26 +584,26 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
numOfRows
++
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
bool
m
gmt
CheckModuleInDnode
(
SDnodeObj
*
pDnode
,
int32_t
moduleType
)
{
static
bool
m
node
CheckModuleInDnode
(
SDnodeObj
*
pDnode
,
int32_t
moduleType
)
{
uint32_t
status
=
pDnode
->
moduleStatus
&
(
1
<<
moduleType
);
return
status
>
0
;
}
static
int32_t
m
gmt
GetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
static
int32_t
m
node
GetModuleMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
...
...
@@ -653,21 +641,21 @@ static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
m
gmt
GetDnodesNum
()
*
TSDB_MOD_MAX
;
pShow
->
numOfRows
=
m
node
GetDnodesNum
()
*
TSDB_MOD_MAX
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
NULL
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
0
;
}
int32_t
m
gmt
RetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveModules
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
SDnodeObj
*
pDnode
=
NULL
;
pShow
->
pIter
=
m
gmt
GetNextDnode
(
pShow
->
pIter
,
(
SDnodeObj
**
)
&
pDnode
);
pShow
->
pIter
=
m
node
GetNextDnode
(
pShow
->
pIter
,
(
SDnodeObj
**
)
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
for
(
int32_t
moduleType
=
0
;
moduleType
<
TSDB_MOD_MAX
;
++
moduleType
)
{
...
...
@@ -698,34 +686,34 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
bool
enable
=
m
gmt
CheckModuleInDnode
(
pDnode
,
moduleType
);
bool
enable
=
m
node
CheckModuleInDnode
(
pDnode
,
moduleType
);
strcpy
(
pWrite
,
enable
?
"enable"
:
"disable"
);
cols
++
;
numOfRows
++
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
bool
m
gmt
CheckConfigShow
(
SGlobalCfg
*
cfg
)
{
static
bool
m
node
CheckConfigShow
(
SGlobalCfg
*
cfg
)
{
if
(
!
(
cfg
->
cfgType
&
TSDB_CFG_CTYPE_B_SHOW
))
return
false
;
return
true
;
}
static
int32_t
m
gmt
GetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
static
int32_t
m
node
GetConfigMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
...
...
@@ -752,23 +740,23 @@ static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
pShow
->
numOfRows
=
0
;
for
(
int32_t
i
=
tsGlobalConfigNum
-
1
;
i
>=
0
;
--
i
)
{
SGlobalCfg
*
cfg
=
tsGlobalConfig
+
i
;
if
(
!
m
gmt
CheckConfigShow
(
cfg
))
continue
;
if
(
!
m
node
CheckConfigShow
(
cfg
))
continue
;
pShow
->
numOfRows
++
;
}
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
RetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveConfigs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
for
(
int32_t
i
=
tsGlobalConfigNum
-
1
;
i
>=
0
&&
numOfRows
<
rows
;
--
i
)
{
SGlobalCfg
*
cfg
=
tsGlobalConfig
+
i
;
if
(
!
m
gmt
CheckConfigShow
(
cfg
))
continue
;
if
(
!
m
node
CheckConfigShow
(
cfg
))
continue
;
char
*
pWrite
;
int32_t
cols
=
0
;
...
...
@@ -806,13 +794,13 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo
return
numOfRows
;
}
static
int32_t
m
gmt
GetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
static
int32_t
m
node
GetVnodeMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
...
...
@@ -838,25 +826,25 @@ static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
SDnodeObj
*
pDnode
=
NULL
;
if
(
pShow
->
payloadLen
>
0
)
{
pDnode
=
m
gmt
GetDnodeByEp
(
pShow
->
payload
);
pDnode
=
m
node
GetDnodeByEp
(
pShow
->
payload
);
}
else
{
void
*
pIter
=
m
gmt
GetNextDnode
(
NULL
,
(
SDnodeObj
**
)
&
pDnode
);
void
*
pIter
=
m
node
GetNextDnode
(
NULL
,
(
SDnodeObj
**
)
&
pDnode
);
sdbFreeIter
(
pIter
);
}
if
(
pDnode
!=
NULL
)
{
pShow
->
numOfRows
+=
pDnode
->
openVnodes
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
pDnode
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
0
;
}
static
int32_t
m
gmt
RetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveVnodes
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
...
...
@@ -869,7 +857,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
void
*
pIter
=
NULL
;
SVgObj
*
pVgroup
;
while
(
1
)
{
pIter
=
m
gmt
GetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
m
node
GetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
...
...
@@ -882,12 +870,12 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
m
gmt
GetMnodeRoleStr
(
pVgid
->
role
));
strcpy
(
pWrite
,
m
node
GetMnodeRoleStr
(
pVgid
->
role
));
cols
++
;
}
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
sdbFreeIter
(
pIter
);
}
else
{
...
...
@@ -898,7 +886,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
return
numOfRows
;
}
char
*
m
gmt
GetDnodeStatusStr
(
int32_t
dnodeStatus
)
{
char
*
m
node
GetDnodeStatusStr
(
int32_t
dnodeStatus
)
{
switch
(
dnodeStatus
)
{
case
TAOS_DN_STATUS_OFFLINE
:
return
"offline"
;
case
TAOS_DN_STATUS_DROPPING
:
return
"dropping"
;
...
...
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
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)
#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)
#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
=
mgmt
GetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
// SUserObj *pUser = mnode
GetUserFromConn(pMsg->thandle);
//
if (pUser == NULL) {
//
rpcRsp.code = TSDB_CODE_INVALID_USER;
//
rpcSendResponse(&rpcRsp);
//
return;
//
}
SCMKillQueryMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
//
SCMKillQueryMsg *pKill = pMsg->pCont;
//
int32_t code;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillQuery
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
//
if (!pUser->writeAuth) {
//
code = TSDB_CODE_NO_RIGHTS;
//
} else {
//
code = mgmtKillQuery(pKill->queryId, pMsg->thandle);
//
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// 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
=
mgmt
GetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
// SUserObj *pUser = mnode
GetUserFromConn(pMsg->thandle);
//
if (pUser == NULL) {
//
rpcRsp.code = TSDB_CODE_INVALID_USER;
//
rpcSendResponse(&rpcRsp);
//
return;
//
}
SCMKillStreamMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
//
SCMKillStreamMsg *pKill = pMsg->pCont;
//
int32_t code;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillStream
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
//
if (!pUser->writeAuth) {
//
code = TSDB_CODE_NO_RIGHTS;
//
} else {
//
code = mgmtKillStream(pKill->queryId, pMsg->thandle);
//
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// 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
=
mgmt
GetUserFromConn
(
pMsg
->
thandle
);
if
(
pUser
==
NULL
)
{
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
// SUserObj *pUser = mnode
GetUserFromConn(pMsg->thandle);
//
if (pUser == NULL) {
//
rpcRsp.code = TSDB_CODE_INVALID_USER;
//
rpcSendResponse(&rpcRsp);
//
return;
//
}
SCMKillConnMsg
*
pKill
=
pMsg
->
pCont
;
int32_t
code
;
//
SCMKillConnMsg *pKill = pMsg->pCont;
//
int32_t code;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillConnection
(
pKill
->
queryId
,
pMsg
->
thandle
);
}
//
if (!pUser->writeAuth) {
//
code = TSDB_CODE_NO_RIGHTS;
//
} else {
//
code = mgmtKillConnection(pKill->queryId, pMsg->thandle);
//
}
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
mgmtDecUserRef
(
pUser
);
// 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
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
);
}
static
void
mnodeProcessUseMsg
(
SMnodeMsg
*
pMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
return
code
;
}
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
;
}
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
;
return
code
;
}
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,7 +310,7 @@ 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
);
...
...
@@ -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
...
...
@@ -24,64 +24,68 @@
#include "tname.h"
#include "tidpool.h"
#include "tglobal.h"
#include "tcompare.h"
#include "tdataformat.h"
#include "tgrant.h"
#include "hash.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "mnodeDb.h"
#include "mnodeDnode.h"
#include "tgrant.h"
#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 "tcompare.h"
#include "tdataformat.h"
#include "mnodeWrite.h"
#include "mnodeRead.h"
#include "mnodePeer.h"
static
void
*
tsChildTableSdb
;
static
void
*
tsSuperTableSdb
;
static
int32_t
tsChildTableUpdateSize
;
static
int32_t
tsSuperTableUpdateSize
;
static
void
*
m
gmt
GetChildTable
(
char
*
tableId
);
static
void
*
m
gmt
GetSuperTable
(
char
*
tableId
);
static
void
*
m
gmt
GetSuperTableByUid
(
uint64_t
uid
);
static
void
m
gmt
DropAllChildTablesInStable
(
SSuperTableObj
*
pStable
);
static
void
m
gmt
AddTableIntoStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
);
static
void
m
gmt
RemoveTableFromStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
);
static
int32_t
m
gmt
GetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
gmt
GetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
void
mgmtProcessCreateTableMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmt
ProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
void
mgmtProcessDropTableMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmt
ProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessDropSuperTableRsp
(
SRpcMsg
*
rpcMsg
);
static
void
mgmt
ProcessDropChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessDropChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
void
mgmtProcessSuperTableVgroupMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmtProcessMultiTableMetaMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmtProcessTableCfgMsg
(
SRpcMsg
*
rpc
Msg
);
static
void
mgmtProcessTableMetaMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmt
GetSuperTableMeta
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
GetChildTableMeta
(
SMnodeMsg
*
pMsg
);
static
void
mgmtAutoCreateChildTable
(
SMnodeMsg
*
pMsg
);
static
void
mgmtProcessAlterTableMsg
(
SMnodeMsg
*
queu
eMsg
);
static
void
mgmt
ProcessAlterTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
m
gmt
FindSuperTableColumnIndex
(
SSuperTableObj
*
pStable
,
char
*
colName
);
static
void
*
m
node
GetChildTable
(
char
*
tableId
);
static
void
*
m
node
GetSuperTable
(
char
*
tableId
);
static
void
*
m
node
GetSuperTableByUid
(
uint64_t
uid
);
static
void
m
node
DropAllChildTablesInStable
(
SSuperTableObj
*
pStable
);
static
void
m
node
AddTableIntoStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
);
static
void
m
node
RemoveTableFromStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
);
static
int32_t
m
node
GetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
RetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
m
node
GetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeProcessCreateTableMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
int32_t
mnode
ProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mnode
ProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnodeProcessDropTableMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
int32_t
mnode
ProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mnode
ProcessDropSuperTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnode
ProcessDropChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mnode
ProcessDropChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnodeProcessSuperTableVgroupMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
int32_t
mnodeProcessMultiTableMetaMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
int32_t
mnodeProcessTableCfgMsg
(
SMnodeMsg
*
mnode
Msg
);
static
int32_t
mnodeProcessTableMetaMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
int32_t
mnode
GetSuperTableMeta
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
GetChildTableMeta
(
SMnodeMsg
*
pMsg
);
static
int32_t
mgmtAutoCreateChildTable
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessAlterTableMsg
(
SMnodeMsg
*
mnod
eMsg
);
static
void
mnode
ProcessAlterTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
m
node
FindSuperTableColumnIndex
(
SSuperTableObj
*
pStable
,
char
*
colName
);
static
void
mgmtDestroyChildTable
(
SChildTableObj
*
pTable
)
{
tfree
(
pTable
->
info
.
tableId
);
...
...
@@ -90,39 +94,39 @@ static void mgmtDestroyChildTable(SChildTableObj *pTable) {
tfree
(
pTable
);
}
static
int32_t
m
gmt
ChildTableActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionDestroy
(
SSdbOper
*
pOper
)
{
mgmtDestroyChildTable
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionInsert
(
SSdbOper
*
pOper
)
{
SChildTableObj
*
pTable
=
pOper
->
pObj
;
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mError
(
"ctable:%s, not in vgId:%d"
,
pTable
->
info
.
tableId
,
pTable
->
vgId
);
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
SDbObj
*
pDb
=
m
gmt
GetDb
(
pVgroup
->
dbName
);
SDbObj
*
pDb
=
m
node
GetDb
(
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
{
mError
(
"ctable:%s, vgId:%d not in db:%s"
,
pTable
->
info
.
tableId
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
return
TSDB_CODE_INVALID_DB
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"ctable:%s, acct:%s not exists"
,
pTable
->
info
.
tableId
,
pDb
->
acct
);
return
TSDB_CODE_INVALID_ACCT
;
}
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
// add ref
pTable
->
superTable
=
m
gmt
GetSuperTableByUid
(
pTable
->
suid
);
m
gmt
AddTableIntoStable
(
pTable
->
superTable
,
pTable
);
pTable
->
superTable
=
m
node
GetSuperTableByUid
(
pTable
->
suid
);
m
node
AddTableIntoStable
(
pTable
->
superTable
,
pTable
);
grantAdd
(
TSDB_GRANT_TIMESERIES
,
pTable
->
superTable
->
numOfColumns
-
1
);
pAcct
->
acctInfo
.
numOfTimeSeries
+=
(
pTable
->
superTable
->
numOfColumns
-
1
);
}
else
{
...
...
@@ -130,56 +134,56 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) {
pAcct
->
acctInfo
.
numOfTimeSeries
+=
(
pTable
->
numOfColumns
-
1
);
}
m
gmt
AddTableIntoDb
(
pDb
);
m
gmt
AddTableIntoVgroup
(
pVgroup
,
pTable
);
m
node
AddTableIntoDb
(
pDb
);
m
node
AddTableIntoVgroup
(
pVgroup
,
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionDelete
(
SSdbOper
*
pOper
)
{
SChildTableObj
*
pTable
=
pOper
->
pObj
;
if
(
pTable
->
vgId
==
0
)
{
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
SDbObj
*
pDb
=
m
gmt
GetDb
(
pVgroup
->
dbName
);
SDbObj
*
pDb
=
m
node
GetDb
(
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
{
mError
(
"ctable:%s, vgId:%d not in DB:%s"
,
pTable
->
info
.
tableId
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
return
TSDB_CODE_INVALID_DB
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"ctable:%s, acct:%s not exists"
,
pTable
->
info
.
tableId
,
pDb
->
acct
);
return
TSDB_CODE_INVALID_ACCT
;
}
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
grantRestore
(
TSDB_GRANT_TIMESERIES
,
pTable
->
superTable
->
numOfColumns
-
1
);
pAcct
->
acctInfo
.
numOfTimeSeries
-=
(
pTable
->
superTable
->
numOfColumns
-
1
);
m
gmt
RemoveTableFromStable
(
pTable
->
superTable
,
pTable
);
m
gmt
DecTableRef
(
pTable
->
superTable
);
m
node
RemoveTableFromStable
(
pTable
->
superTable
,
pTable
);
m
node
DecTableRef
(
pTable
->
superTable
);
}
else
{
grantRestore
(
TSDB_GRANT_TIMESERIES
,
pTable
->
numOfColumns
-
1
);
pAcct
->
acctInfo
.
numOfTimeSeries
-=
(
pTable
->
numOfColumns
-
1
);
}
m
gmt
RemoveTableFromDb
(
pDb
);
m
gmt
RemoveTableFromVgroup
(
pVgroup
,
pTable
);
m
node
RemoveTableFromDb
(
pDb
);
m
node
RemoveTableFromVgroup
(
pVgroup
,
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionUpdate
(
SSdbOper
*
pOper
)
{
SChildTableObj
*
pNew
=
pOper
->
pObj
;
SChildTableObj
*
pTable
=
m
gmt
GetChildTable
(
pNew
->
info
.
tableId
);
SChildTableObj
*
pTable
=
m
node
GetChildTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldSql
=
pTable
->
sql
;
...
...
@@ -192,12 +196,12 @@ static int32_t mgmtChildTableActionUpdate(SSdbOper *pOper) {
free
(
oldSchema
);
free
(
oldTableId
);
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionEncode
(
SSdbOper
*
pOper
)
{
SChildTableObj
*
pTable
=
pOper
->
pObj
;
assert
(
pTable
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
...
...
@@ -227,7 +231,7 @@ static int32_t mgmtChildTableActionEncode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
ChildTableActionDecode
(
SSdbOper
*
pOper
)
{
assert
(
pOper
->
rowData
!=
NULL
);
SChildTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SChildTableObj
));
if
(
pTable
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -264,34 +268,34 @@ static int32_t mgmtChildTableActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ChildTableActionRestored
()
{
static
int32_t
m
node
ChildTableActionRestored
()
{
void
*
pIter
=
NULL
;
SChildTableObj
*
pTable
=
NULL
;
while
(
1
)
{
pIter
=
m
gmt
GetNextChildTable
(
pIter
,
&
pTable
);
pIter
=
m
node
GetNextChildTable
(
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
SDbObj
*
pDb
=
m
gmt
GetDbByTableId
(
pTable
->
info
.
tableId
);
SDbObj
*
pDb
=
m
node
GetDbByTableId
(
pTable
->
info
.
tableId
);
if
(
pDb
==
NULL
)
{
mError
(
"ctable:%s, failed to get db, discard it"
,
pTable
->
info
.
tableId
);
SSdbOper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
table
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mError
(
"ctable:%s, failed to get vgId:%d sid:%d, discard it"
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
sid
);
pTable
->
vgId
=
0
;
SSdbOper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
table
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
if
(
strcmp
(
pVgroup
->
dbName
,
pDb
->
name
)
!=
0
)
{
mError
(
"ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it"
,
...
...
@@ -299,7 +303,7 @@ static int32_t mgmtChildTableActionRestored() {
pTable
->
vgId
=
0
;
SSdbOper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
table
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -308,24 +312,24 @@ static int32_t mgmtChildTableActionRestored() {
pTable
->
vgId
=
0
;
SSdbOper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
table
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
SSuperTableObj
*
pSuperTable
=
m
gmt
GetSuperTableByUid
(
pTable
->
suid
);
SSuperTableObj
*
pSuperTable
=
m
node
GetSuperTableByUid
(
pTable
->
suid
);
if
(
pSuperTable
==
NULL
)
{
mError
(
"ctable:%s, stable:%"
PRIu64
" not exist"
,
pTable
->
info
.
tableId
,
pTable
->
suid
);
pTable
->
vgId
=
0
;
SSdbOper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
table
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
m
gmt
DecTableRef
(
pSuperTable
);
m
node
DecTableRef
(
pSuperTable
);
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -333,7 +337,7 @@ static int32_t mgmtChildTableActionRestored() {
return
0
;
}
static
int32_t
m
gmt
InitChildTables
()
{
static
int32_t
m
node
InitChildTables
()
{
SChildTableObj
tObj
;
tsChildTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
...
...
@@ -344,13 +348,13 @@ static int32_t mgmtInitChildTables() {
.
maxRowSize
=
sizeof
(
SChildTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_ID_LEN
+
TSDB_CQ_SQL_SIZE
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
m
gmt
ChildTableActionInsert
,
.
deleteFp
=
m
gmt
ChildTableActionDelete
,
.
updateFp
=
m
gmt
ChildTableActionUpdate
,
.
encodeFp
=
m
gmt
ChildTableActionEncode
,
.
decodeFp
=
m
gmt
ChildTableActionDecode
,
.
destroyFp
=
m
gmt
ChildTableActionDestroy
,
.
restoredFp
=
m
gmt
ChildTableActionRestored
.
insertFp
=
m
node
ChildTableActionInsert
,
.
deleteFp
=
m
node
ChildTableActionDelete
,
.
updateFp
=
m
node
ChildTableActionUpdate
,
.
encodeFp
=
m
node
ChildTableActionEncode
,
.
decodeFp
=
m
node
ChildTableActionDecode
,
.
destroyFp
=
m
node
ChildTableActionDestroy
,
.
restoredFp
=
m
node
ChildTableActionRestored
};
tsChildTableSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -363,11 +367,11 @@ static int32_t mgmtInitChildTables() {
return
0
;
}
static
void
m
gmtCleanU
pChildTables
()
{
static
void
m
nodeCleanu
pChildTables
()
{
sdbCloseTable
(
tsChildTableSdb
);
}
static
void
m
gmt
AddTableIntoStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
)
{
static
void
m
node
AddTableIntoStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
)
{
pStable
->
numOfTables
++
;
if
(
pStable
->
vgHash
==
NULL
)
{
...
...
@@ -379,16 +383,16 @@ static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCta
}
}
static
void
m
gmt
RemoveTableFromStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
)
{
static
void
m
node
RemoveTableFromStable
(
SSuperTableObj
*
pStable
,
SChildTableObj
*
pCtable
)
{
pStable
->
numOfTables
--
;
if
(
pStable
->
vgHash
==
NULL
)
return
;
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pCtable
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pCtable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
taosHashRemove
(
pStable
->
vgHash
,
(
char
*
)
&
pCtable
->
vgId
,
sizeof
(
pCtable
->
vgId
));
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
static
void
mgmtDestroySuperTable
(
SSuperTableObj
*
pStable
)
{
...
...
@@ -401,37 +405,37 @@ static void mgmtDestroySuperTable(SSuperTableObj *pStable) {
tfree
(
pStable
);
}
static
int32_t
m
gmt
SuperTableActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionDestroy
(
SSdbOper
*
pOper
)
{
mgmtDestroySuperTable
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionInsert
(
SSdbOper
*
pOper
)
{
SSuperTableObj
*
pStable
=
pOper
->
pObj
;
SDbObj
*
pDb
=
m
gmt
GetDbByTableId
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
m
node
GetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
)
{
m
gmt
AddSuperTableIntoDb
(
pDb
);
m
node
AddSuperTableIntoDb
(
pDb
);
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionDelete
(
SSdbOper
*
pOper
)
{
SSuperTableObj
*
pStable
=
pOper
->
pObj
;
SDbObj
*
pDb
=
m
gmt
GetDbByTableId
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
m
node
GetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
)
{
m
gmt
RemoveSuperTableFromDb
(
pDb
);
m
gmt
DropAllChildTablesInStable
((
SSuperTableObj
*
)
pStable
);
m
node
RemoveSuperTableFromDb
(
pDb
);
m
node
DropAllChildTablesInStable
((
SSuperTableObj
*
)
pStable
);
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionUpdate
(
SSdbOper
*
pOper
)
{
SSuperTableObj
*
pNew
=
pOper
->
pObj
;
SSuperTableObj
*
pTable
=
m
gmt
GetSuperTable
(
pNew
->
info
.
tableId
);
SSuperTableObj
*
pTable
=
m
node
GetSuperTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldSchema
=
pTable
->
schema
;
...
...
@@ -442,11 +446,11 @@ static int32_t mgmtSuperTableActionUpdate(SSdbOper *pOper) {
free
(
oldTableId
);
free
(
oldSchema
);
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionEncode
(
SSdbOper
*
pOper
)
{
SSuperTableObj
*
pStable
=
pOper
->
pObj
;
assert
(
pOper
->
pObj
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
...
...
@@ -469,7 +473,7 @@ static int32_t mgmtSuperTableActionEncode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
SuperTableActionDecode
(
SSdbOper
*
pOper
)
{
assert
(
pOper
->
rowData
!=
NULL
);
SSuperTableObj
*
pStable
=
(
SSuperTableObj
*
)
calloc
(
1
,
sizeof
(
SSuperTableObj
));
if
(
pStable
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -496,11 +500,11 @@ static int32_t mgmtSuperTableActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SuperTableActionRestored
()
{
static
int32_t
m
node
SuperTableActionRestored
()
{
return
0
;
}
static
int32_t
m
gmt
InitSuperTables
()
{
static
int32_t
m
node
InitSuperTables
()
{
SSuperTableObj
tObj
;
tsSuperTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
...
...
@@ -511,13 +515,13 @@ static int32_t mgmtInitSuperTables() {
.
maxRowSize
=
sizeof
(
SSuperTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_ID_LEN
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
m
gmt
SuperTableActionInsert
,
.
deleteFp
=
m
gmt
SuperTableActionDelete
,
.
updateFp
=
m
gmt
SuperTableActionUpdate
,
.
encodeFp
=
m
gmt
SuperTableActionEncode
,
.
decodeFp
=
m
gmt
SuperTableActionDecode
,
.
destroyFp
=
m
gmt
SuperTableActionDestroy
,
.
restoredFp
=
m
gmt
SuperTableActionRestored
.
insertFp
=
m
node
SuperTableActionInsert
,
.
deleteFp
=
m
node
SuperTableActionDelete
,
.
updateFp
=
m
node
SuperTableActionUpdate
,
.
encodeFp
=
m
node
SuperTableActionEncode
,
.
decodeFp
=
m
node
SuperTableActionDecode
,
.
destroyFp
=
m
node
SuperTableActionDestroy
,
.
restoredFp
=
m
node
SuperTableActionRestored
};
tsSuperTableSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -530,63 +534,63 @@ static int32_t mgmtInitSuperTables() {
return
0
;
}
static
void
m
gmtCleanU
pSuperTables
()
{
static
void
m
nodeCleanu
pSuperTables
()
{
sdbCloseTable
(
tsSuperTableSdb
);
}
int32_t
m
gmt
InitTables
()
{
int32_t
code
=
m
gmt
InitSuperTables
();
int32_t
m
node
InitTables
()
{
int32_t
code
=
m
node
InitSuperTables
();
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
code
=
m
gmt
InitChildTables
();
code
=
m
node
InitChildTables
();
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_TABLES_META
,
mgmt
ProcessMultiTableMetaMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_TABLE
,
mgmt
ProcessCreateTableMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_TABLE
,
mgmt
ProcessDropTableMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_TABLE
,
mgmt
ProcessAlterTableMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_TABLE_META
,
mgmt
ProcessTableMetaMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_STABLE_VGROUP
,
mgmt
ProcessSuperTableVgroupMsg
);
m
nodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_TABLES_META
,
mnode
ProcessMultiTableMetaMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_TABLE
,
mnode
ProcessCreateTableMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_TABLE
,
mnode
ProcessDropTableMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_TABLE
,
mnode
ProcessAlterTableMsg
);
m
nodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_TABLE_META
,
mnode
ProcessTableMetaMsg
);
m
nodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_STABLE_VGROUP
,
mnode
ProcessSuperTableVgroupMsg
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP
,
mgmt
ProcessCreateChildTableRsp
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_DROP_TABLE_RSP
,
mgmt
ProcessDropChildTableRsp
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_DROP_STABLE_RSP
,
mgmt
ProcessDropSuperTableRsp
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP
,
mgmt
ProcessAlterTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP
,
mnode
ProcessCreateChildTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_DROP_TABLE_RSP
,
mnode
ProcessDropChildTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_DROP_STABLE_RSP
,
mnode
ProcessDropSuperTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP
,
mnode
ProcessAlterTableRsp
);
dnodeAddServerMsgHandle
(
TSDB_MSG_TYPE_DM_CONFIG_TABLE
,
mgmt
ProcessTableCfgMsg
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_CONFIG_TABLE
,
mnode
ProcessTableCfgMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_TABLE
,
mgmt
GetShowTableMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_TABLE
,
mgmt
RetrieveShowTables
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_METRIC
,
mgmt
GetShowSuperTableMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_METRIC
,
mgmt
RetrieveShowSuperTables
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_TABLE
,
mnode
GetShowTableMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_TABLE
,
mnode
RetrieveShowTables
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_METRIC
,
mnode
GetShowSuperTableMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_METRIC
,
mnode
RetrieveShowSuperTables
);
return
TSDB_CODE_SUCCESS
;
}
static
void
*
m
gmt
GetChildTable
(
char
*
tableId
)
{
static
void
*
m
node
GetChildTable
(
char
*
tableId
)
{
return
sdbGetRow
(
tsChildTableSdb
,
tableId
);
}
static
void
*
m
gmt
GetSuperTable
(
char
*
tableId
)
{
static
void
*
m
node
GetSuperTable
(
char
*
tableId
)
{
return
sdbGetRow
(
tsSuperTableSdb
,
tableId
);
}
static
void
*
m
gmt
GetSuperTableByUid
(
uint64_t
uid
)
{
static
void
*
m
node
GetSuperTableByUid
(
uint64_t
uid
)
{
SSuperTableObj
*
pStable
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
m
gmt
GetNextSuperTable
(
pIter
,
&
pStable
);
pIter
=
m
node
GetNextSuperTable
(
pIter
,
&
pStable
);
if
(
pStable
==
NULL
)
break
;
if
(
pStable
->
uid
==
uid
)
{
sdbFreeIter
(
pIter
);
return
pStable
;
}
m
gmt
DecTableRef
(
pStable
);
m
node
DecTableRef
(
pStable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -594,13 +598,13 @@ static void *mgmtGetSuperTableByUid(uint64_t uid) {
return
NULL
;
}
void
*
m
gmt
GetTable
(
char
*
tableId
)
{
void
*
pTable
=
m
gmt
GetSuperTable
(
tableId
);
void
*
m
node
GetTable
(
char
*
tableId
)
{
void
*
pTable
=
m
node
GetSuperTable
(
tableId
);
if
(
pTable
!=
NULL
)
{
return
pTable
;
}
pTable
=
m
gmt
GetChildTable
(
tableId
);
pTable
=
m
node
GetChildTable
(
tableId
);
if
(
pTable
!=
NULL
)
{
return
pTable
;
}
...
...
@@ -608,15 +612,15 @@ void *mgmtGetTable(char *tableId) {
return
NULL
;
}
void
*
m
gmt
GetNextChildTable
(
void
*
pIter
,
SChildTableObj
**
pTable
)
{
void
*
m
node
GetNextChildTable
(
void
*
pIter
,
SChildTableObj
**
pTable
)
{
return
sdbFetchRow
(
tsChildTableSdb
,
pIter
,
(
void
**
)
pTable
);
}
void
*
m
gmt
GetNextSuperTable
(
void
*
pIter
,
SSuperTableObj
**
pTable
)
{
void
*
m
node
GetNextSuperTable
(
void
*
pIter
,
SSuperTableObj
**
pTable
)
{
return
sdbFetchRow
(
tsSuperTableSdb
,
pIter
,
(
void
**
)
pTable
);
}
void
m
gmt
IncTableRef
(
void
*
p1
)
{
void
m
node
IncTableRef
(
void
*
p1
)
{
STableObj
*
pTable
=
(
STableObj
*
)
p1
;
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
sdbIncRef
(
tsSuperTableSdb
,
pTable
);
...
...
@@ -625,7 +629,7 @@ void mgmtIncTableRef(void *p1) {
}
}
void
m
gmt
DecTableRef
(
void
*
p1
)
{
void
m
node
DecTableRef
(
void
*
p1
)
{
if
(
p1
==
NULL
)
return
;
STableObj
*
pTable
=
(
STableObj
*
)
p1
;
...
...
@@ -636,9 +640,9 @@ void mgmtDecTableRef(void *p1) {
}
}
void
m
gmtCleanU
pTables
()
{
m
gmtCleanU
pChildTables
();
m
gmtCleanU
pSuperTables
();
void
m
nodeCleanu
pTables
()
{
m
nodeCleanu
pChildTables
();
m
nodeCleanu
pSuperTables
();
}
// todo move to name.h, add length of table name
...
...
@@ -655,113 +659,105 @@ static void mgmtExtractTableName(char* tableId, char* name) {
}
}
static
void
mgmt
ProcessCreateTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessCreateTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCreateTableMsg
*
pCreate
=
pMsg
->
pCont
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDb
(
pCreate
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDb
(
pCreate
->
db
);
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"table:%s, failed to create, db not selected"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_DB_NOT_SELECTED
);
return
;
return
TSDB_CODE_DB_NOT_SELECTED
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
gmt
GetTable
(
pCreate
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
node
GetTable
(
pCreate
->
tableId
);
if
(
pMsg
->
pTable
!=
NULL
&&
pMsg
->
retry
==
0
)
{
if
(
pCreate
->
getMeta
)
{
mTrace
(
"table:%s, continue to get meta"
,
pCreate
->
tableId
);
mgmt
GetChildTableMeta
(
pMsg
);
return
mnode
GetChildTableMeta
(
pMsg
);
}
else
if
(
pCreate
->
igExists
)
{
mTrace
(
"table:%s, is already exist"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
)
;
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"table:%s, failed to create, table already exist"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_TABLE_ALREADY_EXIST
)
;
return
TSDB_CODE_TABLE_ALREADY_EXIST
;
}
return
;
}
if
(
pCreate
->
numOfTags
!=
0
)
{
mTrace
(
"table:%s, create msg is received from thandle:%p"
,
pCreate
->
tableId
,
pMsg
->
thandle
);
mgmt
ProcessCreateSuperTableMsg
(
pMsg
);
return
mnode
ProcessCreateSuperTableMsg
(
pMsg
);
}
else
{
mTrace
(
"table:%s, create msg is received from thandle:%p"
,
pCreate
->
tableId
,
pMsg
->
thandle
);
mgmt
ProcessCreateChildTableMsg
(
pMsg
);
return
mnode
ProcessCreateChildTableMsg
(
pMsg
);
}
}
static
void
mgmt
ProcessDropTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessDropTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMDropTableMsg
*
pDrop
=
pMsg
->
pCont
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDbByTableId
(
pDrop
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDbByTableId
(
pDrop
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"table:%s, failed to drop table, db not selected"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_DB_NOT_SELECTED
);
return
;
return
TSDB_CODE_DB_NOT_SELECTED
;
}
if
(
m
gmt
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
if
(
m
node
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"table:%s, failed to drop table, in monitor database"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_MONITOR_DB_FORBIDDEN
);
return
;
return
TSDB_CODE_MONITOR_DB_FORBIDDEN
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
gmt
GetTable
(
pDrop
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
node
GetTable
(
pDrop
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
pDrop
->
igNotExists
)
{
mTrace
(
"table:%s, table is not exist, think drop success"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
);
return
;
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"table:%s, failed to drop table, table not exist"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
return
TSDB_CODE_INVALID_TABLE
;
}
}
if
(
pMsg
->
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
mPrint
(
"table:%s, start to drop stable"
,
pDrop
->
tableId
);
mgmt
ProcessDropSuperTableMsg
(
pMsg
);
return
mnode
ProcessDropSuperTableMsg
(
pMsg
);
}
else
{
mPrint
(
"table:%s, start to drop ctable"
,
pDrop
->
tableId
);
mgmt
ProcessDropChildTableMsg
(
pMsg
);
return
mnode
ProcessDropChildTableMsg
(
pMsg
);
}
}
static
void
mgmt
ProcessTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
SCMTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
pInfo
->
createFlag
=
htons
(
pInfo
->
createFlag
);
mTrace
(
"table:%s, table meta msg is received from thandle:%p, createFlag:%d"
,
pInfo
->
tableId
,
pMsg
->
thandle
,
pInfo
->
createFlag
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDbByTableId
(
pInfo
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDbByTableId
(
pInfo
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"table:%s, failed to get table meta, db not selected"
,
pInfo
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_DB_NOT_SELECTED
);
return
;
return
TSDB_CODE_DB_NOT_SELECTED
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
gmt
GetTable
(
pInfo
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
node
GetTable
(
pInfo
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
!
pInfo
->
createFlag
)
{
mError
(
"table:%s, failed to get table meta, table not exist"
,
pInfo
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
)
;
return
TSDB_CODE_INVALID_TABLE
;
}
else
{
mgmtAutoCreateChildTable
(
pMsg
);
return
mgmtAutoCreateChildTable
(
pMsg
);
}
}
else
{
if
(
pMsg
->
pTable
->
type
!=
TSDB_SUPER_TABLE
)
{
mgmt
GetChildTableMeta
(
pMsg
);
return
mnode
GetChildTableMeta
(
pMsg
);
}
else
{
mgmt
GetSuperTableMeta
(
pMsg
);
return
mnode
GetSuperTableMeta
(
pMsg
);
}
}
}
static
void
mgmt
ProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCreateTableMsg
*
pCreate
=
pMsg
->
pCont
;
SSuperTableObj
*
pStable
=
calloc
(
1
,
sizeof
(
SSuperTableObj
));
if
(
pStable
==
NULL
)
{
mError
(
"table:%s, failed to create, no enough memory"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
tableId
);
...
...
@@ -779,8 +775,7 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if
(
pStable
->
schema
==
NULL
)
{
free
(
pStable
);
mError
(
"table:%s, failed to create, no schema input"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
return
TSDB_CODE_INVALID_TABLE
;
}
memcpy
(
pStable
->
schema
,
pCreate
->
schema
,
numOfCols
*
sizeof
(
SSchema
));
...
...
@@ -805,20 +800,20 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mgmtDestroySuperTable
(
pStable
);
mError
(
"table:%s, failed to create, sdb error"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SDB_ERROR
)
;
return
TSDB_CODE_SDB_ERROR
;
}
else
{
mLPrint
(
"table:%s, is created, tags:%d fields:%d"
,
pStable
->
info
.
tableId
,
pStable
->
numOfTags
,
pStable
->
numOfColumns
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
)
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
mgmt
ProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
SSuperTableObj
*
pStable
=
(
SSuperTableObj
*
)
pMsg
->
pTable
;
if
(
pStable
->
numOfTables
!=
0
)
{
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pStable
->
vgHash
);
while
(
taosHashIterNext
(
pIter
))
{
int32_t
*
pVgId
=
taosHashIterGet
(
pIter
);
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
*
pVgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
*
pVgId
);
if
(
pVgroup
==
NULL
)
break
;
SMDDropSTableMsg
*
pDrop
=
rpcMallocCont
(
sizeof
(
SMDDropSTableMsg
));
...
...
@@ -828,14 +823,14 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
mgmtExtractTableName
(
pStable
->
info
.
tableId
,
pDrop
->
tableId
);
mPrint
(
"stable:%s, send drop stable msg to vgId:%d"
,
pStable
->
info
.
tableId
,
pVgroup
->
vgId
);
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromVgroup
(
pVgroup
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromVgroup
(
pVgroup
);
SRpcMsg
rpcMsg
=
{.
pCont
=
pDrop
,
.
contLen
=
sizeof
(
SMDDropSTableMsg
),
.
msgType
=
TSDB_MSG_TYPE_MD_DROP_STABLE
};
dnodeSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
taosHashDestroyIter
(
pIter
);
m
gmt
DropAllChildTablesInStable
(
pStable
);
m
node
DropAllChildTablesInStable
(
pStable
);
}
SSdbOper
oper
=
{
...
...
@@ -846,10 +841,10 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
int32_t
code
=
sdbDeleteRow
(
&
oper
);
mLPrint
(
"stable:%s, is dropped from sdb, result:%s"
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
return
code
;
}
static
int32_t
m
gmt
FindSuperTableTagIndex
(
SSuperTableObj
*
pStable
,
const
char
*
tagName
)
{
static
int32_t
m
node
FindSuperTableTagIndex
(
SSuperTableObj
*
pStable
,
const
char
*
tagName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pStable
->
schema
;
for
(
int32_t
tag
=
0
;
tag
<
pStable
->
numOfTags
;
tag
++
)
{
if
(
strcasecmp
(
schema
[
pStable
->
numOfColumns
+
tag
].
name
,
tagName
)
==
0
)
{
...
...
@@ -860,19 +855,19 @@ static int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *t
return
-
1
;
}
static
int32_t
m
gmt
AddSuperTableTag
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ntags
)
{
static
int32_t
m
node
AddSuperTableTag
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ntags
)
{
if
(
pStable
->
numOfTags
+
ntags
>
TSDB_MAX_TAGS
)
{
mError
(
"stable:%s, add tag, too many tags"
,
pStable
->
info
.
tableId
);
return
TSDB_CODE_TOO_MANY_TAGS
;
}
for
(
int32_t
i
=
0
;
i
<
ntags
;
i
++
)
{
if
(
m
gmt
FindSuperTableColumnIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
if
(
m
node
FindSuperTableColumnIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
mError
(
"stable:%s, add tag, column:%s already exist"
,
pStable
->
info
.
tableId
,
schema
[
i
].
name
);
return
TSDB_CODE_TAG_ALREAY_EXIST
;
}
if
(
m
gmt
FindSuperTableTagIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
if
(
m
node
FindSuperTableTagIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
mError
(
"stable:%s, add tag, tag:%s already exist"
,
pStable
->
info
.
tableId
,
schema
[
i
].
name
);
return
TSDB_CODE_FIELD_ALREAY_EXIST
;
}
...
...
@@ -906,8 +901,8 @@ static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], i
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DropSuperTableTag
(
SSuperTableObj
*
pStable
,
char
*
tagName
)
{
int32_t
col
=
m
gmt
FindSuperTableTagIndex
(
pStable
,
tagName
);
static
int32_t
m
node
DropSuperTableTag
(
SSuperTableObj
*
pStable
,
char
*
tagName
)
{
int32_t
col
=
m
node
FindSuperTableTagIndex
(
pStable
,
tagName
);
if
(
col
<
0
)
{
mError
(
"stable:%s, drop tag, tag:%s not exist"
,
pStable
->
info
.
tableId
,
tagName
);
return
TSDB_CODE_TAG_NOT_EXIST
;
...
...
@@ -933,8 +928,8 @@ static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
ModifySuperTableTagName
(
SSuperTableObj
*
pStable
,
char
*
oldTagName
,
char
*
newTagName
)
{
int32_t
col
=
m
gmt
FindSuperTableTagIndex
(
pStable
,
oldTagName
);
static
int32_t
m
node
ModifySuperTableTagName
(
SSuperTableObj
*
pStable
,
char
*
oldTagName
,
char
*
newTagName
)
{
int32_t
col
=
m
node
FindSuperTableTagIndex
(
pStable
,
oldTagName
);
if
(
col
<
0
)
{
mError
(
"stable:%s, failed to modify table tag, oldName: %s, newName: %s"
,
pStable
->
info
.
tableId
,
oldTagName
,
newTagName
);
return
TSDB_CODE_TAG_NOT_EXIST
;
...
...
@@ -946,7 +941,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag
return
TSDB_CODE_COL_NAME_TOO_LONG
;
}
if
(
m
gmt
FindSuperTableTagIndex
(
pStable
,
newTagName
)
>=
0
)
{
if
(
m
node
FindSuperTableTagIndex
(
pStable
,
newTagName
)
>=
0
)
{
return
TSDB_CODE_TAG_ALREAY_EXIST
;
}
...
...
@@ -969,7 +964,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
FindSuperTableColumnIndex
(
SSuperTableObj
*
pStable
,
char
*
colName
)
{
static
int32_t
m
node
FindSuperTableColumnIndex
(
SSuperTableObj
*
pStable
,
char
*
colName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pStable
->
schema
;
for
(
int32_t
col
=
0
;
col
<
pStable
->
numOfColumns
;
col
++
)
{
if
(
strcasecmp
(
schema
[
col
].
name
,
colName
)
==
0
)
{
...
...
@@ -980,19 +975,19 @@ static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colN
return
-
1
;
}
static
int32_t
m
gmt
AddSuperTableColumn
(
SDbObj
*
pDb
,
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ncols
)
{
static
int32_t
m
node
AddSuperTableColumn
(
SDbObj
*
pDb
,
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ncols
)
{
if
(
ncols
<=
0
)
{
mError
(
"stable:%s, add column, ncols:%d <= 0"
,
pStable
->
info
.
tableId
);
return
TSDB_CODE_APP_ERROR
;
}
for
(
int32_t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
(
m
gmt
FindSuperTableColumnIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
if
(
m
node
FindSuperTableColumnIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
mError
(
"stable:%s, add column, column:%s already exist"
,
pStable
->
info
.
tableId
,
schema
[
i
].
name
);
return
TSDB_CODE_FIELD_ALREAY_EXIST
;
}
if
(
m
gmt
FindSuperTableTagIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
if
(
m
node
FindSuperTableTagIndex
(
pStable
,
schema
[
i
].
name
)
>
0
)
{
mError
(
"stable:%s, add column, tag:%s already exist"
,
pStable
->
info
.
tableId
,
schema
[
i
].
name
);
return
TSDB_CODE_TAG_ALREAY_EXIST
;
}
...
...
@@ -1013,10 +1008,10 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
pStable
->
numOfColumns
+=
ncols
;
pStable
->
sversion
++
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
!=
NULL
)
{
pAcct
->
acctInfo
.
numOfTimeSeries
+=
(
ncols
*
pStable
->
numOfTables
);
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
SSdbOper
oper
=
{
...
...
@@ -1034,8 +1029,8 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DropSuperTableColumn
(
SDbObj
*
pDb
,
SSuperTableObj
*
pStable
,
char
*
colName
)
{
int32_t
col
=
m
gmt
FindSuperTableColumnIndex
(
pStable
,
colName
);
static
int32_t
m
node
DropSuperTableColumn
(
SDbObj
*
pDb
,
SSuperTableObj
*
pStable
,
char
*
colName
)
{
int32_t
col
=
m
node
FindSuperTableColumnIndex
(
pStable
,
colName
);
if
(
col
<=
0
)
{
mError
(
"stable:%s, drop column, column:%s not exist"
,
pStable
->
info
.
tableId
,
colName
);
return
TSDB_CODE_FIELD_NOT_EXIST
;
...
...
@@ -1050,10 +1045,10 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
int32_t
schemaSize
=
sizeof
(
SSchema
)
*
(
pStable
->
numOfTags
+
pStable
->
numOfColumns
);
pStable
->
schema
=
realloc
(
pStable
->
schema
,
schemaSize
);
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
!=
NULL
)
{
pAcct
->
acctInfo
.
numOfTimeSeries
-=
pStable
->
numOfTables
;
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
SSdbOper
oper
=
{
...
...
@@ -1072,8 +1067,8 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
}
// show super tables
static
int32_t
m
gmt
GetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
static
int32_t
m
node
GetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
TSDB_CODE_DB_NOT_SELECTED
;
int32_t
cols
=
0
;
...
...
@@ -1118,12 +1113,12 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
pShow
->
numOfRows
=
pDb
->
numOfSuperTables
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
0
;
}
// retrieve super tables
int32_t
m
gmt
RetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
...
...
@@ -1131,7 +1126,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
char
prefix
[
20
]
=
{
0
};
int32_t
prefixLen
;
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
strcpy
(
prefix
,
pDb
->
name
);
...
...
@@ -1142,10 +1137,10 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
char
stableName
[
TSDB_TABLE_NAME_LEN
+
1
]
=
{
0
};
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextSuperTable
(
pShow
->
pIter
,
&
pTable
);
pShow
->
pIter
=
m
node
GetNextSuperTable
(
pShow
->
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pTable
->
info
.
tableId
,
prefix
,
prefixLen
))
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -1153,7 +1148,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
mgmtExtractTableName
(
pTable
->
info
.
tableId
,
stableName
);
if
(
pShow
->
payloadLen
>
0
&&
patternMatch
(
pShow
->
payload
,
stableName
,
TSDB_TABLE_NAME_LEN
,
&
info
)
!=
TSDB_PATTERN_MATCH
)
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -1185,16 +1180,16 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
cols
++
;
numOfRows
++
;
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
pShow
->
numOfReads
+=
numOfRows
;
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
numOfRows
;
}
void
m
gmt
DropAllSuperTables
(
SDbObj
*
pDropDb
)
{
void
m
node
DropAllSuperTables
(
SDbObj
*
pDropDb
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
int32_t
dbNameLen
=
strlen
(
pDropDb
->
name
);
...
...
@@ -1203,7 +1198,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
mPrint
(
"db:%s, all super tables will be dropped from sdb"
,
pDropDb
->
name
);
while
(
1
)
{
pIter
=
m
gmt
GetNextSuperTable
(
pIter
,
&
pTable
);
pIter
=
m
node
GetNextSuperTable
(
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pDropDb
->
name
,
pTable
->
info
.
tableId
,
dbNameLen
)
==
0
)
{
...
...
@@ -1216,7 +1211,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
numOfTables
++
;
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -1224,7 +1219,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
mPrint
(
"db:%s, all super tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
static
int32_t
m
gmt
SetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSuperTableObj
*
pTable
)
{
static
int32_t
m
node
SetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSuperTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
+
pTable
->
numOfTags
;
assert
(
numOfCols
<=
TSDB_MAX_COLUMNS
);
...
...
@@ -1239,7 +1234,7 @@ static int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTa
return
(
pTable
->
numOfColumns
+
pTable
->
numOfTags
)
*
sizeof
(
SSchema
);
}
static
void
mgmt
GetSuperTableMeta
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
GetSuperTableMeta
(
SMnodeMsg
*
pMsg
)
{
SSuperTableObj
*
pTable
=
(
SSuperTableObj
*
)
pMsg
->
pTable
;
STableMetaMsg
*
pMeta
=
rpcMallocCont
(
sizeof
(
STableMetaMsg
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
));
pMeta
->
uid
=
htobe64
(
pTable
->
uid
);
...
...
@@ -1249,21 +1244,19 @@ static void mgmtGetSuperTableMeta(SMnodeMsg *pMsg) {
pMeta
->
numOfTags
=
(
uint8_t
)
pTable
->
numOfTags
;
pMeta
->
numOfColumns
=
htons
((
int16_t
)
pTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
info
.
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
gmt
SetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
node
SetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
);
strncpy
(
pMeta
->
tableId
,
pTable
->
info
.
tableId
,
TSDB_TABLE_ID_LEN
);
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pMeta
,
.
contLen
=
pMeta
->
contLen
,
};
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pMeta
;
pMsg
->
rpcRsp
.
len
=
pMeta
->
contLen
;
mTrace
(
"stable:%s, uid:%"
PRIu64
" table meta is retrieved"
,
pTable
->
info
.
tableId
,
pTable
->
uid
);
return
TSDB_CODE_SUCCESS
;
}
static
void
mgmt
ProcessSuperTableVgroupMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessSuperTableVgroupMsg
(
SMnodeMsg
*
pMsg
)
{
SCMSTableVgroupMsg
*
pInfo
=
pMsg
->
pCont
;
int32_t
numOfTable
=
htonl
(
pInfo
->
numOfTables
);
...
...
@@ -1271,17 +1264,16 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
int32_t
contLen
=
sizeof
(
SCMSTableVgroupRspMsg
)
+
32
*
sizeof
(
SCMVgroupInfo
)
+
sizeof
(
SVgroupsInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SCMSTableVgroupMsg
)
+
(
TSDB_TABLE_ID_LEN
)
*
i
;
SSuperTableObj
*
pTable
=
m
gmt
GetSuperTable
(
stableName
);
SSuperTableObj
*
pTable
=
m
node
GetSuperTable
(
stableName
);
if
(
pTable
->
vgHash
!=
NULL
)
{
contLen
+=
(
taosHashGetSize
(
pTable
->
vgHash
)
*
sizeof
(
SCMVgroupInfo
)
+
sizeof
(
SVgroupsInfo
));
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
SCMSTableVgroupRspMsg
*
pRsp
=
rpcMallocCont
(
contLen
);
if
(
pRsp
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
pRsp
->
numOfTables
=
htonl
(
numOfTable
);
...
...
@@ -1289,14 +1281,14 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SCMSTableVgroupMsg
)
+
(
TSDB_TABLE_ID_LEN
)
*
i
;
SSuperTableObj
*
pTable
=
m
gmt
GetSuperTable
(
stableName
);
SSuperTableObj
*
pTable
=
m
node
GetSuperTable
(
stableName
);
SVgroupsInfo
*
pVgroupInfo
=
(
SVgroupsInfo
*
)
msg
;
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pTable
->
vgHash
);
int32_t
vgSize
=
0
;
while
(
taosHashIterNext
(
pIter
))
{
int32_t
*
pVgId
=
taosHashIterGet
(
pIter
);
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
*
pVgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
*
pVgId
);
if
(
pVgroup
==
NULL
)
continue
;
pVgroupInfo
->
vgroups
[
vgSize
].
vgId
=
htonl
(
pVgroup
->
vgId
);
...
...
@@ -1311,7 +1303,7 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
}
vgSize
++
;
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
taosHashDestroyIter
(
pIter
);
...
...
@@ -1322,14 +1314,13 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
msg
+=
sizeof
(
SVgroupsInfo
)
+
vgSize
*
sizeof
(
SCMVgroupInfo
);
}
SRpcMsg
rpcRsp
=
{
0
};
rpcRsp
.
handle
=
pMsg
->
thandle
;
rpcRsp
.
pCont
=
pRsp
;
rpcRsp
.
contLen
=
msg
-
(
char
*
)
pRsp
;
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pRsp
;
pMsg
->
rpcRsp
.
len
=
msg
-
(
char
*
)
pRsp
;
return
TSDB_CODE_SUCCESS
;
}
static
void
m
gmt
ProcessDropSuperTableRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessDropSuperTableRsp
(
SRpcMsg
*
rpcMsg
)
{
mPrint
(
"drop stable rsp received, result:%s"
,
tstrerror
(
rpcMsg
->
code
));
}
...
...
@@ -1400,7 +1391,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb
return
pCreate
;
}
static
SChildTableObj
*
m
gmt
DoCreateChildTable
(
SCMCreateTableMsg
*
pCreate
,
SVgObj
*
pVgroup
,
int32_t
tid
)
{
static
SChildTableObj
*
m
node
DoCreateChildTable
(
SCMCreateTableMsg
*
pCreate
,
SVgObj
*
pVgroup
,
int32_t
tid
)
{
SChildTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SChildTableObj
));
if
(
pTable
==
NULL
)
{
mError
(
"table:%s, failed to alloc memory"
,
pCreate
->
tableId
);
...
...
@@ -1421,14 +1412,14 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
STagData
*
pTagData
=
(
STagData
*
)
pCreate
->
schema
;
// it is a tag key
SSuperTableObj
*
pSuperTable
=
m
gmt
GetSuperTable
(
pTagData
->
name
);
SSuperTableObj
*
pSuperTable
=
m
node
GetSuperTable
(
pTagData
->
name
);
if
(
pSuperTable
==
NULL
)
{
mError
(
"table:%s, corresponding super table:%s does not exist"
,
pCreate
->
tableId
,
pTagData
->
name
);
free
(
pTable
);
terrno
=
TSDB_CODE_INVALID_TABLE
;
return
NULL
;
}
m
gmt
DecTableRef
(
pSuperTable
);
m
node
DecTableRef
(
pSuperTable
);
pTable
->
suid
=
pSuperTable
->
uid
;
pTable
->
uid
=
(((
uint64_t
)
pTable
->
vgId
)
<<
40
)
+
((((
uint64_t
)
pTable
->
sid
)
&
((
1ul
<<
24
)
-
1ul
))
<<
16
)
+
...
...
@@ -1487,20 +1478,18 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj
return
pTable
;
}
static
void
mgmt
ProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMCreateTableMsg
*
pCreate
=
pMsg
->
pCont
;
int32_t
code
=
grantCheck
(
TSDB_GRANT_TIMESERIES
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to create, grant timeseries failed"
,
pCreate
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
return
code
;
}
SVgObj
*
pVgroup
=
m
gmt
GetAvailableVgroup
(
pMsg
->
pDb
);
SVgObj
*
pVgroup
=
m
node
GetAvailableVgroup
(
pMsg
->
pDb
);
if
(
pVgroup
==
NULL
)
{
mTrace
(
"table:%s, start to create a new vgroup"
,
pCreate
->
tableId
);
mgmtCreateVgroup
(
mgmtCloneQueuedMsg
(
pMsg
),
pMsg
->
pDb
);
return
;
return
mnodeCreateVgroup
(
pMsg
,
pMsg
->
pDb
);
}
if
(
pMsg
->
retry
==
0
)
{
...
...
@@ -1508,39 +1497,34 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
int32_t
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
if
(
sid
<=
0
)
{
mTrace
(
"tables:%s, no enough sid in vgId:%d"
,
pCreate
->
tableId
,
pVgroup
->
vgId
);
mgmtCreateVgroup
(
mgmtCloneQueuedMsg
(
pMsg
),
pMsg
->
pDb
);
return
;
return
mnodeCreateVgroup
(
pMsg
,
pMsg
->
pDb
);
}
pMsg
->
pTable
=
(
STableObj
*
)
m
gmt
DoCreateChildTable
(
pCreate
,
pVgroup
,
sid
);
pMsg
->
pTable
=
(
STableObj
*
)
m
node
DoCreateChildTable
(
pCreate
,
pVgroup
,
sid
);
if
(
pMsg
->
pTable
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
terrno
);
return
;
return
terrno
;
}
m
gmt
IncTableRef
(
pMsg
->
pTable
);
m
node
IncTableRef
(
pMsg
->
pTable
);
}
}
else
{
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
gmt
GetTable
(
pCreate
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
node
GetTable
(
pCreate
->
tableId
);
}
if
(
pMsg
->
pTable
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
terrno
);
return
;
return
terrno
;
}
SMDCreateTableMsg
*
pMDCreate
=
mgmtBuildCreateChildTableMsg
(
pCreate
,
(
SChildTableObj
*
)
pMsg
->
pTable
);
if
(
pMDCreate
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
terrno
);
return
;
return
terrno
;
}
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
SMnodeMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
pMsg
);
newMsg
->
ahandle
=
pMsg
->
pTable
;
newMsg
->
maxRetry
=
10
;
SRpcIpSet
ipSet
=
mnodeGetIpSetFromVgroup
(
pVgroup
);
pMsg
->
ahandle
=
pMsg
->
pTable
;
pMsg
->
maxRetry
=
10
;
SRpcMsg
rpcMsg
=
{
.
handle
=
new
Msg
,
.
handle
=
p
Msg
,
.
pCont
=
pMDCreate
,
.
contLen
=
htonl
(
pMDCreate
->
contLen
),
.
code
=
0
,
...
...
@@ -1548,22 +1532,22 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
};
dnodeSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
return
TSDB_CODE_ACTION_IN_PROGRESS
;
}
static
void
mgmt
ProcessDropChildTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessDropChildTableMsg
(
SMnodeMsg
*
pMsg
)
{
SChildTableObj
*
pTable
=
(
SChildTableObj
*
)
pMsg
->
pTable
;
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
m
gmt
GetVgroup
(
pTable
->
vgId
);
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
m
node
GetVgroup
(
pTable
->
vgId
);
if
(
pMsg
->
pVgroup
==
NULL
)
{
mError
(
"table:%s, failed to drop ctable, vgroup not exist"
,
pTable
->
info
.
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_OTHERS
);
return
;
return
TSDB_CODE_OTHERS
;
}
SMDDropTableMsg
*
pDrop
=
rpcMallocCont
(
sizeof
(
SMDDropTableMsg
));
if
(
pDrop
==
NULL
)
{
mError
(
"table:%s, failed to drop ctable, no enough memory"
,
pTable
->
info
.
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
strcpy
(
pDrop
->
tableId
,
pTable
->
info
.
tableId
);
...
...
@@ -1572,13 +1556,12 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) {
pDrop
->
sid
=
htonl
(
pTable
->
sid
);
pDrop
->
uid
=
htobe64
(
pTable
->
uid
);
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromVgroup
(
pMsg
->
pVgroup
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromVgroup
(
pMsg
->
pVgroup
);
mPrint
(
"table:%s, send drop ctable msg"
,
pDrop
->
tableId
);
SMnodeMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
pMsg
);
newMsg
->
ahandle
=
pMsg
->
pTable
;
pMsg
->
ahandle
=
pMsg
->
pTable
;
SRpcMsg
rpcMsg
=
{
.
handle
=
new
Msg
,
.
handle
=
p
Msg
,
.
pCont
=
pDrop
,
.
contLen
=
sizeof
(
SMDDropTableMsg
),
.
code
=
0
,
...
...
@@ -1586,13 +1569,15 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) {
};
dnodeSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
return
TSDB_CODE_ACTION_IN_PROGRESS
;
}
static
int32_t
m
gmt
ModifyChildTableTagValue
(
SChildTableObj
*
pTable
,
char
*
tagName
,
char
*
nContent
)
{
static
int32_t
m
node
ModifyChildTableTagValue
(
SChildTableObj
*
pTable
,
char
*
tagName
,
char
*
nContent
)
{
return
TSDB_CODE_OPS_NOT_SUPPORT
;
}
static
int32_t
m
gmt
FindNormalTableColumnIndex
(
SChildTableObj
*
pTable
,
char
*
colName
)
{
static
int32_t
m
node
FindNormalTableColumnIndex
(
SChildTableObj
*
pTable
,
char
*
colName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pTable
->
schema
;
for
(
int32_t
col
=
0
;
col
<
pTable
->
numOfColumns
;
col
++
)
{
if
(
strcasecmp
(
schema
[
col
].
name
,
colName
)
==
0
)
{
...
...
@@ -1603,14 +1588,14 @@ static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colN
return
-
1
;
}
static
int32_t
m
gmt
AddNormalTableColumn
(
SDbObj
*
pDb
,
SChildTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ncols
)
{
static
int32_t
m
node
AddNormalTableColumn
(
SDbObj
*
pDb
,
SChildTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ncols
)
{
if
(
ncols
<=
0
)
{
mError
(
"table:%s, add column, ncols:%d <= 0"
,
pTable
->
info
.
tableId
);
return
TSDB_CODE_APP_ERROR
;
}
for
(
int32_t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
(
m
gmt
FindNormalTableColumnIndex
(
pTable
,
schema
[
i
].
name
)
>
0
)
{
if
(
m
node
FindNormalTableColumnIndex
(
pTable
,
schema
[
i
].
name
)
>
0
)
{
mError
(
"table:%s, add column, column:%s already exist"
,
pTable
->
info
.
tableId
,
schema
[
i
].
name
);
return
TSDB_CODE_FIELD_ALREAY_EXIST
;
}
...
...
@@ -1629,10 +1614,10 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
pTable
->
numOfColumns
+=
ncols
;
pTable
->
sversion
++
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
!=
NULL
)
{
pAcct
->
acctInfo
.
numOfTimeSeries
+=
ncols
;
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
SSdbOper
oper
=
{
...
...
@@ -1650,8 +1635,8 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
DropNormalTableColumn
(
SDbObj
*
pDb
,
SChildTableObj
*
pTable
,
char
*
colName
)
{
int32_t
col
=
m
gmt
FindNormalTableColumnIndex
(
pTable
,
colName
);
static
int32_t
m
node
DropNormalTableColumn
(
SDbObj
*
pDb
,
SChildTableObj
*
pTable
,
char
*
colName
)
{
int32_t
col
=
m
node
FindNormalTableColumnIndex
(
pTable
,
colName
);
if
(
col
<=
0
)
{
mError
(
"table:%s, drop column, column:%s not exist"
,
pTable
->
info
.
tableId
,
colName
);
return
TSDB_CODE_FIELD_NOT_EXIST
;
...
...
@@ -1661,10 +1646,10 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
pTable
->
numOfColumns
--
;
pTable
->
sversion
++
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pDb
->
acct
);
if
(
pAcct
!=
NULL
)
{
pAcct
->
acctInfo
.
numOfTimeSeries
--
;
m
gmt
DecAcctRef
(
pAcct
);
m
node
DecAcctRef
(
pAcct
);
}
SSdbOper
oper
=
{
...
...
@@ -1682,7 +1667,7 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
SetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SChildTableObj
*
pTable
)
{
static
int32_t
m
node
SetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SChildTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
strcpy
(
pSchema
->
name
,
pTable
->
schema
[
i
].
name
);
...
...
@@ -1695,7 +1680,7 @@ static int32_t mgmtSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pT
return
numOfCols
*
sizeof
(
SSchema
);
}
static
int32_t
m
gmt
DoGetChildTableMeta
(
SMnodeMsg
*
pMsg
,
STableMetaMsg
*
pMeta
)
{
static
int32_t
m
node
DoGetChildTableMeta
(
SMnodeMsg
*
pMsg
,
STableMetaMsg
*
pMeta
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
SChildTableObj
*
pTable
=
(
SChildTableObj
*
)
pMsg
->
pTable
;
...
...
@@ -1710,28 +1695,28 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta
->
tversion
=
htons
(
pTable
->
superTable
->
tversion
);
pMeta
->
numOfTags
=
(
int8_t
)
pTable
->
superTable
->
numOfTags
;
pMeta
->
numOfColumns
=
htons
((
int16_t
)
pTable
->
superTable
->
numOfColumns
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
gmt
SetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
->
superTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
node
SetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
->
superTable
);
}
else
{
pMeta
->
sversion
=
htons
(
pTable
->
sversion
);
pMeta
->
tversion
=
0
;
pMeta
->
numOfTags
=
0
;
pMeta
->
numOfColumns
=
htons
((
int16_t
)
pTable
->
numOfColumns
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
gmt
SetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
m
node
SetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
}
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
m
gmt
GetVgroup
(
pTable
->
vgId
);
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
m
node
GetVgroup
(
pTable
->
vgId
);
if
(
pMsg
->
pVgroup
==
NULL
)
{
mError
(
"table:%s, failed to get table meta, db not selected"
,
pTable
->
info
.
tableId
);
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
for
(
int32_t
i
=
0
;
i
<
pMsg
->
pVgroup
->
numOfVnodes
;
++
i
)
{
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pMsg
->
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pMsg
->
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
if
(
pDnode
==
NULL
)
break
;
strcpy
(
pMeta
->
vgroup
.
ipAddr
[
i
].
fqdn
,
pDnode
->
dnodeFqdn
);
pMeta
->
vgroup
.
ipAddr
[
i
].
port
=
htons
(
pDnode
->
dnodePort
+
TSDB_PORT_DNODESHELL
);
pMeta
->
vgroup
.
numOfIps
++
;
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
pMeta
->
vgroup
.
vgId
=
htonl
(
pMsg
->
pVgroup
->
vgId
);
...
...
@@ -1740,7 +1725,7 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
return
TSDB_CODE_SUCCESS
;
}
static
void
mgmtAutoCreateChildTable
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mgmtAutoCreateChildTable
(
SMnodeMsg
*
pMsg
)
{
SCMTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
STagData
*
pTag
=
(
STagData
*
)
pInfo
->
tags
;
...
...
@@ -1748,8 +1733,7 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMCreateTableMsg
*
pCreateMsg
=
rpcMallocCont
(
contLen
);
if
(
pCreateMsg
==
NULL
)
{
mError
(
"table:%s, failed to create table while get meta info, no enough memory"
,
pInfo
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
strncpy
(
pCreateMsg
->
tableId
,
pInfo
->
tableId
,
tListLen
(
pInfo
->
tableId
));
...
...
@@ -1760,34 +1744,33 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) {
memcpy
(
pCreateMsg
->
schema
,
pInfo
->
tags
,
contLen
-
sizeof
(
SCMCreateTableMsg
));
SMnodeMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
pMsg
);
newMsg
->
msgType
=
TSDB_MSG_TYPE_CM_CREATE_TABLE
;
newMsg
->
pCont
=
pCreateMsg
;
pMsg
->
msgType
=
TSDB_MSG_TYPE_CM_CREATE_TABLE
;
rpcFreeCont
(
pMsg
->
pCont
);
pMsg
->
pCont
=
pCreateMsg
;
pMsg
->
contLen
=
contLen
;
mTrace
(
"table:%s, start to create on demand, stable:%s"
,
pInfo
->
tableId
,
pInfo
->
tags
);
mgmtAddToShellQueue
(
newMsg
);
return
TSDB_CODE_ACTION_NEED_REPROCESSED
;
}
static
void
mgmt
GetChildTableMeta
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
GetChildTableMeta
(
SMnodeMsg
*
pMsg
)
{
STableMetaMsg
*
pMeta
=
rpcMallocCont
(
sizeof
(
STableMetaMsg
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
));
if
(
pMeta
==
NULL
)
{
mError
(
"table:%s, failed to get table meta, no enough memory"
,
pMsg
->
pTable
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
m
gmt
DoGetChildTableMeta
(
pMsg
,
pMeta
);
m
node
DoGetChildTableMeta
(
pMsg
,
pMeta
);
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pMeta
,
.
contLen
=
pMeta
->
contLen
,
};
pMsg
->
rpcRsp
.
len
=
pMeta
->
contLen
;
pMsg
->
rpcRsp
.
rsp
=
pMeta
;
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
rpcSendResponse
(
&
rpcRsp
);
return
TSDB_CODE_SUCCESS
;
}
void
m
gmt
DropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
)
{
void
m
node
DropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SChildTableObj
*
pTable
=
NULL
;
...
...
@@ -1795,7 +1778,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
mPrint
(
"vgId:%d, all child tables will be dropped from sdb"
,
pVgroup
->
vgId
);
while
(
1
)
{
pIter
=
m
gmt
GetNextChildTable
(
pIter
,
&
pTable
);
pIter
=
m
node
GetNextChildTable
(
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
pTable
->
vgId
==
pVgroup
->
vgId
)
{
...
...
@@ -1807,7 +1790,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
sdbDeleteRow
(
&
oper
);
numOfTables
++
;
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -1815,7 +1798,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
mPrint
(
"vgId:%d, all child tables is dropped from sdb"
,
pVgroup
->
vgId
);
}
void
m
gmt
DropAllChildTables
(
SDbObj
*
pDropDb
)
{
void
m
node
DropAllChildTables
(
SDbObj
*
pDropDb
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
int32_t
dbNameLen
=
strlen
(
pDropDb
->
name
);
...
...
@@ -1824,7 +1807,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
mPrint
(
"db:%s, all child tables will be dropped from sdb"
,
pDropDb
->
name
);
while
(
1
)
{
pIter
=
m
gmt
GetNextChildTable
(
pIter
,
&
pTable
);
pIter
=
m
node
GetNextChildTable
(
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pDropDb
->
name
,
pTable
->
info
.
tableId
,
dbNameLen
)
==
0
)
{
...
...
@@ -1836,7 +1819,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
sdbDeleteRow
(
&
oper
);
numOfTables
++
;
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -1844,7 +1827,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
mPrint
(
"db:%s, all child tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
static
void
m
gmt
DropAllChildTablesInStable
(
SSuperTableObj
*
pStable
)
{
static
void
m
node
DropAllChildTablesInStable
(
SSuperTableObj
*
pStable
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SChildTableObj
*
pTable
=
NULL
;
...
...
@@ -1852,7 +1835,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
mPrint
(
"stable:%s, all child tables will dropped from sdb"
,
pStable
->
info
.
tableId
,
numOfTables
);
while
(
1
)
{
pIter
=
m
gmt
GetNextChildTable
(
pIter
,
&
pTable
);
pIter
=
m
node
GetNextChildTable
(
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
pTable
->
superTable
==
pStable
)
{
...
...
@@ -1865,7 +1848,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
numOfTables
++
;
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -1873,42 +1856,39 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
mPrint
(
"stable:%s, all child tables:%d is dropped from sdb"
,
pStable
->
info
.
tableId
,
numOfTables
);
}
static
SChildTableObj
*
m
gmt
GetTableByPos
(
int32_t
vnode
,
int32_t
sid
)
{
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
vnode
);
static
SChildTableObj
*
m
node
GetTableByPos
(
int32_t
vnode
,
int32_t
sid
)
{
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
vnode
);
if
(
pVgroup
==
NULL
)
return
NULL
;
SChildTableObj
*
pTable
=
pVgroup
->
tableList
[
sid
-
1
];
m
gmt
IncTableRef
((
STableObj
*
)
pTable
);
m
node
IncTableRef
((
STableObj
*
)
pTable
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
return
pTable
;
}
static
void
mgmtProcessTableCfgMsg
(
SRpcMsg
*
rpc
Msg
)
{
SDMConfigTableMsg
*
pCfg
=
(
SDMConfigTableMsg
*
)
rpc
Msg
->
pCont
;
static
int32_t
mnodeProcessTableCfgMsg
(
SMnodeMsg
*
p
Msg
)
{
SDMConfigTableMsg
*
pCfg
=
(
SDMConfigTableMsg
*
)
p
Msg
->
pCont
;
pCfg
->
dnode
=
htonl
(
pCfg
->
dnode
);
pCfg
->
vnode
=
htonl
(
pCfg
->
vnode
);
pCfg
->
sid
=
htonl
(
pCfg
->
sid
);
mTrace
(
"dnode:%s, vnode:%d, sid:%d, receive table config msg"
,
taosIpStr
(
pCfg
->
dnode
),
pCfg
->
vnode
,
pCfg
->
sid
);
SChildTableObj
*
pTable
=
m
gmt
GetTableByPos
(
pCfg
->
vnode
,
pCfg
->
sid
);
SChildTableObj
*
pTable
=
m
node
GetTableByPos
(
pCfg
->
vnode
,
pCfg
->
sid
);
if
(
pTable
==
NULL
)
{
mError
(
"dnode:%s, vnode:%d, sid:%d, table not found"
,
taosIpStr
(
pCfg
->
dnode
),
pCfg
->
vnode
,
pCfg
->
sid
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_NOT_ACTIVE_TABLE
);
return
;
return
TSDB_CODE_NOT_ACTIVE_TABLE
;
}
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_SUCCESS
);
SMDCreateTableMsg
*
pMDCreate
=
NULL
;
pMDCreate
=
mgmtBuildCreateChildTableMsg
(
NULL
,
(
SChildTableObj
*
)
pTable
);
if
(
pMDCreate
==
NULL
)
{
m
gmt
DecTableRef
(
pTable
);
return
;
m
node
DecTableRef
(
pTable
);
return
terrno
;
}
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pCfg
->
dnode
);
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pCfg
->
dnode
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
SRpcMsg
rpcRsp
=
{
.
handle
=
NULL
,
.
pCont
=
pMDCreate
,
...
...
@@ -1918,32 +1898,33 @@ static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg) {
};
dnodeSendMsgToDnode
(
&
ipSet
,
&
rpcRsp
);
mgmtDecTableRef
(
pTable
);
mgmtDecDnodeRef
(
pDnode
);
mnodeDecTableRef
(
pTable
);
mnodeDecDnodeRef
(
pDnode
);
return
TSDB_CODE_SUCCESS
;
}
// handle drop child response
static
void
m
gmt
ProcessDropChildTableRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessDropChildTableRsp
(
SRpcMsg
*
rpcMsg
)
{
if
(
rpcMsg
->
handle
==
NULL
)
return
;
SMnodeMsg
*
queu
eMsg
=
rpcMsg
->
handle
;
queu
eMsg
->
received
++
;
SMnodeMsg
*
mnod
eMsg
=
rpcMsg
->
handle
;
mnod
eMsg
->
received
++
;
SChildTableObj
*
pTable
=
queu
eMsg
->
ahandle
;
mPrint
(
"table:%s, drop table rsp received, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
queu
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
SChildTableObj
*
pTable
=
mnod
eMsg
->
ahandle
;
mPrint
(
"table:%s, drop table rsp received, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
mnod
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
if
(
rpcMsg
->
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to drop in dnode, reason:%s"
,
pTable
->
info
.
tableId
,
tstrerror
(
rpcMsg
->
code
));
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
rpcMsg
->
code
);
free
(
queueMsg
);
mgmtDecTableRef
(
pTable
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
mnodeDecTableRef
(
pTable
);
return
;
}
if
(
queueMsg
->
pVgroup
==
NULL
)
queueMsg
->
pVgroup
=
mgmt
GetVgroup
(
pTable
->
vgId
);
if
(
queu
eMsg
->
pVgroup
==
NULL
)
{
if
(
mnodeMsg
->
pVgroup
==
NULL
)
mnodeMsg
->
pVgroup
=
mnode
GetVgroup
(
pTable
->
vgId
);
if
(
mnod
eMsg
->
pVgroup
==
NULL
)
{
mError
(
"table:%s, failed to get vgroup"
,
pTable
->
info
.
tableId
);
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
TSDB_CODE_INVALID_VGROUP_ID
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
TSDB_CODE_INVALID_VGROUP_ID
);
return
;
}
...
...
@@ -1956,39 +1937,38 @@ static void mgmtProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
int32_t
code
=
sdbDeleteRow
(
&
oper
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, update ctables sdb error"
,
pTable
->
info
.
tableId
);
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
TSDB_CODE_SDB_ERROR
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
TSDB_CODE_SDB_ERROR
);
return
;
}
if
(
queu
eMsg
->
pVgroup
->
numOfTables
<=
0
)
{
mPrint
(
"vgId:%d, all tables is dropped, drop vgroup"
,
queu
eMsg
->
pVgroup
->
vgId
);
m
gmtDropVgroup
(
queu
eMsg
->
pVgroup
,
NULL
);
if
(
mnod
eMsg
->
pVgroup
->
numOfTables
<=
0
)
{
mPrint
(
"vgId:%d, all tables is dropped, drop vgroup"
,
mnod
eMsg
->
pVgroup
->
vgId
);
m
nodeDropVgroup
(
mnod
eMsg
->
pVgroup
,
NULL
);
}
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
TSDB_CODE_SUCCESS
);
mgmtFreeQueuedMsg
(
queueMsg
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
TSDB_CODE_SUCCESS
);
}
// handle create table response from dnode
// if failed, drop the table cached
static
void
m
gmt
ProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
)
{
if
(
rpcMsg
->
handle
==
NULL
)
return
;
SMnodeMsg
*
queu
eMsg
=
rpcMsg
->
handle
;
queu
eMsg
->
received
++
;
SMnodeMsg
*
mnod
eMsg
=
rpcMsg
->
handle
;
mnod
eMsg
->
received
++
;
SChildTableObj
*
pTable
=
queu
eMsg
->
ahandle
;
mTrace
(
"table:%s, create table rsp received, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
queu
eMsg
->
thandle
,
SChildTableObj
*
pTable
=
mnod
eMsg
->
ahandle
;
mTrace
(
"table:%s, create table rsp received, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
mnod
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
if
(
rpcMsg
->
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
queueMsg
->
retry
++
<
queu
eMsg
->
maxRetry
)
{
if
(
mnodeMsg
->
retry
++
<
mnod
eMsg
->
maxRetry
)
{
mTrace
(
"table:%s, create table rsp received, retry:%d thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
queueMsg
->
retry
,
queu
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
mgmtDealyedAddToShellQueue
(
queu
eMsg
);
mnodeMsg
->
retry
,
mnod
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
dnodeDelayReprocessMnodeWriteMsg
(
mnod
eMsg
);
}
else
{
mError
(
"table:%s, failed to create in dnode, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
queu
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
mnod
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
...
...
@@ -1997,38 +1977,35 @@ static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
};
sdbDeleteRow
(
&
oper
);
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
rpcMsg
->
code
);
mgmtFreeQueuedMsg
(
queueMsg
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
}
}
else
{
mTrace
(
"table:%s, created in dnode, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
queu
eMsg
->
thandle
,
mTrace
(
"table:%s, created in dnode, thandle:%p result:%s"
,
pTable
->
info
.
tableId
,
mnod
eMsg
->
thandle
,
tstrerror
(
rpcMsg
->
code
));
SCMCreateTableMsg
*
pCreate
=
queu
eMsg
->
pCont
;
SCMCreateTableMsg
*
pCreate
=
mnod
eMsg
->
pCont
;
if
(
pCreate
->
getMeta
)
{
mTrace
(
"table:%s, continue to get meta"
,
pTable
->
info
.
tableId
);
queu
eMsg
->
retry
=
0
;
mgmtAddToShellQueue
(
queu
eMsg
);
mnod
eMsg
->
retry
=
0
;
dnodeReprocessMnodeWriteMsg
(
mnod
eMsg
);
}
else
{
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
rpcMsg
->
code
);
mgmtFreeQueuedMsg
(
queueMsg
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
}
}
}
// not implemented yet
static
void
m
gmt
ProcessAlterTableRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessAlterTableRsp
(
SRpcMsg
*
rpcMsg
)
{
mTrace
(
"alter table rsp received, handle:%p code:%s"
,
rpcMsg
->
handle
,
tstrerror
(
rpcMsg
->
code
));
}
static
void
mgmt
ProcessMultiTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessMultiTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
SCMMultiTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
pInfo
->
numOfTables
=
htonl
(
pInfo
->
numOfTables
);
int32_t
totalMallocLen
=
4
*
1024
*
1024
;
// first malloc 4 MB, subsequent reallocation as twice
SMultiTableMeta
*
pMultiMeta
=
rpcMallocCont
(
totalMallocLen
);
if
(
pMultiMeta
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
pMultiMeta
->
contLen
=
sizeof
(
SMultiTableMeta
);
...
...
@@ -2036,12 +2013,12 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
for
(
int32_t
t
=
0
;
t
<
pInfo
->
numOfTables
;
++
t
)
{
char
*
tableId
=
(
char
*
)(
pInfo
->
tableIds
+
t
*
TSDB_TABLE_ID_LEN
+
1
);
SChildTableObj
*
pTable
=
m
gmt
GetChildTable
(
tableId
);
SChildTableObj
*
pTable
=
m
node
GetChildTable
(
tableId
);
if
(
pTable
==
NULL
)
continue
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDbByTableId
(
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDbByTableId
(
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -2050,35 +2027,33 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
totalMallocLen
*=
2
;
pMultiMeta
=
rpcReallocCont
(
pMultiMeta
,
totalMallocLen
);
if
(
pMultiMeta
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
mgmtDecTableRef
(
pTable
);
return
;
mnodeDecTableRef
(
pTable
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
else
{
t
--
;
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
}
STableMetaMsg
*
pMeta
=
(
STableMetaMsg
*
)(
pMultiMeta
->
metas
+
pMultiMeta
->
contLen
);
int32_t
code
=
m
gmt
DoGetChildTableMeta
(
pMsg
,
pMeta
);
int32_t
code
=
m
node
DoGetChildTableMeta
(
pMsg
,
pMeta
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
pMultiMeta
->
numOfTables
++
;
pMultiMeta
->
contLen
+=
pMeta
->
contLen
;
}
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
SRpcMsg
rpcRsp
=
{
0
};
rpcRsp
.
handle
=
pMsg
->
thandle
;
rpcRsp
.
pCont
=
pMultiMeta
;
rpcRsp
.
contLen
=
pMultiMeta
->
contLen
;
rpcSendResponse
(
&
rpcRsp
);
pMsg
->
rpcRsp
.
rsp
=
pMultiMeta
;
pMsg
->
rpcRsp
.
len
=
pMultiMeta
->
contLen
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
GetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
static
int32_t
m
node
GetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
TSDB_CODE_DB_NOT_SELECTED
;
int32_t
cols
=
0
;
...
...
@@ -2119,7 +2094,7 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
pShow
->
numOfRows
=
pDb
->
numOfTables
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
0
;
}
...
...
@@ -2131,8 +2106,8 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_
}
}
static
int32_t
m
gmt
RetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
static
int32_t
m
node
RetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
int32_t
numOfRows
=
0
;
...
...
@@ -2145,12 +2120,12 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
int32_t
prefixLen
=
strlen
(
prefix
);
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextChildTable
(
pShow
->
pIter
,
&
pTable
);
pShow
->
pIter
=
m
node
GetNextChildTable
(
pShow
->
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
// not belong to current db
if
(
strncmp
(
pTable
->
info
.
tableId
,
prefix
,
prefixLen
))
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -2160,7 +2135,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
mgmtExtractTableName
(
pTable
->
info
.
tableId
,
tableName
);
if
(
pShow
->
payloadLen
>
0
&&
patternMatch
(
pShow
->
payload
,
tableName
,
TSDB_TABLE_NAME_LEN
,
&
info
)
!=
TSDB_PATTERN_MATCH
)
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
continue
;
}
...
...
@@ -2195,40 +2170,37 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
cols
++
;
numOfRows
++
;
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
}
pShow
->
numOfReads
+=
numOfRows
;
const
int32_t
NUM_OF_COLUMNS
=
4
;
mgmtVacuumResult
(
data
,
NUM_OF_COLUMNS
,
numOfRows
,
rows
,
pShow
);
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
numOfRows
;
}
static
void
mgmt
ProcessAlterTableMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessAlterTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMAlterTableMsg
*
pAlter
=
pMsg
->
pCont
;
mTrace
(
"table:%s, alter table msg is received from thandle:%p"
,
pAlter
->
tableId
,
pMsg
->
thandle
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
gmt
GetDbByTableId
(
pAlter
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
m
node
GetDbByTableId
(
pAlter
->
tableId
);
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"table:%s, failed to alter table, db not selected"
,
pAlter
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_DB_NOT_SELECTED
);
return
;
return
TSDB_CODE_DB_NOT_SELECTED
;
}
if
(
m
gmt
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
if
(
m
node
CheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"table:%s, failed to alter table, its log db"
,
pAlter
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_MONITOR_DB_FORBIDDEN
);
return
;
return
TSDB_CODE_MONITOR_DB_FORBIDDEN
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
gmt
GetTable
(
pAlter
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
m
node
GetTable
(
pAlter
->
tableId
);
if
(
pMsg
->
pTable
==
NULL
)
{
mError
(
"table:%s, failed to alter table, table not exist"
,
pMsg
->
pTable
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
return
TSDB_CODE_INVALID_TABLE
;
}
pAlter
->
type
=
htons
(
pAlter
->
type
);
...
...
@@ -2237,8 +2209,7 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
if
(
pAlter
->
numOfCols
>
2
)
{
mError
(
"table:%s, error numOfCols:%d in alter table"
,
pAlter
->
tableId
,
pAlter
->
numOfCols
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_APP_ERROR
);
return
;
return
TSDB_CODE_APP_ERROR
;
}
for
(
int32_t
i
=
0
;
i
<
pAlter
->
numOfCols
;
++
i
)
{
...
...
@@ -2250,15 +2221,15 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
SSuperTableObj
*
pTable
=
(
SSuperTableObj
*
)
pMsg
->
pTable
;
mTrace
(
"table:%s, start to alter stable"
,
pAlter
->
tableId
);
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
)
{
code
=
m
gmt
AddSuperTableTag
(
pTable
,
pAlter
->
schema
,
1
);
code
=
m
node
AddSuperTableTag
(
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
)
{
code
=
m
gmt
DropSuperTableTag
(
pTable
,
pAlter
->
schema
[
0
].
name
);
code
=
m
node
DropSuperTableTag
(
pTable
,
pAlter
->
schema
[
0
].
name
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
)
{
code
=
m
gmt
ModifySuperTableTagName
(
pTable
,
pAlter
->
schema
[
0
].
name
,
pAlter
->
schema
[
1
].
name
);
code
=
m
node
ModifySuperTableTagName
(
pTable
,
pAlter
->
schema
[
0
].
name
,
pAlter
->
schema
[
1
].
name
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
code
=
m
gmt
AddSuperTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
,
1
);
code
=
m
node
AddSuperTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_COLUMN
)
{
code
=
m
gmt
DropSuperTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
[
0
].
name
);
code
=
m
node
DropSuperTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
[
0
].
name
);
}
else
{
}
}
else
{
...
...
@@ -2266,14 +2237,14 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
SChildTableObj
*
pTable
=
(
SChildTableObj
*
)
pMsg
->
pTable
;
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
)
{
char
*
tagVal
=
(
char
*
)(
pAlter
->
schema
+
pAlter
->
numOfCols
);
code
=
m
gmt
ModifyChildTableTagValue
(
pTable
,
pAlter
->
schema
[
0
].
name
,
tagVal
);
code
=
m
node
ModifyChildTableTagValue
(
pTable
,
pAlter
->
schema
[
0
].
name
,
tagVal
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
code
=
m
gmt
AddNormalTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
,
1
);
code
=
m
node
AddNormalTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_COLUMN
)
{
code
=
m
gmt
DropNormalTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
[
0
].
name
);
code
=
m
node
DropNormalTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
[
0
].
name
);
}
else
{
}
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
return
code
;
}
src/mnode/src/mnodeUser.c
浏览文件 @
cf687279
...
...
@@ -21,36 +21,39 @@
#include "tglobal.h"
#include "tgrant.h"
#include "tdataformat.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "mnodeMnode.h"
#include "mnodeSdb.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeUser.h"
#include "mnodeWrite.h"
#include "mnodePeer.h"
static
void
*
tsUserSdb
=
NULL
;
static
int32_t
tsUserUpdateSize
=
0
;
static
int32_t
m
gmt
GetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
mgmt
ProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmt
ProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
void
mgmtProcessAuthMsg
(
SRpcMsg
*
rpc
Msg
);
static
int32_t
m
gmt
UserActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
GetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnode
ProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnode
ProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessAuthMsg
(
SMnodeMsg
*
p
Msg
);
static
int32_t
m
node
UserActionDestroy
(
SSdbOper
*
pOper
)
{
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
UserActionInsert
(
SSdbOper
*
pOper
)
{
SUserObj
*
pUser
=
pOper
->
pObj
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pUser
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pUser
->
acct
);
if
(
pAcct
!=
NULL
)
{
m
gmt
AddUserToAcct
(
pAcct
,
pUser
);
m
gmt
DecAcctRef
(
pAcct
);
m
node
AddUserToAcct
(
pAcct
,
pUser
);
m
node
DecAcctRef
(
pAcct
);
}
else
{
mError
(
"user:%s, acct:%s info not exist in sdb"
,
pUser
->
user
,
pUser
->
acct
);
return
TSDB_CODE_INVALID_ACCT
;
...
...
@@ -59,37 +62,37 @@ static int32_t mgmtUserActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
UserActionDelete
(
SSdbOper
*
pOper
)
{
SUserObj
*
pUser
=
pOper
->
pObj
;
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
pUser
->
acct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
pUser
->
acct
);
if
(
pAcct
!=
NULL
)
{
m
gmt
DropUserFromAcct
(
pAcct
,
pUser
);
m
gmt
DecAcctRef
(
pAcct
);
m
node
DropUserFromAcct
(
pAcct
,
pUser
);
m
node
DecAcctRef
(
pAcct
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
UserActionUpdate
(
SSdbOper
*
pOper
)
{
SUserObj
*
pUser
=
pOper
->
pObj
;
SUserObj
*
pSaved
=
m
gmt
GetUser
(
pUser
->
user
);
SUserObj
*
pSaved
=
m
node
GetUser
(
pUser
->
user
);
if
(
pUser
!=
pSaved
)
{
memcpy
(
pSaved
,
pUser
,
tsUserUpdateSize
);
free
(
pUser
);
}
m
gmt
DecUserRef
(
pSaved
);
m
node
DecUserRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
UserActionEncode
(
SSdbOper
*
pOper
)
{
SUserObj
*
pUser
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pUser
,
tsUserUpdateSize
);
pOper
->
rowSize
=
tsUserUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
UserActionDecode
(
SSdbOper
*
pOper
)
{
SUserObj
*
pUser
=
(
SUserObj
*
)
calloc
(
1
,
sizeof
(
SUserObj
));
if
(
pUser
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -98,19 +101,19 @@ static int32_t mgmtUserActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
UserActionRestored
()
{
static
int32_t
m
node
UserActionRestored
()
{
if
(
dnodeIsFirstDeploy
())
{
SAcctObj
*
pAcct
=
m
gmt
GetAcct
(
"root"
);
m
gmt
CreateUser
(
pAcct
,
"root"
,
"taosdata"
);
m
gmt
CreateUser
(
pAcct
,
"monitor"
,
tsInternalPass
);
m
gmt
CreateUser
(
pAcct
,
"_root"
,
tsInternalPass
);
m
gmt
DecAcctRef
(
pAcct
);
SAcctObj
*
pAcct
=
m
node
GetAcct
(
"root"
);
m
node
CreateUser
(
pAcct
,
"root"
,
"taosdata"
);
m
node
CreateUser
(
pAcct
,
"monitor"
,
tsInternalPass
);
m
node
CreateUser
(
pAcct
,
"_root"
,
tsInternalPass
);
m
node
DecAcctRef
(
pAcct
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
m
gmt
InitUsers
()
{
int32_t
m
node
InitUsers
()
{
SUserObj
tObj
;
tsUserUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -121,13 +124,13 @@ int32_t mgmtInitUsers() {
.
maxRowSize
=
tsUserUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
m
gmt
UserActionInsert
,
.
deleteFp
=
m
gmt
UserActionDelete
,
.
updateFp
=
m
gmt
UserActionUpdate
,
.
encodeFp
=
m
gmt
UserActionEncode
,
.
decodeFp
=
m
gmt
UserActionDecode
,
.
destroyFp
=
m
gmt
UserActionDestroy
,
.
restoredFp
=
m
gmt
UserActionRestored
.
insertFp
=
m
node
UserActionInsert
,
.
deleteFp
=
m
node
UserActionDelete
,
.
updateFp
=
m
node
UserActionUpdate
,
.
encodeFp
=
m
node
UserActionEncode
,
.
decodeFp
=
m
node
UserActionDecode
,
.
destroyFp
=
m
node
UserActionDestroy
,
.
restoredFp
=
m
node
UserActionRestored
};
tsUserSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -136,38 +139,38 @@ int32_t mgmtInitUsers() {
return
-
1
;
}
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_USER
,
mgmt
ProcessCreateUserMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_USER
,
mgmt
ProcessAlterUserMsg
);
m
gmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_USER
,
mgmt
ProcessDropUserMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_USER
,
mgmt
GetUserMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_USER
,
mgmt
RetrieveUsers
);
dnodeAddServerMsgHandle
(
TSDB_MSG_TYPE_DM_AUTH
,
mgmt
ProcessAuthMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_USER
,
mnode
ProcessCreateUserMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_USER
,
mnode
ProcessAlterUserMsg
);
m
nodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_USER
,
mnode
ProcessDropUserMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_USER
,
mnode
GetUserMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_USER
,
mnode
RetrieveUsers
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_AUTH
,
mnode
ProcessAuthMsg
);
mTrace
(
"table:%s, hash is created"
,
tableDesc
.
tableName
);
return
0
;
}
void
m
gmtCleanU
pUsers
()
{
void
m
nodeCleanu
pUsers
()
{
sdbCloseTable
(
tsUserSdb
);
}
SUserObj
*
m
gmt
GetUser
(
char
*
name
)
{
SUserObj
*
m
node
GetUser
(
char
*
name
)
{
return
(
SUserObj
*
)
sdbGetRow
(
tsUserSdb
,
name
);
}
void
*
m
gmt
GetNextUser
(
void
*
pIter
,
SUserObj
**
pUser
)
{
void
*
m
node
GetNextUser
(
void
*
pIter
,
SUserObj
**
pUser
)
{
return
sdbFetchRow
(
tsUserSdb
,
pIter
,
(
void
**
)
pUser
);
}
void
m
gmt
IncUserRef
(
SUserObj
*
pUser
)
{
void
m
node
IncUserRef
(
SUserObj
*
pUser
)
{
return
sdbIncRef
(
tsUserSdb
,
pUser
);
}
void
m
gmt
DecUserRef
(
SUserObj
*
pUser
)
{
void
m
node
DecUserRef
(
SUserObj
*
pUser
)
{
return
sdbDecRef
(
tsUserSdb
,
pUser
);
}
static
int32_t
m
gmt
UpdateUser
(
SUserObj
*
pUser
)
{
static
int32_t
m
node
UpdateUser
(
SUserObj
*
pUser
)
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsUserSdb
,
...
...
@@ -182,7 +185,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
return
code
;
}
int32_t
m
gmt
CreateUser
(
SAcctObj
*
pAcct
,
char
*
name
,
char
*
pass
)
{
int32_t
m
node
CreateUser
(
SAcctObj
*
pAcct
,
char
*
name
,
char
*
pass
)
{
int32_t
code
=
acctCheck
(
pAcct
,
ACCT_GRANT_USER
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -196,10 +199,10 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return
TSDB_CODE_INVALID_PASS_FORMAT
;
}
SUserObj
*
pUser
=
m
gmt
GetUser
(
name
);
SUserObj
*
pUser
=
m
node
GetUser
(
name
);
if
(
pUser
!=
NULL
)
{
mTrace
(
"user:%s, is already there"
,
name
);
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
TSDB_CODE_USER_ALREADY_EXIST
;
}
...
...
@@ -235,7 +238,7 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return
code
;
}
static
int32_t
m
gmt
DropUser
(
SUserObj
*
pUser
)
{
static
int32_t
m
node
DropUser
(
SUserObj
*
pUser
)
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsUserSdb
,
...
...
@@ -250,8 +253,8 @@ static int32_t mgmtDropUser(SUserObj *pUser) {
return
code
;
}
static
int32_t
m
gmt
GetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
m
gmt
GetUserFromConn
(
pConn
);
static
int32_t
m
node
GetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
m
node
GetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
{
return
TSDB_CODE_NO_USER_FROM_CONN
;
}
...
...
@@ -289,18 +292,18 @@ static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon
pShow
->
numOfRows
=
pUser
->
pAcct
->
acctInfo
.
numOfUsers
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
return
0
;
}
static
int32_t
m
gmt
RetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
static
int32_t
m
node
RetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SUserObj
*
pUser
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
m
gmt
GetNextUser
(
pShow
->
pIter
,
&
pUser
);
pShow
->
pIter
=
m
node
GetNextUser
(
pShow
->
pIter
,
&
pUser
);
if
(
pUser
==
NULL
)
break
;
cols
=
0
;
...
...
@@ -327,30 +330,30 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
cols
++
;
numOfRows
++
;
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
SUserObj
*
m
gmt
GetUserFromConn
(
void
*
pConn
)
{
SUserObj
*
m
node
GetUserFromConn
(
void
*
pConn
)
{
SRpcConnInfo
connInfo
;
if
(
rpcGetConnInfo
(
pConn
,
&
connInfo
)
==
0
)
{
return
m
gmt
GetUser
(
connInfo
.
user
);
return
m
node
GetUser
(
connInfo
.
user
);
}
else
{
mError
(
"can not get user from conn:%p"
,
pConn
);
return
NULL
;
}
}
static
void
mgmt
ProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
)
{
int32_t
code
;
SUserObj
*
pOperUser
=
pMsg
->
pUser
;
if
(
pOperUser
->
superAuth
)
{
SCMCreateUserMsg
*
pCreate
=
pMsg
->
pCont
;
code
=
m
gmt
CreateUser
(
pOperUser
->
pAcct
,
pCreate
->
user
,
pCreate
->
pass
);
code
=
m
node
CreateUser
(
pOperUser
->
pAcct
,
pCreate
->
user
,
pCreate
->
pass
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"user:%s, is created by %s"
,
pCreate
->
user
,
pOperUser
->
user
);
}
...
...
@@ -359,24 +362,22 @@ static void mgmtProcessCreateUserMsg(SMnodeMsg *pMsg) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
return
code
;
}
static
void
mgmt
ProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
)
{
int32_t
code
;
SUserObj
*
pOperUser
=
pMsg
->
pUser
;
SCMAlterUserMsg
*
pAlter
=
pMsg
->
pCont
;
SUserObj
*
pUser
=
m
gmt
GetUser
(
pAlter
->
user
);
SUserObj
*
pUser
=
m
node
GetUser
(
pAlter
->
user
);
if
(
pUser
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_USER
);
return
;
return
TSDB_CODE_INVALID_USER
;
}
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtDecUserRef
(
pUser
);
return
;
mnodeDecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
if
((
pAlter
->
flag
&
TSDB_ALTER_USER_PASSWD
)
!=
0
)
{
...
...
@@ -398,14 +399,12 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) {
if
(
hasRight
)
{
memset
(
pUser
->
pass
,
0
,
sizeof
(
pUser
->
pass
));
taosEncryptPass
((
uint8_t
*
)
pAlter
->
pass
,
strlen
(
pAlter
->
pass
),
pUser
->
pass
);
code
=
m
gmt
UpdateUser
(
pUser
);
code
=
m
node
UpdateUser
(
pUser
);
mLPrint
(
"user:%s, password is altered by %s, result:%s"
,
pUser
->
user
,
pOperUser
->
user
,
tstrerror
(
code
));
}
else
{
mError
(
"user:%s, no rights to alter user"
,
pOperUser
->
user
);
code
=
TSDB_CODE_NO_RIGHTS
;
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
}
else
if
((
pAlter
->
flag
&
TSDB_ALTER_USER_PRIVILEGES
)
!=
0
)
{
bool
hasRight
=
false
;
...
...
@@ -441,38 +440,35 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) {
pUser
->
writeAuth
=
1
;
}
code
=
m
gmt
UpdateUser
(
pUser
);
code
=
m
node
UpdateUser
(
pUser
);
mLPrint
(
"user:%s, privilege is altered by %s, result:%s"
,
pUser
->
user
,
pOperUser
->
user
,
tstrerror
(
code
));
}
else
{
mError
(
"user:%s, no rights to alter user"
,
pOperUser
->
user
);
code
=
TSDB_CODE_NO_RIGHTS
;
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
}
else
{
mError
(
"user:%s, no rights to alter user"
,
pOperUser
->
user
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
)
;
code
=
TSDB_CODE_NO_RIGHTS
;
}
mgmtDecUserRef
(
pUser
);
mnodeDecUserRef
(
pUser
);
return
code
;
}
static
void
mgmt
ProcessDropUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnode
ProcessDropUserMsg
(
SMnodeMsg
*
pMsg
)
{
int32_t
code
;
SUserObj
*
pOperUser
=
pMsg
->
pUser
;
SCMDropUserMsg
*
pDrop
=
pMsg
->
pCont
;
SUserObj
*
pUser
=
m
gmt
GetUser
(
pDrop
->
user
);
SUserObj
*
pUser
=
m
node
GetUser
(
pDrop
->
user
);
if
(
pUser
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_USER
);
return
;
return
TSDB_CODE_INVALID_USER
;
}
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
strcmp
(
pUser
->
user
,
pUser
->
acct
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtDecUserRef
(
pUser
);
return
;
mnodeDecUserRef
(
pUser
);
return
TSDB_CODE_NO_RIGHTS
;
}
bool
hasRight
=
false
;
...
...
@@ -491,7 +487,7 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) {
}
if
(
hasRight
)
{
code
=
m
gmt
DropUser
(
pUser
);
code
=
m
node
DropUser
(
pUser
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"user:%s, is dropped by %s, result:%s"
,
pUser
->
user
,
pOperUser
->
user
,
tstrerror
(
code
));
}
...
...
@@ -499,18 +495,18 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
m
gmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
mgmtDecUserRef
(
pUser
)
;
m
nodeDecUserRef
(
pUser
);
return
code
;
}
void
mgmt
DropAllUsers
(
SAcctObj
*
pAcct
)
{
void
mnode
DropAllUsers
(
SAcctObj
*
pAcct
)
{
void
*
pIter
=
NULL
;
int32_t
numOfUsers
=
0
;
int32_t
acctNameLen
=
strlen
(
pAcct
->
user
);
SUserObj
*
pUser
=
NULL
;
while
(
1
)
{
pIter
=
m
gmt
GetNextUser
(
pIter
,
&
pUser
);
pIter
=
m
node
GetNextUser
(
pIter
,
&
pUser
);
if
(
pUser
==
NULL
)
break
;
if
(
strncmp
(
pUser
->
acct
,
pAcct
->
user
,
acctNameLen
)
==
0
)
{
...
...
@@ -523,7 +519,7 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
numOfUsers
++
;
}
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -531,14 +527,14 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
mTrace
(
"acct:%s, all users:%d is dropped from sdb"
,
pAcct
->
user
,
numOfUsers
);
}
int32_t
m
gmt
RetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
m
node
RetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
if
(
!
sdbIsMaster
())
{
*
secret
=
0
;
mTrace
(
"user:%s, failed to auth user, reason:%s"
,
user
,
tstrerror
(
TSDB_CODE_NOT_READY
));
return
TSDB_CODE_NOT_READY
;
}
SUserObj
*
pUser
=
m
gmt
GetUser
(
user
);
SUserObj
*
pUser
=
m
node
GetUser
(
user
);
if
(
pUser
==
NULL
)
{
*
secret
=
0
;
mError
(
"user:%s, failed to auth user, reason:%s"
,
user
,
tstrerror
(
TSDB_CODE_INVALID_USER
));
...
...
@@ -549,21 +545,18 @@ int32_t mgmtRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char
*
ckey
=
0
;
memcpy
(
secret
,
pUser
->
pass
,
TSDB_KEY_LEN
);
m
gmt
DecUserRef
(
pUser
);
m
node
DecUserRef
(
pUser
);
mTrace
(
"user:%s, auth info is returned"
,
user
);
return
TSDB_CODE_SUCCESS
;
}
}
static
void
mgmtProcessAuthMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SDMAuthMsg
*
pAuthMsg
=
rpcMsg
->
pCont
;
static
int32_t
mnodeProcessAuthMsg
(
SMnodeMsg
*
pMsg
)
{
SDMAuthMsg
*
pAuthMsg
=
pMsg
->
pCont
;
SDMAuthRsp
*
pAuthRsp
=
rpcMallocCont
(
sizeof
(
SDMAuthRsp
));
rpcRsp
.
code
=
mgmtRetriveAuth
(
pAuthMsg
->
user
,
&
pAuthRsp
->
spi
,
&
pAuthRsp
->
encrypt
,
pAuthRsp
->
secret
,
pAuthRsp
->
ckey
);
rpcRsp
.
pCont
=
pAuthRsp
;
rpcRsp
.
contLen
=
sizeof
(
SDMAuthRsp
);
pMsg
->
rpcRsp
.
rsp
=
pAuthRsp
;
pMsg
->
rpcRsp
.
len
=
sizeof
(
SDMAuthRsp
);
r
pcSendResponse
(
&
rpcRsp
);
r
eturn
mnodeRetriveAuth
(
pAuthMsg
->
user
,
&
pAuthRsp
->
spi
,
&
pAuthRsp
->
encrypt
,
pAuthRsp
->
secret
,
pAuthRsp
->
ckey
);
}
src/mnode/src/mnodeVgroup.c
浏览文件 @
cf687279
...
...
@@ -23,8 +23,9 @@
#include "ttime.h"
#include "tbalance.h"
#include "tglobal.h"
#include "dnode.h"
#include "tdataformat.h"
#include "dnode.h"
#include "mnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeDb.h"
...
...
@@ -32,21 +33,22 @@
#include "mnodeMnode.h"
#include "mnodeProfile.h"
#include "mnodeSdb.h"
#include "mnodeSh
ell
.h"
#include "mnodeSh
ow
.h"
#include "mnodeTable.h"
#include "mnodeVgroup.h"
#include "mnodePeer.h"
static
void
*
tsVgroupSdb
=
NULL
;
static
int32_t
tsVgUpdateSize
=
0
;
static
int32_t
m
gmt
GetVgroupMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
gmt
RetrieveVgroups
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
m
gmt
ProcessCreateVnodeRsp
(
SRpcMsg
*
rpcMsg
);
static
void
m
gmt
ProcessDropVnodeRsp
(
SRpcMsg
*
rpcMsg
);
static
void
mgmtProcessVnodeCfgMsg
(
SRpcMsg
*
rpc
Msg
)
;
static
void
m
gmt
SendDropVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
static
int32_t
m
node
GetVgroupMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
m
node
RetrieveVgroups
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
m
node
ProcessCreateVnodeRsp
(
SRpcMsg
*
rpcMsg
);
static
void
m
node
ProcessDropVnodeRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnodeProcessVnodeCfgMsg
(
SMnodeMsg
*
p
Msg
)
;
static
void
m
node
SendDropVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
static
int32_t
m
gmt
VgroupActionDestroy
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionDestroy
(
SSdbOper
*
pOper
)
{
SVgObj
*
pVgroup
=
pOper
->
pObj
;
if
(
pVgroup
->
idPool
)
{
taosIdPoolCleanUp
(
pVgroup
->
idPool
);
...
...
@@ -60,11 +62,11 @@ static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
VgroupActionInsert
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionInsert
(
SSdbOper
*
pOper
)
{
SVgObj
*
pVgroup
=
pOper
->
pObj
;
// refer to db
SDbObj
*
pDb
=
m
gmt
GetDb
(
pVgroup
->
dbName
);
SDbObj
*
pDb
=
m
node
GetDb
(
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
{
return
TSDB_CODE_INVALID_DB
;
}
...
...
@@ -88,40 +90,40 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) {
}
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
if
(
pDnode
!=
NULL
)
{
pVgroup
->
vnodeGid
[
i
].
pDnode
=
pDnode
;
atomic_add_fetch_32
(
&
pDnode
->
openVnodes
,
1
);
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
}
m
gmt
AddVgroupIntoDb
(
pVgroup
);
m
node
AddVgroupIntoDb
(
pVgroup
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
VgroupActionDelete
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionDelete
(
SSdbOper
*
pOper
)
{
SVgObj
*
pVgroup
=
pOper
->
pObj
;
if
(
pVgroup
->
pDb
!=
NULL
)
{
m
gmt
RemoveVgroupFromDb
(
pVgroup
);
m
node
RemoveVgroupFromDb
(
pVgroup
);
}
m
gmt
DecDbRef
(
pVgroup
->
pDb
);
m
node
DecDbRef
(
pVgroup
->
pDb
);
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
if
(
pDnode
!=
NULL
)
{
atomic_sub_fetch_32
(
&
pDnode
->
openVnodes
,
1
);
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
m
gmt
VgroupUpdateIdPool
(
SVgObj
*
pVgroup
)
{
static
void
m
node
VgroupUpdateIdPool
(
SVgObj
*
pVgroup
)
{
int32_t
oldTables
=
taosIdPoolMaxSize
(
pVgroup
->
idPool
);
SDbObj
*
pDb
=
pVgroup
->
pDb
;
if
(
pDb
!=
NULL
)
{
...
...
@@ -135,9 +137,9 @@ static void mgmtVgroupUpdateIdPool(SVgObj *pVgroup) {
}
}
static
int32_t
m
gmt
VgroupActionUpdate
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionUpdate
(
SSdbOper
*
pOper
)
{
SVgObj
*
pNew
=
pOper
->
pObj
;
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pNew
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pNew
->
vgId
);
if
(
pVgroup
!=
pNew
)
{
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
...
...
@@ -151,24 +153,24 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
free
(
pNew
);
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pVgroup
->
vnodeGid
[
i
].
dnodeId
);
pVgroup
->
vnodeGid
[
i
].
pDnode
=
pDnode
;
if
(
pDnode
!=
NULL
)
{
atomic_add_fetch_32
(
&
pDnode
->
openVnodes
,
1
);
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
}
}
m
gmt
VgroupUpdateIdPool
(
pVgroup
);
m
node
VgroupUpdateIdPool
(
pVgroup
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
mTrace
(
"vgId:%d, is updated, numOfVnode:%d"
,
pVgroup
->
vgId
,
pVgroup
->
numOfVnodes
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
VgroupActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionEncode
(
SSdbOper
*
pOper
)
{
SVgObj
*
pVgroup
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pVgroup
,
tsVgUpdateSize
);
SVgObj
*
pTmpVgroup
=
pOper
->
rowData
;
...
...
@@ -181,7 +183,7 @@ static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
VgroupActionDecode
(
SSdbOper
*
pOper
)
{
static
int32_t
m
node
VgroupActionDecode
(
SSdbOper
*
pOper
)
{
SVgObj
*
pVgroup
=
(
SVgObj
*
)
calloc
(
1
,
sizeof
(
SVgObj
));
if
(
pVgroup
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
...
...
@@ -190,11 +192,11 @@ static int32_t mgmtVgroupActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
m
gmt
VgroupActionRestored
()
{
static
int32_t
m
node
VgroupActionRestored
()
{
return
0
;
}
int32_t
m
gmt
InitVgroups
()
{
int32_t
m
node
InitVgroups
()
{
SVgObj
tObj
;
tsVgUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
...
...
@@ -205,13 +207,13 @@ int32_t mgmtInitVgroups() {
.
maxRowSize
=
tsVgUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_AUTO
,
.
insertFp
=
m
gmt
VgroupActionInsert
,
.
deleteFp
=
m
gmt
VgroupActionDelete
,
.
updateFp
=
m
gmt
VgroupActionUpdate
,
.
encodeFp
=
m
gmt
VgroupActionEncode
,
.
decodeFp
=
m
gmt
VgroupActionDecode
,
.
destroyFp
=
m
gmt
VgroupActionDestroy
,
.
restoredFp
=
m
gmt
VgroupActionRestored
,
.
insertFp
=
m
node
VgroupActionInsert
,
.
deleteFp
=
m
node
VgroupActionDelete
,
.
updateFp
=
m
node
VgroupActionUpdate
,
.
encodeFp
=
m
node
VgroupActionEncode
,
.
decodeFp
=
m
node
VgroupActionDecode
,
.
destroyFp
=
m
node
VgroupActionDestroy
,
.
restoredFp
=
m
node
VgroupActionRestored
,
};
tsVgroupSdb
=
sdbOpenTable
(
&
tableDesc
);
...
...
@@ -220,30 +222,30 @@ int32_t mgmtInitVgroups() {
return
-
1
;
}
mnodeAddShowMetaHandle
(
TSDB_M
NODE_TABLE_VGROUP
,
mgmt
GetVgroupMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
NODE_TABLE_VGROUP
,
mgmt
RetrieveVgroups
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP
,
mgmt
ProcessCreateVnodeRsp
);
dnodeAddClientRspHandle
(
TSDB_MSG_TYPE_MD_DROP_VNODE_RSP
,
mgmt
ProcessDropVnodeRsp
);
dnodeAddServerMsgHandle
(
TSDB_MSG_TYPE_DM_CONFIG_VNODE
,
mgmt
ProcessVnodeCfgMsg
);
mnodeAddShowMetaHandle
(
TSDB_M
GMT_TABLE_VGROUP
,
mnode
GetVgroupMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_M
GMT_TABLE_VGROUP
,
mnode
RetrieveVgroups
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP
,
mnode
ProcessCreateVnodeRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_DROP_VNODE_RSP
,
mnode
ProcessDropVnodeRsp
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_CONFIG_VNODE
,
mnode
ProcessVnodeCfgMsg
);
mTrace
(
"table:vgroups is created"
);
return
0
;
}
void
m
gmt
IncVgroupRef
(
SVgObj
*
pVgroup
)
{
void
m
node
IncVgroupRef
(
SVgObj
*
pVgroup
)
{
return
sdbIncRef
(
tsVgroupSdb
,
pVgroup
);
}
void
m
gmt
DecVgroupRef
(
SVgObj
*
pVgroup
)
{
void
m
node
DecVgroupRef
(
SVgObj
*
pVgroup
)
{
return
sdbDecRef
(
tsVgroupSdb
,
pVgroup
);
}
SVgObj
*
m
gmt
GetVgroup
(
int32_t
vgId
)
{
SVgObj
*
m
node
GetVgroup
(
int32_t
vgId
)
{
return
(
SVgObj
*
)
sdbGetRow
(
tsVgroupSdb
,
&
vgId
);
}
void
m
gmt
UpdateVgroup
(
SVgObj
*
pVgroup
)
{
void
m
node
UpdateVgroup
(
SVgObj
*
pVgroup
)
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsVgroupSdb
,
...
...
@@ -251,10 +253,10 @@ void mgmtUpdateVgroup(SVgObj *pVgroup) {
};
sdbUpdateRow
(
&
oper
);
m
gmt
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
m
node
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
}
void
m
gmt
UpdateVgroupStatus
(
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
,
SVnodeLoad
*
pVload
)
{
void
m
node
UpdateVgroupStatus
(
SVgObj
*
pVgroup
,
SDnodeObj
*
pDnode
,
SVnodeLoad
*
pVload
)
{
bool
dnodeExist
=
false
;
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
...
...
@@ -269,9 +271,9 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
}
if
(
!
dnodeExist
)
{
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromIp
(
pDnode
->
dnodeEp
);
mError
(
"vgId:%d, dnode:%d not exist in mnode, drop it"
,
pVload
->
vgId
,
pDnode
->
dnodeId
);
m
gmt
SendDropVnodeMsg
(
pVload
->
vgId
,
&
ipSet
,
NULL
);
m
node
SendDropVnodeMsg
(
pVload
->
vgId
,
&
ipSet
,
NULL
);
return
;
}
...
...
@@ -285,19 +287,19 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
mError
(
"dnode:%d, vgId:%d, vnode cfgVersion:%d repica:%d not match with mgmt cfgVersion:%d replica:%d"
,
pDnode
->
dnodeId
,
pVload
->
vgId
,
pVload
->
cfgVersion
,
pVload
->
replica
,
pVgroup
->
pDb
->
cfgVersion
,
pVgroup
->
numOfVnodes
);
m
gmt
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
m
node
SendCreateVgroupMsg
(
pVgroup
,
NULL
);
}
}
SVgObj
*
m
gmt
GetAvailableVgroup
(
SDbObj
*
pDb
)
{
SVgObj
*
m
node
GetAvailableVgroup
(
SDbObj
*
pDb
)
{
return
pDb
->
pHead
;
}
void
*
m
gmt
GetNextVgroup
(
void
*
pIter
,
SVgObj
**
pVgroup
)
{
void
*
m
node
GetNextVgroup
(
void
*
pIter
,
SVgObj
**
pVgroup
)
{
return
sdbFetchRow
(
tsVgroupSdb
,
pIter
,
(
void
**
)
pVgroup
);
}
void
mgmt
CreateVgroup
(
SMnodeMsg
*
pMsg
,
SDbObj
*
pDb
)
{
int32_t
mnode
CreateVgroup
(
SMnodeMsg
*
pMsg
,
SDbObj
*
pDb
)
{
SVgObj
*
pVgroup
=
(
SVgObj
*
)
calloc
(
1
,
sizeof
(
SVgObj
));
strcpy
(
pVgroup
->
dbName
,
pDb
->
name
);
pVgroup
->
numOfVnodes
=
pDb
->
cfg
.
replications
;
...
...
@@ -305,9 +307,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if
(
balanceAllocVnodes
(
pVgroup
)
!=
0
)
{
mError
(
"db:%s, no enough dnode to alloc %d vnodes to vgroup"
,
pDb
->
name
,
pVgroup
->
numOfVnodes
);
free
(
pVgroup
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_ENOUGH_DNODES
);
mgmtFreeQueuedMsg
(
pMsg
);
return
;
mnodeCleanupMsg
(
pMsg
);
return
TSDB_CODE_NO_ENOUGH_DNODES
;
}
SSdbOper
oper
=
{
...
...
@@ -321,9 +322,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pVgroup
);
code
=
TSDB_CODE_SDB_ERROR
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SDB_ERROR
);
mgmtFreeQueuedMsg
(
pMsg
);
return
;
mnodeCleanupMsg
(
pMsg
);
return
TSDB_CODE_SDB_ERROR
;
}
mPrint
(
"vgId:%d, is created in mnode, db:%s replica:%d"
,
pVgroup
->
vgId
,
pDb
->
name
,
pVgroup
->
numOfVnodes
);
...
...
@@ -333,15 +333,17 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
pMsg
->
ahandle
=
pVgroup
;
pMsg
->
expected
=
pVgroup
->
numOfVnodes
;
mgmtSendCreateVgroupMsg
(
pVgroup
,
pMsg
);
mnodeSendCreateVgroupMsg
(
pVgroup
,
pMsg
);
return
TSDB_CODE_ACTION_IN_PROGRESS
;
}
void
m
gmt
DropVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
void
m
node
DropVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
if
(
ahandle
!=
NULL
)
{
m
gmt
SendDropVgroupMsg
(
pVgroup
,
ahandle
);
m
node
SendDropVgroupMsg
(
pVgroup
,
ahandle
);
}
else
{
mTrace
(
"vgId:%d, replica:%d is deleting from sdb"
,
pVgroup
->
vgId
,
pVgroup
->
numOfVnodes
);
m
gmt
SendDropVgroupMsg
(
pVgroup
,
NULL
);
m
node
SendDropVgroupMsg
(
pVgroup
,
NULL
);
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsVgroupSdb
,
...
...
@@ -351,12 +353,12 @@ void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) {
}
}
void
m
gmtCleanU
pVgroups
()
{
void
m
nodeCleanu
pVgroups
()
{
sdbCloseTable
(
tsVgroupSdb
);
}
int32_t
m
gmt
GetVgroupMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
int32_t
m
node
GetVgroupMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
{
return
TSDB_CODE_DB_NOT_SELECTED
;
}
...
...
@@ -380,15 +382,15 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SVgObj
*
pVgroup
=
NULL
;
STableObj
*
pTable
=
NULL
;
if
(
pShow
->
payloadLen
>
0
)
{
pTable
=
m
gmt
GetTable
(
pShow
->
payload
);
pTable
=
m
node
GetTable
(
pShow
->
payload
);
if
(
NULL
==
pTable
||
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
m
gmt
DecTableRef
(
pTable
);
m
node
DecTableRef
(
pTable
);
return
TSDB_CODE_INVALID_TABLE_ID
;
}
m
gmt
DecTableRef
(
pTable
);
pVgroup
=
m
gmt
GetVgroup
(((
SChildTableObj
*
)
pTable
)
->
vgId
);
m
node
DecTableRef
(
pTable
);
pVgroup
=
m
node
GetVgroup
(((
SChildTableObj
*
)
pTable
)
->
vgId
);
if
(
NULL
==
pVgroup
)
return
TSDB_CODE_INVALID_TABLE_ID
;
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
maxReplica
=
pVgroup
->
numOfVnodes
>
maxReplica
?
pVgroup
->
numOfVnodes
:
maxReplica
;
}
else
{
SVgObj
*
pVgroup
=
pDb
->
pHead
;
...
...
@@ -434,19 +436,19 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow
->
pIter
=
pVgroup
;
}
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
0
;
}
int32_t
m
gmt
RetrieveVgroups
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
m
node
RetrieveVgroups
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SVgObj
*
pVgroup
=
NULL
;
int32_t
maxReplica
=
0
;
int32_t
cols
=
0
;
char
*
pWrite
;
SDbObj
*
pDb
=
m
gmt
GetDb
(
pShow
->
db
);
SDbObj
*
pDb
=
m
node
GetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
pVgroup
=
pDb
->
pHead
;
...
...
@@ -483,7 +485,7 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
role
=
m
gmt
GetMnodeRoleStr
(
pVgroup
->
vnodeGid
[
i
].
role
);
char
*
role
=
m
node
GetMnodeRoleStr
(
pVgroup
->
vnodeGid
[
i
].
role
);
STR_TO_VARSTR
(
pWrite
,
role
);
cols
++
;
}
else
{
...
...
@@ -502,12 +504,12 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
}
pShow
->
numOfReads
+=
numOfRows
;
m
gmt
DecDbRef
(
pDb
);
m
node
DecDbRef
(
pDb
);
return
numOfRows
;
}
void
m
gmt
AddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
)
{
void
m
node
AddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
)
{
if
(
pTable
->
sid
>=
1
&&
pVgroup
->
tableList
[
pTable
->
sid
-
1
]
==
NULL
)
{
pVgroup
->
tableList
[
pTable
->
sid
-
1
]
=
pTable
;
taosIdPoolMarkStatus
(
pVgroup
->
idPool
,
pTable
->
sid
);
...
...
@@ -515,21 +517,21 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
}
if
(
pVgroup
->
numOfTables
>=
pVgroup
->
pDb
->
cfg
.
maxTables
)
{
m
gmt
MoveVgroupToTail
(
pVgroup
);
m
node
MoveVgroupToTail
(
pVgroup
);
}
m
gmt
IncVgroupRef
(
pVgroup
);
m
node
IncVgroupRef
(
pVgroup
);
}
void
m
gmt
RemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
)
{
void
m
node
RemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SChildTableObj
*
pTable
)
{
if
(
pTable
->
sid
>=
1
&&
pVgroup
->
tableList
[
pTable
->
sid
-
1
]
!=
NULL
)
{
pVgroup
->
tableList
[
pTable
->
sid
-
1
]
=
NULL
;
taosFreeId
(
pVgroup
->
idPool
,
pTable
->
sid
);
pVgroup
->
numOfTables
--
;
}
m
gmt
MoveVgroupToHead
(
pVgroup
);
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
MoveVgroupToHead
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
SMDCreateVnodeMsg
*
mgmtBuildCreateVnodeMsg
(
SVgObj
*
pVgroup
)
{
...
...
@@ -571,7 +573,7 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
return
pVnode
;
}
SRpcIpSet
m
gmt
GetIpSetFromVgroup
(
SVgObj
*
pVgroup
)
{
SRpcIpSet
m
node
GetIpSetFromVgroup
(
SVgObj
*
pVgroup
)
{
SRpcIpSet
ipSet
=
{
.
numOfIps
=
pVgroup
->
numOfVnodes
,
.
inUse
=
0
,
...
...
@@ -583,7 +585,7 @@ SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) {
return
ipSet
;
}
SRpcIpSet
m
gmt
GetIpSetFromIp
(
char
*
ep
)
{
SRpcIpSet
m
node
GetIpSetFromIp
(
char
*
ep
)
{
SRpcIpSet
ipSet
;
ipSet
.
numOfIps
=
1
;
...
...
@@ -593,7 +595,7 @@ SRpcIpSet mgmtGetIpSetFromIp(char *ep) {
return
ipSet
;
}
void
m
gmt
SendCreateVnodeMsg
(
SVgObj
*
pVgroup
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
)
{
void
m
node
SendCreateVnodeMsg
(
SVgObj
*
pVgroup
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
)
{
mTrace
(
"vgId:%d, send create vnode:%d msg, ahandle:%p"
,
pVgroup
->
vgId
,
pVgroup
->
vgId
,
ahandle
);
SMDCreateVnodeMsg
*
pCreate
=
mgmtBuildCreateVnodeMsg
(
pVgroup
);
SRpcMsg
rpcMsg
=
{
...
...
@@ -606,34 +608,33 @@ void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
dnodeSendMsgToDnode
(
ipSet
,
&
rpcMsg
);
}
void
m
gmt
SendCreateVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
void
m
node
SendCreateVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
mTrace
(
"vgId:%d, send create all vnodes msg, ahandle:%p"
,
pVgroup
->
vgId
,
ahandle
);
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromIp
(
pVgroup
->
vnodeGid
[
i
].
pDnode
->
dnodeEp
);
m
gmt
SendCreateVnodeMsg
(
pVgroup
,
&
ipSet
,
ahandle
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromIp
(
pVgroup
->
vnodeGid
[
i
].
pDnode
->
dnodeEp
);
m
node
SendCreateVnodeMsg
(
pVgroup
,
&
ipSet
,
ahandle
);
}
}
static
void
m
gmt
ProcessCreateVnodeRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessCreateVnodeRsp
(
SRpcMsg
*
rpcMsg
)
{
if
(
rpcMsg
->
handle
==
NULL
)
return
;
SMnodeMsg
*
queu
eMsg
=
rpcMsg
->
handle
;
queu
eMsg
->
received
++
;
SMnodeMsg
*
mnod
eMsg
=
rpcMsg
->
handle
;
mnod
eMsg
->
received
++
;
if
(
rpcMsg
->
code
==
TSDB_CODE_SUCCESS
)
{
queu
eMsg
->
code
=
rpcMsg
->
code
;
queu
eMsg
->
successed
++
;
mnod
eMsg
->
code
=
rpcMsg
->
code
;
mnod
eMsg
->
successed
++
;
}
SVgObj
*
pVgroup
=
queu
eMsg
->
ahandle
;
SVgObj
*
pVgroup
=
mnod
eMsg
->
ahandle
;
mTrace
(
"vgId:%d, create vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p"
,
pVgroup
->
vgId
,
tstrerror
(
rpcMsg
->
code
),
queueMsg
->
received
,
queueMsg
->
successed
,
queu
eMsg
->
expected
,
queu
eMsg
->
thandle
,
rpcMsg
->
handle
);
pVgroup
->
vgId
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
received
,
mnodeMsg
->
successed
,
mnod
eMsg
->
expected
,
mnod
eMsg
->
thandle
,
rpcMsg
->
handle
);
if
(
queueMsg
->
received
!=
queu
eMsg
->
expected
)
return
;
if
(
mnodeMsg
->
received
!=
mnod
eMsg
->
expected
)
return
;
if
(
queueMsg
->
received
==
queueMsg
->
successed
)
{
SMnodeMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
queueMsg
);
mgmtAddToShellQueue
(
newMsg
);
if
(
mnodeMsg
->
received
==
mnodeMsg
->
successed
)
{
dnodeReprocessMnodeWriteMsg
(
mnodeMsg
);
}
else
{
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
...
...
@@ -645,10 +646,8 @@ static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
code
=
TSDB_CODE_SDB_ERROR
;
}
mgmtSendSimpleResp
(
queueMsg
->
thandle
,
rpcMsg
->
code
);
dnodeSendRpcMnodeWriteRsp
(
mnodeMsg
,
code
);
}
mgmtFreeQueuedMsg
(
queueMsg
);
}
static
SMDDropVnodeMsg
*
mgmtBuildDropVnodeMsg
(
int32_t
vgId
)
{
...
...
@@ -659,7 +658,7 @@ static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) {
return
pDrop
;
}
void
m
gmt
SendDropVnodeMsg
(
int32_t
vgId
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
)
{
void
m
node
SendDropVnodeMsg
(
int32_t
vgId
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
)
{
SMDDropVnodeMsg
*
pDrop
=
mgmtBuildDropVnodeMsg
(
vgId
);
SRpcMsg
rpcMsg
=
{
.
handle
=
ahandle
,
...
...
@@ -671,32 +670,32 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) {
dnodeSendMsgToDnode
(
ipSet
,
&
rpcMsg
);
}
static
void
m
gmt
SendDropVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
static
void
m
node
SendDropVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
)
{
mTrace
(
"vgId:%d, send drop all vnodes msg, ahandle:%p"
,
pVgroup
->
vgId
,
ahandle
);
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SRpcIpSet
ipSet
=
m
gmt
GetIpSetFromIp
(
pVgroup
->
vnodeGid
[
i
].
pDnode
->
dnodeEp
);
SRpcIpSet
ipSet
=
m
node
GetIpSetFromIp
(
pVgroup
->
vnodeGid
[
i
].
pDnode
->
dnodeEp
);
mTrace
(
"vgId:%d, send drop vnode msg to dnode:%d, ahandle:%p"
,
pVgroup
->
vgId
,
pVgroup
->
vnodeGid
[
i
].
dnodeId
,
ahandle
);
m
gmt
SendDropVnodeMsg
(
pVgroup
->
vgId
,
&
ipSet
,
ahandle
);
m
node
SendDropVnodeMsg
(
pVgroup
->
vgId
,
&
ipSet
,
ahandle
);
}
}
static
void
m
gmt
ProcessDropVnodeRsp
(
SRpcMsg
*
rpcMsg
)
{
static
void
m
node
ProcessDropVnodeRsp
(
SRpcMsg
*
rpcMsg
)
{
mTrace
(
"drop vnode rsp is received, handle:%p"
,
rpcMsg
->
handle
);
if
(
rpcMsg
->
handle
==
NULL
)
return
;
SMnodeMsg
*
queu
eMsg
=
rpcMsg
->
handle
;
queu
eMsg
->
received
++
;
SMnodeMsg
*
mnod
eMsg
=
rpcMsg
->
handle
;
mnod
eMsg
->
received
++
;
if
(
rpcMsg
->
code
==
TSDB_CODE_SUCCESS
)
{
queu
eMsg
->
code
=
rpcMsg
->
code
;
queu
eMsg
->
successed
++
;
mnod
eMsg
->
code
=
rpcMsg
->
code
;
mnod
eMsg
->
successed
++
;
}
SVgObj
*
pVgroup
=
queu
eMsg
->
ahandle
;
SVgObj
*
pVgroup
=
mnod
eMsg
->
ahandle
;
mTrace
(
"vgId:%d, drop vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p"
,
pVgroup
->
vgId
,
tstrerror
(
rpcMsg
->
code
),
queueMsg
->
received
,
queueMsg
->
successed
,
queu
eMsg
->
expected
,
queu
eMsg
->
thandle
,
rpcMsg
->
handle
);
pVgroup
->
vgId
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
received
,
mnodeMsg
->
successed
,
mnod
eMsg
->
expected
,
mnod
eMsg
->
thandle
,
rpcMsg
->
handle
);
if
(
queueMsg
->
received
!=
queu
eMsg
->
expected
)
return
;
if
(
mnodeMsg
->
received
!=
mnod
eMsg
->
expected
)
return
;
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
...
...
@@ -708,41 +707,35 @@ static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
code
=
TSDB_CODE_SDB_ERROR
;
}
SMnodeMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
queueMsg
);
mgmtAddToShellQueue
(
newMsg
);
queueMsg
->
pCont
=
NULL
;
mgmtFreeQueuedMsg
(
queueMsg
);
dnodeReprocessMnodeWriteMsg
(
mnodeMsg
);
}
static
void
mgmtProcessVnodeCfgMsg
(
SRpcMsg
*
rpc
Msg
)
{
SDMConfigVnodeMsg
*
pCfg
=
(
SDMConfigVnodeMsg
*
)
rpc
Msg
->
pCont
;
static
int32_t
mnodeProcessVnodeCfgMsg
(
SMnodeMsg
*
p
Msg
)
{
SDMConfigVnodeMsg
*
pCfg
=
(
SDMConfigVnodeMsg
*
)
p
Msg
->
pCont
;
pCfg
->
dnodeId
=
htonl
(
pCfg
->
dnodeId
);
pCfg
->
vgId
=
htonl
(
pCfg
->
vgId
);
SDnodeObj
*
pDnode
=
m
gmt
GetDnode
(
pCfg
->
dnodeId
);
SDnodeObj
*
pDnode
=
m
node
GetDnode
(
pCfg
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mTrace
(
"dnode:%s, invalid dnode"
,
taosIpStr
(
pCfg
->
dnodeId
),
pCfg
->
vgId
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_NOT_ACTIVE_VNODE
);
return
;
return
TSDB_CODE_NOT_ACTIVE_VNODE
;
}
m
gmt
DecDnodeRef
(
pDnode
);
m
node
DecDnodeRef
(
pDnode
);
SVgObj
*
pVgroup
=
m
gmt
GetVgroup
(
pCfg
->
vgId
);
SVgObj
*
pVgroup
=
m
node
GetVgroup
(
pCfg
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mTrace
(
"dnode:%s, vgId:%d, no vgroup info"
,
taosIpStr
(
pCfg
->
dnodeId
),
pCfg
->
vgId
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_NOT_ACTIVE_VNODE
);
return
;
return
TSDB_CODE_NOT_ACTIVE_VNODE
;
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_SUCCESS
);
SRpcIpSet
ipSet
=
mnodeGetIpSetFromIp
(
pDnode
->
dnodeEp
);
mnodeSendCreateVnodeMsg
(
pVgroup
,
&
ipSet
,
NULL
);
SRpcIpSet
ipSet
=
mgmtGetIpSetFromIp
(
pDnode
->
dnodeEp
);
mgmtSendCreateVnodeMsg
(
pVgroup
,
&
ipSet
,
NULL
);
return
TSDB_CODE_SUCCESS
;
}
void
m
gmt
DropAllDnodeVgroups
(
SDnodeObj
*
pDropDnode
)
{
void
m
node
DropAllDnodeVgroups
(
SDnodeObj
*
pDropDnode
)
{
void
*
pIter
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
int32_t
numOfVgroups
=
0
;
...
...
@@ -750,11 +743,11 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
mPrint
(
"dnode:%d, all vgroups will be dropped from sdb"
,
pDropDnode
->
dnodeId
);
while
(
1
)
{
pIter
=
m
gmt
GetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
m
node
GetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
->
vnodeGid
[
0
].
dnodeId
==
pDropDnode
->
dnodeId
)
{
m
gmt
DropAllChildTablesInVgroups
(
pVgroup
);
m
node
DropAllChildTablesInVgroups
(
pVgroup
);
SSdbOper
oper
=
{
.
type
=
SDB_OPER_LOCAL
,
.
table
=
tsVgroupSdb
,
...
...
@@ -763,7 +756,7 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
sdbDeleteRow
(
&
oper
);
numOfVgroups
++
;
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -771,21 +764,21 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
mPrint
(
"dnode:%d, all vgroups is dropped from sdb"
,
pDropDnode
->
dnodeId
);
}
void
m
gmt
UpdateAllDbVgroups
(
SDbObj
*
pAlterDb
)
{
void
m
node
UpdateAllDbVgroups
(
SDbObj
*
pAlterDb
)
{
void
*
pIter
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
mPrint
(
"db:%s, all vgroups will be update in sdb"
,
pAlterDb
->
name
);
while
(
1
)
{
pIter
=
m
gmt
GetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
m
node
GetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
->
pDb
==
pAlterDb
)
{
m
gmt
VgroupUpdateIdPool
(
pVgroup
);
m
node
VgroupUpdateIdPool
(
pVgroup
);
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
sdbFreeIter
(
pIter
);
...
...
@@ -793,14 +786,14 @@ void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb) {
mPrint
(
"db:%s, all vgroups is updated in sdb"
,
pAlterDb
->
name
);
}
void
m
gmt
DropAllDbVgroups
(
SDbObj
*
pDropDb
,
bool
sendMsg
)
{
void
m
node
DropAllDbVgroups
(
SDbObj
*
pDropDb
,
bool
sendMsg
)
{
void
*
pIter
=
NULL
;
int32_t
numOfVgroups
=
0
;
SVgObj
*
pVgroup
=
NULL
;
mPrint
(
"db:%s, all vgroups will be dropped from sdb"
,
pDropDb
->
name
);
while
(
1
)
{
pIter
=
m
gmt
GetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
m
node
GetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
->
pDb
==
pDropDb
)
{
...
...
@@ -813,11 +806,11 @@ void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) {
numOfVgroups
++
;
if
(
sendMsg
)
{
m
gmt
SendDropVgroupMsg
(
pVgroup
,
NULL
);
m
node
SendDropVgroupMsg
(
pVgroup
,
NULL
);
}
}
m
gmt
DecVgroupRef
(
pVgroup
);
m
node
DecVgroupRef
(
pVgroup
);
}
sdbFreeIter
(
pIter
);
...
...
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
[
rpcMsg
->
msgType
])(
pMsg
);
}
static
void
mgmtDoDealyedAddToShellQueue
(
void
*
param
,
void
*
tmrId
)
{
mgmtAddToShellQueue
(
param
);
}
void
mgmtDealyedAddToShellQueue
(
SMnodeMsg
*
queuedMsg
)
{
void
*
unUsed
=
NULL
;
taosTmrReset
(
mgmtDoDealyedAddToShellQueue
,
300
,
queuedMsg
,
tsMgmtTmr
,
&
unUsed
);
return
(
*
tsMnodeProcessWriteMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录