提交 cf687279 编写于 作者: S Shengliang Guan

[TD-335] first compiler vresion

上级 7ac821f2
...@@ -2175,7 +2175,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -2175,7 +2175,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
*/ */
SShowInfo* pShowInfo = &pInfo->pDCLInfo->showOpt; SShowInfo* pShowInfo = &pInfo->pDCLInfo->showOpt;
int16_t showType = pShowInfo->showType; int16_t showType = pShowInfo->showType;
if (showType == TSDB_MNODE_TABLE_TABLE || showType == TSDB_MNODE_TABLE_METRIC || showType == TSDB_MNODE_TABLE_VGROUP) { if (showType == TSDB_MGMT_TABLE_TABLE || showType == TSDB_MGMT_TABLE_METRIC || showType == TSDB_MGMT_TABLE_VGROUP) {
// db prefix in tagCond, show table conds in payload // db prefix in tagCond, show table conds in payload
SSQLToken* pDbPrefixToken = &pShowInfo->prefix; SSQLToken* pDbPrefixToken = &pShowInfo->prefix;
if (pDbPrefixToken->type != 0) { if (pDbPrefixToken->type != 0) {
...@@ -2212,7 +2212,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -2212,7 +2212,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
} }
} else if (showType == TSDB_MNODE_TABLE_VNODES) { } else if (showType == TSDB_MGMT_TABLE_VNODES) {
if (pShowInfo->prefix.type == 0) { if (pShowInfo->prefix.type == 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "No specified ip of dnode"); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "No specified ip of dnode");
} }
......
...@@ -1116,7 +1116,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1116,7 +1116,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SShowInfo *pShowInfo = &pInfo->pDCLInfo->showOpt; SShowInfo *pShowInfo = &pInfo->pDCLInfo->showOpt;
pShowMsg->type = pShowInfo->showType; pShowMsg->type = pShowInfo->showType;
if (pShowInfo->showType != TSDB_MNODE_TABLE_VNODES) { if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
SSQLToken *pPattern = &pShowInfo->pattern; SSQLToken *pPattern = &pShowInfo->pattern;
if (pPattern->type > 0) { // only show tables support wildcard query if (pPattern->type > 0) { // only show tables support wildcard query
strncpy(pShowMsg->payload, pPattern->z, pPattern->n); strncpy(pShowMsg->payload, pPattern->z, pPattern->n);
......
...@@ -100,7 +100,7 @@ extern int32_t tsMaxMgmtConnections; ...@@ -100,7 +100,7 @@ extern int32_t tsMaxMgmtConnections;
extern int32_t tsBalanceInterval; extern int32_t tsBalanceInterval;
extern int32_t tsOfflineThreshold; extern int32_t tsOfflineThreshold;
extern int32_t tsMgmtEqualVnodeNum; extern int32_t tsMnodeEqualVnodeNum;
extern int32_t tsEnableHttpModule; extern int32_t tsEnableHttpModule;
extern int32_t tsEnableMqttModule; extern int32_t tsEnableMqttModule;
......
...@@ -117,7 +117,7 @@ int32_t tsMaxVnodeConnections = 10000; ...@@ -117,7 +117,7 @@ int32_t tsMaxVnodeConnections = 10000;
int32_t tsBalanceInterval = 300; // seconds int32_t tsBalanceInterval = 300; // seconds
int32_t tsOfflineThreshold = 86400*100; // seconds 10days int32_t tsOfflineThreshold = 86400*100; // seconds 10days
int32_t tsMgmtEqualVnodeNum = 4; int32_t tsMnodeEqualVnodeNum = 4;
int32_t tsEnableHttpModule = 1; int32_t tsEnableHttpModule = 1;
int32_t tsEnableMqttModule = 0; // not finished yet, not started it by default int32_t tsEnableMqttModule = 0; // not finished yet, not started it by default
...@@ -874,7 +874,7 @@ static void doInitGlobalConfig() { ...@@ -874,7 +874,7 @@ static void doInitGlobalConfig() {
// module configs // module configs
cfg.option = "mgmtEqualVnodeNum"; cfg.option = "mgmtEqualVnodeNum";
cfg.ptr = &tsMgmtEqualVnodeNum; cfg.ptr = &tsMnodeEqualVnodeNum;
cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 0; cfg.minValue = 0;
......
...@@ -16,7 +16,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) ...@@ -16,7 +16,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)
ADD_EXECUTABLE(taosd ${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) IF (TD_ACCOUNT)
TARGET_LINK_LIBRARIES(taosd account) TARGET_LINK_LIBRARIES(taosd account)
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
extern "C" { extern "C" {
#endif #endif
int32_t dnodeInitMnodeMgmt(); int32_t dnodeInitMnodePeer();
void dnodeCleanupMnodeMgmt(); void dnodeCleanupMnodePeer();
void dnodeDispatchToMnodeMgmtQueue(SRpcMsg *pMsg); void dnodeDispatchToMnodePeerQueue(SRpcMsg *pMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -32,7 +32,9 @@ void* dnodeGetVnodeWal(void *pVnode); ...@@ -32,7 +32,9 @@ void* dnodeGetVnodeWal(void *pVnode);
void* dnodeGetVnodeTsdb(void *pVnode); void* dnodeGetVnodeTsdb(void *pVnode);
void dnodeReleaseVnode(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 #ifdef __cplusplus
} }
......
...@@ -25,51 +25,51 @@ ...@@ -25,51 +25,51 @@
#include "mnode.h" #include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeMWrite.h" #include "dnodeMWrite.h"
typedef struct { typedef struct {
pthread_t thread; pthread_t thread;
int32_t workerId; int32_t workerId;
} SMMgmtWorker; } SMPeerWorker;
typedef struct { typedef struct {
int32_t num; int32_t num;
SMMgmtWorker *mgmtWorker; SMPeerWorker *peerWorker;
} SMMgmtWorkerPool; } SMPeerWorkerPool;
static SMMgmtWorkerPool tsMMgmtPool; static SMPeerWorkerPool tsMPeerPool;
static taos_qset tsMMgmtQset; static taos_qset tsMPeerQset;
static taos_queue tsMMgmtQueue; static taos_queue tsMPeerQueue;
static void *dnodeProcessMnodeMgmtQueue(void *param); static void *dnodeProcessMnodePeerQueue(void *param);
int32_t dnodeInitMnodeMgmt() { int32_t dnodeInitMnodePeer() {
tsMMgmtQset = taosOpenQset(); tsMPeerQset = taosOpenQset();
tsMMgmtPool.num = 1; tsMPeerPool.num = 1;
tsMMgmtPool.mgmtWorker = (SMMgmtWorker *)calloc(sizeof(SMMgmtWorker), tsMMgmtPool.num); tsMPeerPool.peerWorker = (SMPeerWorker *)calloc(sizeof(SMPeerWorker), tsMPeerPool.num);
if (tsMMgmtPool.mgmtWorker == NULL) return -1; if (tsMPeerPool.peerWorker == NULL) return -1;
for (int32_t i = 0; i < tsMMgmtPool.num; ++i) { for (int32_t i = 0; i < tsMPeerPool.num; ++i) {
SMMgmtWorker *pWorker = tsMMgmtPool.mgmtWorker + i; SMPeerWorker *pWorker = tsMPeerPool.peerWorker + i;
pWorker->workerId = i; pWorker->workerId = i;
} }
dPrint("dnode mmgmt is opened"); dPrint("dnode mpeer is opened");
return 0; return 0;
} }
void dnodeCleanupMnodeMgmt() { void dnodeCleanupMnodePeer() {
for (int32_t i = 0; i < tsMMgmtPool.num; ++i) { for (int32_t i = 0; i < tsMPeerPool.num; ++i) {
SMMgmtWorker *pWorker = tsMMgmtPool.mgmtWorker + i; SMPeerWorker *pWorker = tsMPeerPool.peerWorker + i;
if (pWorker->thread) { if (pWorker->thread) {
taosQsetThreadResume(tsMMgmtQset); taosQsetThreadResume(tsMPeerQset);
} }
} }
for (int32_t i = 0; i < tsMMgmtPool.num; ++i) { for (int32_t i = 0; i < tsMPeerPool.num; ++i) {
SMMgmtWorker *pWorker = tsMMgmtPool.mgmtWorker + i; SMPeerWorker *pWorker = tsMPeerPool.peerWorker + i;
if (pWorker->thread) { if (pWorker->thread) {
pthread_join(pWorker->thread, NULL); pthread_join(pWorker->thread, NULL);
} }
...@@ -78,77 +78,77 @@ void dnodeCleanupMnodeMgmt() { ...@@ -78,77 +78,77 @@ void dnodeCleanupMnodeMgmt() {
dPrint("dnode mmgmt is closed"); dPrint("dnode mmgmt is closed");
} }
int32_t dnodeAllocateMnodeMqueue() { int32_t dnodeAllocateMnodePqueue() {
tsMMgmtQueue = taosOpenQueue(); tsMPeerQueue = taosOpenQueue();
if (tsMMgmtQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (tsMPeerQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
taosAddIntoQset(tsMMgmtQset, tsMMgmtQueue, NULL); taosAddIntoQset(tsMPeerQset, tsMPeerQueue, NULL);
for (int32_t i = 0; i < tsMMgmtPool.num; ++i) { for (int32_t i = 0; i < tsMPeerPool.num; ++i) {
SMMgmtWorker *pWorker = tsMMgmtPool.mgmtWorker + i; SMPeerWorker *pWorker = tsMPeerPool.peerWorker + i;
pWorker->workerId = i; pWorker->workerId = i;
pthread_attr_t thAttr; pthread_attr_t thAttr;
pthread_attr_init(&thAttr); pthread_attr_init(&thAttr);
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessMnodeMgmtQueue, pWorker) != 0) { if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessMnodePeerQueue, pWorker) != 0) {
dError("failed to create thread to process mmgmt queue, reason:%s", strerror(errno)); dError("failed to create thread to process mmgmt queue, reason:%s", strerror(errno));
} }
pthread_attr_destroy(&thAttr); pthread_attr_destroy(&thAttr);
dTrace("dnode mmgmt worker:%d is launched, total:%d", pWorker->workerId, tsMMgmtPool.num); dTrace("dnode mmgmt worker:%d is launched, total:%d", pWorker->workerId, tsMPeerPool.num);
} }
dTrace("dnode mmgmt queue:%p is allocated", tsMMgmtQueue); dTrace("dnode mmgmt queue:%p is allocated", tsMPeerQueue);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void dnodeFreeMnodeRqueue() { void dnodeFreeMnodePqueue() {
taosCloseQueue(tsMMgmtQueue); taosCloseQueue(tsMPeerQueue);
tsMMgmtQueue = NULL; tsMPeerQueue = NULL;
} }
void dnodeDispatchToMnodeMgmtQueue(SRpcMsg *pMsg) { void dnodeDispatchToMnodePeerQueue(SRpcMsg *pMsg) {
if (!mnodeIsRunning() || tsMMgmtQueue == NULL) { if (!mnodeIsRunning() || tsMPeerQueue == NULL) {
dnodeSendRediretMsg(pMsg); dnodeSendRedirectMsg(pMsg->msgType, pMsg->handle, false);
return; return;
} }
SMnodeMsg *pMgmt = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg)); SMnodeMsg *pPeer = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg));
pMgmt->rpcMsg = *pMsg; mnodeCreateMsg(pPeer, pMsg);
taosWriteQitem(tsMMgmtQueue, TAOS_QTYPE_RPC, pMgmt); taosWriteQitem(tsMPeerQueue, TAOS_QTYPE_RPC, pPeer);
} }
static void dnodeSendRpcMnodeMgmtRsp(SMnodeMsg *pMgmt, int32_t code) { static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) {
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pMgmt->rpcMsg.handle, .handle = pPeer->thandle,
.pCont = pMgmt->rspRet.rsp, .pCont = pPeer->rpcRsp.rsp,
.contLen = pMgmt->rspRet.len, .contLen = pPeer->rpcRsp.len,
.code = pMgmt->rspRet.code, .code = code,
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
rpcFreeCont(pMgmt->rpcMsg.pCont); mnodeCleanupMsg(pPeer);
} }
static void *dnodeProcessMnodeMgmtQueue(void *param) { static void *dnodeProcessMnodePeerQueue(void *param) {
SMnodeMsg *pMgmtMsg; SMnodeMsg *pPeerMsg;
int32_t type; int32_t type;
void * unUsed; void * unUsed;
while (1) { while (1) {
if (taosReadQitemFromQset(tsMMgmtQset, &type, (void **)&pMgmtMsg, &unUsed) == 0) { if (taosReadQitemFromQset(tsMPeerQset, &type, (void **)&pPeerMsg, &unUsed) == 0) {
dTrace("dnodeProcessMnodeMgmtQueue: got no message from qset, exiting..."); dTrace("dnodeProcessMnodePeerQueue: got no message from qset, exiting...");
break; break;
} }
dTrace("%p, msg:%s will be processed", pMgmtMsg->rpcMsg.ahandle, taosMsg[pMgmtMsg->rpcMsg.msgType]); dTrace("%p, msg:%s will be processed", pPeerMsg->ahandle, taosMsg[pPeerMsg->msgType]);
int32_t code = mnodeProcessMgmt(pMgmtMsg); int32_t code = mnodeProcessPeerReq(pPeerMsg);
dnodeSendRpcMnodeMgmtRsp(pMgmtMsg, code); dnodeSendRpcMnodePeerRsp(pPeerMsg, code);
taosFreeQitem(pMgmtMsg); taosFreeQitem(pPeerMsg);
} }
return NULL; return NULL;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "mnode.h" #include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeMRead.h" #include "dnodeMRead.h"
typedef struct { typedef struct {
...@@ -116,12 +116,12 @@ void dnodeFreeMnodeRqueue() { ...@@ -116,12 +116,12 @@ void dnodeFreeMnodeRqueue() {
void dnodeDispatchToMnodeReadQueue(SRpcMsg *pMsg) { void dnodeDispatchToMnodeReadQueue(SRpcMsg *pMsg) {
if (!mnodeIsRunning() || tsMReadQueue == NULL) { if (!mnodeIsRunning() || tsMReadQueue == NULL) {
dnodeSendRediretMsg(pMsg); dnodeSendRedirectMsg(pMsg->msgType, pMsg->handle, true);
return; return;
} }
SMnodeMsg *pRead = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg)); SMnodeMsg *pRead = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg));
pRead->rpcMsg = *pMsg; mnodeCreateMsg(pRead, pMsg);
taosWriteQitem(tsMReadQueue, TAOS_QTYPE_RPC, pRead); taosWriteQitem(tsMReadQueue, TAOS_QTYPE_RPC, pRead);
} }
...@@ -129,14 +129,14 @@ static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) { ...@@ -129,14 +129,14 @@ static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) {
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pRead->rpcMsg.handle, .handle = pRead->thandle,
.pCont = pRead->rspRet.rsp, .pCont = pRead->rpcRsp.rsp,
.contLen = pRead->rspRet.len, .contLen = pRead->rpcRsp.len,
.code = pRead->rspRet.code, .code = code,
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
rpcFreeCont(pRead->rpcMsg.pCont); mnodeCleanupMsg(pRead);
} }
static void *dnodeProcessMnodeReadQueue(void *param) { static void *dnodeProcessMnodeReadQueue(void *param) {
...@@ -150,7 +150,7 @@ static void *dnodeProcessMnodeReadQueue(void *param) { ...@@ -150,7 +150,7 @@ static void *dnodeProcessMnodeReadQueue(void *param) {
break; 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); int32_t code = mnodeProcessRead(pReadMsg);
dnodeSendRpcMnodeReadRsp(pReadMsg, code); dnodeSendRpcMnodeReadRsp(pReadMsg, code);
taosFreeQitem(pReadMsg); taosFreeQitem(pReadMsg);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "taoserror.h" #include "taoserror.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tutil.h" #include "tutil.h"
#include "ttimer.h"
#include "tqueue.h" #include "tqueue.h"
#include "trpc.h" #include "trpc.h"
#include "twal.h" #include "twal.h"
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
#include "mnode.h" #include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeMWrite.h" #include "dnodeMWrite.h"
typedef struct { typedef struct {
...@@ -41,6 +42,7 @@ typedef struct { ...@@ -41,6 +42,7 @@ typedef struct {
static SMWriteWorkerPool tsMWritePool; static SMWriteWorkerPool tsMWritePool;
static taos_qset tsMWriteQset; static taos_qset tsMWriteQset;
static taos_queue tsMWriteQueue; static taos_queue tsMWriteQueue;
extern void * tsDnodeTmr;
static void *dnodeProcessMnodeWriteQueue(void *param); static void *dnodeProcessMnodeWriteQueue(void *param);
...@@ -78,7 +80,7 @@ void dnodeCleanupMnodeWrite() { ...@@ -78,7 +80,7 @@ void dnodeCleanupMnodeWrite() {
dPrint("dnode mwrite is closed"); dPrint("dnode mwrite is closed");
} }
int32_t dnodeAllocateMnodeRqueue() { int32_t dnodeAllocateMnodeWqueue() {
tsMWriteQueue = taosOpenQueue(); tsMWriteQueue = taosOpenQueue();
if (tsMWriteQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (tsMWriteQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -104,34 +106,35 @@ int32_t dnodeAllocateMnodeRqueue() { ...@@ -104,34 +106,35 @@ int32_t dnodeAllocateMnodeRqueue() {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void dnodeFreeMnodeRqueue() { void dnodeFreeMnodeWqueue() {
taosCloseQueue(tsMWriteQueue); taosCloseQueue(tsMWriteQueue);
tsMWriteQueue = NULL; tsMWriteQueue = NULL;
} }
void dnodeDispatchToMnodeWriteQueue(SRpcMsg *pMsg) { void dnodeDispatchToMnodeWriteQueue(SRpcMsg *pMsg) {
if (!mnodeIsRunning() || tsMWriteQueue == NULL) { if (!mnodeIsRunning() || tsMWriteQueue == NULL) {
dnodeSendRediretMsg(pMsg); dnodeSendRedirectMsg(pMsg->msgType, pMsg->handle, true);
return; return;
} }
SMnodeMsg *pWrite = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg)); SMnodeMsg *pWrite = (SMnodeMsg *)taosAllocateQitem(sizeof(SMnodeMsg));
pWrite->rpcMsg = *pMsg; mnodeCreateMsg(pWrite, pMsg);
taosWriteQitem(tsMWriteQueue, TAOS_QTYPE_RPC, pWrite); 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; if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pWrite->rpcMsg.handle, .handle = pWrite->thandle,
.pCont = pWrite->rspRet.rsp, .pCont = pWrite->rpcRsp.rsp,
.contLen = pWrite->rspRet.len, .contLen = pWrite->rpcRsp.len,
.code = pWrite->rspRet.code, .code = code,
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
rpcFreeCont(pWrite->rpcMsg.pCont); mnodeCleanupMsg(pWrite);
} }
static void *dnodeProcessMnodeWriteQueue(void *param) { static void *dnodeProcessMnodeWriteQueue(void *param) {
...@@ -145,7 +148,7 @@ static void *dnodeProcessMnodeWriteQueue(void *param) { ...@@ -145,7 +148,7 @@ static void *dnodeProcessMnodeWriteQueue(void *param) {
break; 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); int32_t code = mnodeProcessWrite(pWriteMsg);
dnodeSendRpcMnodeWriteRsp(pWriteMsg, code); dnodeSendRpcMnodeWriteRsp(pWriteMsg, code);
taosFreeQitem(pWriteMsg); taosFreeQitem(pWriteMsg);
...@@ -153,3 +156,30 @@ static void *dnodeProcessMnodeWriteQueue(void *param) { ...@@ -153,3 +156,30 @@ static void *dnodeProcessMnodeWriteQueue(void *param) {
return NULL; 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
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
#include "tglobal.h" #include "tglobal.h"
#include "dnode.h" #include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodePeer.h" #include "dnodePeer.h"
#include "dnodeModule.h" #include "dnodeModule.h"
#include "dnodeVRead.h" #include "dnodeVRead.h"
#include "dnodeVWrite.h" #include "dnodeVWrite.h"
#include "dnodeMRead.h" #include "dnodeMRead.h"
#include "dnodeMWrite.h" #include "dnodeMWrite.h"
#include "dnodeMMgmt.h" #include "dnodeMPeer.h"
#include "dnodeShell.h" #include "dnodeShell.h"
static int32_t dnodeInitStorage(); static int32_t dnodeInitStorage();
...@@ -72,7 +72,7 @@ int32_t dnodeInitSystem() { ...@@ -72,7 +72,7 @@ int32_t dnodeInitSystem() {
if (dnodeInitVnodeWrite() != 0) return -1; if (dnodeInitVnodeWrite() != 0) return -1;
if (dnodeInitMnodeRead() != 0) return -1; if (dnodeInitMnodeRead() != 0) return -1;
if (dnodeInitMnodeWrite() != 0) return -1; if (dnodeInitMnodeWrite() != 0) return -1;
if (dnodeInitMnodeMgmt() != 0) return -1; if (dnodeInitMnodePeer() != 0) return -1;
if (dnodeInitClient() != 0) return -1; if (dnodeInitClient() != 0) return -1;
if (dnodeInitServer() != 0) return -1; if (dnodeInitServer() != 0) return -1;
if (dnodeInitMgmt() != 0) return -1; if (dnodeInitMgmt() != 0) return -1;
...@@ -95,7 +95,7 @@ void dnodeCleanUpSystem() { ...@@ -95,7 +95,7 @@ void dnodeCleanUpSystem() {
dnodeCleanupMgmt(); dnodeCleanupMgmt();
dnodeCleanupServer(); dnodeCleanupServer();
dnodeCleanupClient(); dnodeCleanupClient();
dnodeCleanupMnodeMgmt(); dnodeCleanupMnodePeer();
dnodeCleanupMnodeWrite(); dnodeCleanupMnodeWrite();
dnodeCleanupMnodeRead(); dnodeCleanupMnodeRead();
dnodeCleanupVnodeWrite(); dnodeCleanupVnodeWrite();
......
...@@ -32,13 +32,22 @@ ...@@ -32,13 +32,22 @@
#include "vnode.h" #include "vnode.h"
#include "mnode.h" #include "mnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeVRead.h" #include "dnodeVRead.h"
#include "dnodeVWrite.h" #include "dnodeVWrite.h"
#include "dnodeModule.h" #include "dnodeModule.h"
#define MPEER_CONTENT_LEN 2000 #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 void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes);
static bool dnodeReadMnodeInfos(); static bool dnodeReadMnodeInfos();
static void dnodeSaveMnodeInfos(); static void dnodeSaveMnodeInfos();
...@@ -48,14 +57,6 @@ static void dnodeSaveDnodeCfg(); ...@@ -48,14 +57,6 @@ static void dnodeSaveDnodeCfg();
static void dnodeProcessStatusRsp(SRpcMsg *pMsg); static void dnodeProcessStatusRsp(SRpcMsg *pMsg);
static void dnodeSendStatusMsg(void *handle, void *tmrId); 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 int32_t dnodeOpenVnodes();
static void dnodeCloseVnodes(); static void dnodeCloseVnodes();
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg); static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg);
...@@ -81,22 +82,40 @@ int32_t dnodeInitMgmt() { ...@@ -81,22 +82,40 @@ int32_t dnodeInitMgmt() {
} }
if (!dnodeReadMnodeInfos()) { if (!dnodeReadMnodeInfos()) {
memset(&tsMnodeIpSet, 0, sizeof(SRpcIpSet)); memset(&tsDMnodeIpSetForPeer, 0, sizeof(SRpcIpSet));
memset(&tsMnodeInfos, 0, sizeof(SDMMnodeInfos)); memset(&tsDMnodeIpSetForShell, 0, sizeof(SRpcIpSet));
tsMnodeIpSet.numOfIps = 1; memset(&tsDMnodeInfos, 0, sizeof(SDMMnodeInfos));
taosGetFqdnPortFromEp(tsFirst, tsMnodeIpSet.fqdn[0], &tsMnodeIpSet.port[0]);
tsMnodeIpSet.port[0] += TSDB_PORT_DNODEDNODE; 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) { if (strcmp(tsSecond, tsFirst) != 0) {
tsMnodeIpSet.numOfIps = 2; tsDMnodeIpSetForPeer.numOfIps = 2;
taosGetFqdnPortFromEp(tsSecond, tsMnodeIpSet.fqdn[1], &tsMnodeIpSet.port[1]); taosGetFqdnPortFromEp(tsSecond, tsDMnodeIpSetForPeer.fqdn[1], &tsDMnodeIpSetForPeer.port[1]);
tsMnodeIpSet.port[1] += TSDB_PORT_DNODEDNODE; tsDMnodeIpSetForPeer.port[1] += TSDB_PORT_DNODEDNODE;
tsDMnodeIpSetForShell.numOfIps = 2;
taosGetFqdnPortFromEp(tsSecond, tsDMnodeIpSetForShell.fqdn[1], &tsDMnodeIpSetForShell.port[1]);
tsDMnodeIpSetForShell.port[1] += TSDB_PORT_DNODESHELL;
} }
} else { } else {
tsMnodeIpSet.inUse = tsMnodeInfos.inUse; tsDMnodeIpSetForPeer.inUse = tsDMnodeInfos.inUse;
tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum; tsDMnodeIpSetForPeer.numOfIps = tsDMnodeInfos.nodeNum;
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, tsMnodeIpSet.fqdn[i], &tsMnodeIpSet.port[i]); taosGetFqdnPortFromEp(tsDMnodeInfos.nodeInfos[i].nodeEp, tsDMnodeIpSetForPeer.fqdn[i], &tsDMnodeIpSetForPeer.port[i]);
tsMnodeIpSet.port[i] += TSDB_PORT_DNODEDNODE; 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) { ...@@ -265,26 +284,23 @@ static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg) {
return taosCfgDynamicOptions(pCfg->config); return taosCfgDynamicOptions(pCfg->config);
} }
void dnodeUpdateIpSet(SRpcIpSet *pIpSet) { void dnodeUpdateMnodeIpSetForPeer(SRpcIpSet *pIpSet) {
dPrint("mnode IP list is changed, numOfIps:%d inUse:%d", pIpSet->numOfIps, pIpSet->inUse); dPrint("mnode IP list is changed, numOfIps:%d inUse:%d", pIpSet->numOfIps, pIpSet->inUse);
for (int i = 0; i < pIpSet->numOfIps; ++i) { for (int i = 0; i < pIpSet->numOfIps; ++i) {
dPrint("mnode index:%d %s:%u", i, pIpSet->fqdn[i], pIpSet->port[i]) dPrint("mnode index:%d %s:%u", i, pIpSet->fqdn[i], pIpSet->port[i])
} }
tsMnodeIpSet = *pIpSet; tsDMnodeIpSetForPeer = *pIpSet;
} }
void dnodeGetMnodeDnodeIpSet(void *ipSetRaw, bool encode) { void dnodeGetMnodeIpSetForPeer(void *ipSetRaw) {
SRpcIpSet *ipSet = ipSetRaw; SRpcIpSet *ipSet = ipSetRaw;
ipSet->numOfIps = tsMnodeInfos.nodeNum; *ipSet = tsDMnodeIpSetForPeer;
ipSet->inUse = tsMnodeInfos.inUse; }
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; ++i) {
taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, ipSet->fqdn[i], &ipSet->port[i]); void dnodeGetMnodeIpSetForShell(void *ipSetRaw) {
ipSet->port[i] += TSDB_PORT_DNODEDNODE; SRpcIpSet *ipSet = ipSetRaw;
if (encode) { *ipSet = tsDMnodeIpSetForShell;
ipSet->port[i] = htons(ipSet->port[i]);
}
}
} }
static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
...@@ -324,22 +340,22 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { ...@@ -324,22 +340,22 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
} }
static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes) { static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes) {
bool mnodesChanged = (memcmp(&tsMnodeInfos, pMnodes, sizeof(SDMMnodeInfos)) != 0); bool mnodesChanged = (memcmp(&tsDMnodeInfos, pMnodes, sizeof(SDMMnodeInfos)) != 0);
bool mnodesNotInit = (tsMnodeInfos.nodeNum == 0); bool mnodesNotInit = (tsDMnodeInfos.nodeNum == 0);
if (!(mnodesChanged || mnodesNotInit)) return; if (!(mnodesChanged || mnodesNotInit)) return;
memcpy(&tsMnodeInfos, pMnodes, sizeof(SDMMnodeInfos)); memcpy(&tsDMnodeInfos, pMnodes, sizeof(SDMMnodeInfos));
tsMnodeIpSet.inUse = tsMnodeInfos.inUse; tsDMnodeIpSetForPeer.inUse = tsDMnodeInfos.inUse;
tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum; tsDMnodeIpSetForPeer.numOfIps = tsDMnodeInfos.nodeNum;
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, tsMnodeIpSet.fqdn[i], &tsMnodeIpSet.port[i]); taosGetFqdnPortFromEp(tsDMnodeInfos.nodeInfos[i].nodeEp, tsDMnodeIpSetForPeer.fqdn[i], &tsDMnodeIpSetForPeer.port[i]);
tsMnodeIpSet.port[i] += TSDB_PORT_DNODEDNODE; tsDMnodeIpSetForPeer.port[i] += TSDB_PORT_DNODEDNODE;
} }
dPrint("mnodes is changed, nodeNum:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse); dPrint("mnodes is changed, nodeNum:%d inUse:%d", tsDMnodeInfos.nodeNum, tsDMnodeInfos.inUse);
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
dPrint("mnode:%d, %s", tsMnodeInfos.nodeInfos[i].nodeId, tsMnodeInfos.nodeInfos[i].nodeEp); dPrint("mnode:%d, %s", tsDMnodeInfos.nodeInfos[i].nodeId, tsDMnodeInfos.nodeInfos[i].nodeEp);
} }
dnodeSaveMnodeInfos(); dnodeSaveMnodeInfos();
...@@ -377,14 +393,14 @@ static bool dnodeReadMnodeInfos() { ...@@ -377,14 +393,14 @@ static bool dnodeReadMnodeInfos() {
dError("failed to read mnode mgmtIpList.json, inUse not found"); dError("failed to read mnode mgmtIpList.json, inUse not found");
goto PARSE_OVER; goto PARSE_OVER;
} }
tsMnodeInfos.inUse = inUse->valueint; tsDMnodeInfos.inUse = inUse->valueint;
cJSON* nodeNum = cJSON_GetObjectItem(root, "nodeNum"); cJSON* nodeNum = cJSON_GetObjectItem(root, "nodeNum");
if (!nodeNum || nodeNum->type != cJSON_Number) { if (!nodeNum || nodeNum->type != cJSON_Number) {
dError("failed to read mnode mgmtIpList.json, nodeNum not found"); dError("failed to read mnode mgmtIpList.json, nodeNum not found");
goto PARSE_OVER; goto PARSE_OVER;
} }
tsMnodeInfos.nodeNum = nodeNum->valueint; tsDMnodeInfos.nodeNum = nodeNum->valueint;
cJSON* nodeInfos = cJSON_GetObjectItem(root, "nodeInfos"); cJSON* nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
if (!nodeInfos || nodeInfos->type != cJSON_Array) { if (!nodeInfos || nodeInfos->type != cJSON_Array) {
...@@ -393,7 +409,7 @@ static bool dnodeReadMnodeInfos() { ...@@ -393,7 +409,7 @@ static bool dnodeReadMnodeInfos() {
} }
int size = cJSON_GetArraySize(nodeInfos); int size = cJSON_GetArraySize(nodeInfos);
if (size != tsMnodeInfos.nodeNum) { if (size != tsDMnodeInfos.nodeNum) {
dError("failed to read mnode mgmtIpList.json, nodeInfos size not matched"); dError("failed to read mnode mgmtIpList.json, nodeInfos size not matched");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -407,21 +423,21 @@ static bool dnodeReadMnodeInfos() { ...@@ -407,21 +423,21 @@ static bool dnodeReadMnodeInfos() {
dError("failed to read mnode mgmtIpList.json, nodeId not found"); dError("failed to read mnode mgmtIpList.json, nodeId not found");
goto PARSE_OVER; goto PARSE_OVER;
} }
tsMnodeInfos.nodeInfos[i].nodeId = nodeId->valueint; tsDMnodeInfos.nodeInfos[i].nodeId = nodeId->valueint;
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp"); cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) { if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
dError("failed to read mnode mgmtIpList.json, nodeName not found"); dError("failed to read mnode mgmtIpList.json, nodeName not found");
goto PARSE_OVER; goto PARSE_OVER;
} }
strncpy(tsMnodeInfos.nodeInfos[i].nodeEp, nodeEp->valuestring, TSDB_EP_LEN); strncpy(tsDMnodeInfos.nodeInfos[i].nodeEp, nodeEp->valuestring, TSDB_EP_LEN);
} }
ret = true; ret = true;
dPrint("read mnode iplist successed, numOfIps:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse); dPrint("read mnode iplist successed, numOfIps:%d inUse:%d", tsDMnodeInfos.nodeNum, tsDMnodeInfos.inUse);
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
dPrint("mnode:%d, %s", tsMnodeInfos.nodeInfos[i].nodeId, tsMnodeInfos.nodeInfos[i].nodeEp); dPrint("mnode:%d, %s", tsDMnodeInfos.nodeInfos[i].nodeId, tsDMnodeInfos.nodeInfos[i].nodeEp);
} }
PARSE_OVER: PARSE_OVER:
...@@ -442,13 +458,13 @@ static void dnodeSaveMnodeInfos() { ...@@ -442,13 +458,13 @@ static void dnodeSaveMnodeInfos() {
char * content = calloc(1, maxLen + 1); char * content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"inUse\": %d,\n", tsMnodeInfos.inUse); len += snprintf(content + len, maxLen - len, " \"inUse\": %d,\n", tsDMnodeInfos.inUse);
len += snprintf(content + len, maxLen - len, " \"nodeNum\": %d,\n", tsMnodeInfos.nodeNum); len += snprintf(content + len, maxLen - len, " \"nodeNum\": %d,\n", tsDMnodeInfos.nodeNum);
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n"); len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsMnodeInfos.nodeInfos[i].nodeId); len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsDMnodeInfos.nodeInfos[i].nodeId);
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsMnodeInfos.nodeInfos[i].nodeEp); len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsDMnodeInfos.nodeInfos[i].nodeEp);
if (i < tsMnodeInfos.nodeNum -1) { if (i < tsDMnodeInfos.nodeNum -1) {
len += snprintf(content + len, maxLen - len, " },{\n"); len += snprintf(content + len, maxLen - len, " },{\n");
} else { } else {
len += snprintf(content + len, maxLen - len, " }]\n"); len += snprintf(content + len, maxLen - len, " }]\n");
...@@ -464,11 +480,11 @@ static void dnodeSaveMnodeInfos() { ...@@ -464,11 +480,11 @@ static void dnodeSaveMnodeInfos() {
} }
char *dnodeGetMnodeMasterEp() { char *dnodeGetMnodeMasterEp() {
return tsMnodeInfos.nodeInfos[tsMnodeIpSet.inUse].nodeEp; return tsDMnodeInfos.nodeInfos[tsDMnodeIpSetForPeer.inUse].nodeEp;
} }
void* dnodeGetMnodeInfos() { void* dnodeGetMnodeInfos() {
return &tsMnodeInfos; return &tsDMnodeInfos;
} }
static void dnodeSendStatusMsg(void *handle, void *tmrId) { static void dnodeSendStatusMsg(void *handle, void *tmrId) {
...@@ -511,7 +527,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { ...@@ -511,7 +527,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
.msgType = TSDB_MSG_TYPE_DM_STATUS .msgType = TSDB_MSG_TYPE_DM_STATUS
}; };
dnodeSendMsgToDnode(&tsMnodeIpSet, &rpcMsg); dnodeSendMsgToDnode(&tsDMnodeIpSetForPeer, &rpcMsg);
} }
static bool dnodeReadDnodeCfg() { static bool dnodeReadDnodeCfg() {
...@@ -593,14 +609,18 @@ int32_t dnodeGetDnodeId() { ...@@ -593,14 +609,18 @@ int32_t dnodeGetDnodeId() {
return tsDnodeCfg.dnodeId; return tsDnodeCfg.dnodeId;
} }
void dnodeSendRediretMsg(SRpcMsg *rpcMsg) { void dnodeSendRedirectMsg(int32_t msgType, void *thandle, bool forShell) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
rpcGetConnInfo(rpcMsg->handle, &connInfo); rpcGetConnInfo(thandle, &connInfo);
SRpcIpSet ipSet = {0}; SRpcIpSet ipSet = {0};
dnodeGetMnodeDnodeIpSet(&ipSet); if (forShell) {
dnodeGetMnodeIpSetForShell(&ipSet);
dTrace("msg:%s will be redirected, dnodeIp:%s user:%s, numOfIps:%d inUse:%d", taosMsg[rpcMsg->msgType], } else {
dnodeGetMnodeIpSetForPeer(&ipSet);
}
dTrace("msg:%s will be redirected, dnodeIp:%s user:%s, numOfIps:%d inUse:%d", taosMsg[msgType],
taosIpStr(connInfo.clientIp), connInfo.user, ipSet.numOfIps, ipSet.inUse); taosIpStr(connInfo.clientIp), connInfo.user, ipSet.numOfIps, ipSet.inUse);
for (int i = 0; i < ipSet.numOfIps; ++i) { for (int i = 0; i < ipSet.numOfIps; ++i) {
...@@ -608,5 +628,5 @@ void dnodeSendRediretMsg(SRpcMsg *rpcMsg) { ...@@ -608,5 +628,5 @@ void dnodeSendRediretMsg(SRpcMsg *rpcMsg) {
ipSet.port[i] = htons(ipSet.port[i]); ipSet.port[i] = htons(ipSet.port[i]);
} }
rpcSendRedirectRsp(rpcMsg->handle, &ipSet); rpcSendRedirectRsp(thandle, &ipSet);
} }
\ No newline at end of file
...@@ -48,9 +48,9 @@ static void dnodeUnSetModuleStatus(int32_t module) { ...@@ -48,9 +48,9 @@ static void dnodeUnSetModuleStatus(int32_t module) {
static void dnodeAllocModules() { static void dnodeAllocModules() {
tsModule[TSDB_MOD_MGMT].enable = false; tsModule[TSDB_MOD_MGMT].enable = false;
tsModule[TSDB_MOD_MGMT].name = "mgmt"; tsModule[TSDB_MOD_MGMT].name = "mgmt";
tsModule[TSDB_MOD_MGMT].initFp = mgmtInitSystem; tsModule[TSDB_MOD_MGMT].initFp = mnodeInitSystem;
tsModule[TSDB_MOD_MGMT].cleanUpFp = mgmtCleanUpSystem; tsModule[TSDB_MOD_MGMT].cleanUpFp = mnodeCleanupSystem;
tsModule[TSDB_MOD_MGMT].startFp = mgmtStartSystem; tsModule[TSDB_MOD_MGMT].startFp = mnodeStartSystem;
tsModule[TSDB_MOD_MGMT].stopFp = mgmtStopSystem; tsModule[TSDB_MOD_MGMT].stopFp = mgmtStopSystem;
tsModule[TSDB_MOD_HTTP].enable = (tsEnableHttpModule == 1); tsModule[TSDB_MOD_HTTP].enable = (tsEnableHttpModule == 1);
......
...@@ -23,15 +23,15 @@ ...@@ -23,15 +23,15 @@
#include "taosmsg.h" #include "taosmsg.h"
#include "tglobal.h" #include "tglobal.h"
#include "trpc.h" #include "trpc.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeVWrite.h" #include "dnodeVWrite.h"
#include "dnodeMRead.h" #include "dnodeMRead.h"
#include "dnodeMWrite.h" #include "dnodeMWrite.h"
#include "mnode.h"
extern void dnodeUpdateIpSet(SRpcIpSet *pIpSet); extern void dnodeUpdateMnodeIpSetForPeer(SRpcIpSet *pIpSet);
static void (*dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *); static void (*dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *); static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *);
static void (*dnodeProcessRspMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *rpcMsg); static void (*dnodeProcessRspMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *rpcMsg);
...@@ -148,9 +148,10 @@ void dnodeCleanupClient() { ...@@ -148,9 +148,10 @@ void dnodeCleanupClient() {
} }
static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
if (dnodeProcessRspMsgFp[pMsg->msgType]) { 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); (*dnodeProcessRspMsgFp[pMsg->msgType])(pMsg);
} else { } else {
dError("RPC %p, msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]); dError("RPC %p, msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]);
...@@ -169,6 +170,6 @@ void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg) { ...@@ -169,6 +170,6 @@ void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg) {
void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) { void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
SRpcIpSet ipSet = {0}; SRpcIpSet ipSet = {0};
dnodeGetMnodeDnodeIpSet(&ipSet, false); dnodeGetMnodeIpSetForPeer(&ipSet);
rpcSendRecv(tsDnodeClientRpc, &ipSet, rpcMsg, rpcRsp); rpcSendRecv(tsDnodeClientRpc, &ipSet, rpcMsg, rpcRsp);
} }
...@@ -37,8 +37,6 @@ static void * tsDnodeShellRpc = NULL; ...@@ -37,8 +37,6 @@ static void * tsDnodeShellRpc = NULL;
static int32_t tsDnodeQueryReqNum = 0; static int32_t tsDnodeQueryReqNum = 0;
static int32_t tsDnodeSubmitReqNum = 0; static int32_t tsDnodeSubmitReqNum = 0;
void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg);
int32_t dnodeInitShell() { int32_t dnodeInitShell() {
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_SUBMIT] = dnodeDispatchToVnodeWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_SUBMIT] = dnodeDispatchToVnodeWriteQueue;
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_QUERY] = dnodeDispatchToVnodeReadQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_QUERY] = dnodeDispatchToVnodeReadQueue;
...@@ -141,7 +139,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { ...@@ -141,7 +139,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
} }
static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
int code = mgmtRetriveAuth(user, spi, encrypt, secret, ckey); int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
if (code != TSDB_CODE_NOT_READY) return code; if (code != TSDB_CODE_NOT_READY) return code;
SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg));
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "twal.h" #include "twal.h"
#include "tglobal.h" #include "tglobal.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
#include "dnodeVRead.h" #include "dnodeVRead.h"
#include "vnode.h" #include "vnode.h"
...@@ -93,7 +93,7 @@ void dnodeCleanupVnodeRead() { ...@@ -93,7 +93,7 @@ void dnodeCleanupVnodeRead() {
} }
void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) { void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) {
int32_t queuedMsgNum = 0; int32_t mnodeMsgNum = 0;
int32_t leftLen = pMsg->contLen; int32_t leftLen = pMsg->contLen;
char *pCont = (char *) pMsg->pCont; char *pCont = (char *) pMsg->pCont;
void *pVnode; void *pVnode;
...@@ -125,12 +125,12 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) { ...@@ -125,12 +125,12 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) {
// next vnode // next vnode
leftLen -= pHead->contLen; leftLen -= pHead->contLen;
pCont -= pHead->contLen; pCont -= pHead->contLen;
queuedMsgNum++; mnodeMsgNum++;
taosWriteQitem(queue, TAOS_QTYPE_RPC, pRead); taosWriteQitem(queue, TAOS_QTYPE_RPC, pRead);
} }
if (queuedMsgNum == 0) { if (mnodeMsgNum == 0) {
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pMsg->handle, .handle = pMsg->handle,
.pCont = NULL, .pCont = NULL,
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "tdataformat.h" #include "tdataformat.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeVWrite.h" #include "dnodeVWrite.h"
#include "dnodeVMgmt.h" #include "dnodeMgmt.h"
typedef struct { typedef struct {
taos_qall qall; taos_qall qall;
......
...@@ -43,16 +43,21 @@ void *dnodeAllocateRqueue(void *pVnode); ...@@ -43,16 +43,21 @@ void *dnodeAllocateRqueue(void *pVnode);
void dnodeFreeRqueue(void *rqueue); void dnodeFreeRqueue(void *rqueue);
void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code); void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code);
bool dnodeIsFirstDeploy(); bool dnodeIsFirstDeploy();
char *dnodeGetMnodeMasterEp(); char * dnodeGetMnodeMasterEp();
void dnodeGetMnodeDnodeIpSet(void *ipSet, bool encode); void dnodeGetMnodeIpSetForPeer(void *ipSet);
void * dnodeGetMnodeInfos(); void dnodeGetMnodeIpSetForShell(void *ipSet);
int32_t dnodeGetDnodeId(); void * dnodeGetMnodeInfos();
int32_t dnodeGetDnodeId();
void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
void dnodeAddServerMsgHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)); void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg); void dnodeAddServerMsgHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp); 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 #ifdef __cplusplus
} }
......
...@@ -13,44 +13,62 @@ ...@@ -13,44 +13,62 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_H #ifndef TDENGINE_MNODE_H
#define TDENGINE_MGMT_H #define TDENGINE_MNODE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
struct SAcctObj;
struct SDnodeObj;
struct SUserObj;
struct SDbObj;
struct SVgObj;
struct STableObj;
struct SRpcMsg;
typedef struct { typedef struct {
int len; int len;
int code;
void *rsp; void *rsp;
} SMnodeRsp; } SMnodeRsp;
typedef struct { typedef struct SMnodeMsg {
SRpcMsg rpcMsg;
SMnodeRsp rpcRsp; 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;
SMnodeMsg *mnodeCreateMsg(SRpcMsg *rpcMsg); void mnodeCreateMsg(SMnodeMsg *pMsg, struct SRpcMsg *rpcMsg);
bool mnodeInitMsg(SMnodeMsg *pMsg); int32_t mnodeInitMsg(SMnodeMsg *pMsg);
void mnodeRleaseMsg(SMnodeMsg *pMsg); void mnodeCleanupMsg(SMnodeMsg *pMsg);
int32_t mgmtInitSystem(); int32_t mnodeInitSystem();
int32_t mgmtStartSystem(); int32_t mnodeStartSystem();
void mgmtCleanUpSystem(); void mnodeCleanupSystem();
void mgmtStopSystem(); void mgmtStopSystem();
void sdbUpdateSync(); void sdbUpdateSync();
void* mnodeGetRqueue(void *);
void* mnodeGetWqueue(int32_t vgId);
bool mnodeIsRunning(); bool mnodeIsRunning();
int32_t mnodeProcessRead(SMnodeMsg *pMsg); int32_t mnodeProcessRead(SMnodeMsg *pMsg);
int32_t mnodeProcessWrite(SMnodeMsg *pMsg); int32_t mnodeProcessWrite(SMnodeMsg *pMsg);
int32_t mnodeProcessMgmt(SMnodeMsg *pMsg); int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg);
void mnodeProcessPeerRsp(struct SRpcMsg *pMsg);
int32_t mgmtRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey); int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey);
void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg);
void mgmtProcessReqMsgFromDnode(SRpcMsg *rpcMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -121,23 +121,23 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY14, "dummy14" ) ...@@ -121,23 +121,23 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY14, "dummy14" )
#define TSDB_IE_TYPE_DNODE_STATE 7 #define TSDB_IE_TYPE_DNODE_STATE 7
enum _mgmt_table { enum _mgmt_table {
TSDB_MNODE_TABLE_ACCT, TSDB_MGMT_TABLE_ACCT,
TSDB_MNODE_TABLE_USER, TSDB_MGMT_TABLE_USER,
TSDB_MNODE_TABLE_DB, TSDB_MGMT_TABLE_DB,
TSDB_MNODE_TABLE_TABLE, TSDB_MGMT_TABLE_TABLE,
TSDB_MNODE_TABLE_DNODE, TSDB_MGMT_TABLE_DNODE,
TSDB_MNODE_TABLE_MNODE, TSDB_MGMT_TABLE_MNODE,
TSDB_MNODE_TABLE_VGROUP, TSDB_MGMT_TABLE_VGROUP,
TSDB_MNODE_TABLE_METRIC, TSDB_MGMT_TABLE_METRIC,
TSDB_MNODE_TABLE_MODULE, TSDB_MGMT_TABLE_MODULE,
TSDB_MNODE_TABLE_QUERIES, TSDB_MGMT_TABLE_QUERIES,
TSDB_MNODE_TABLE_STREAMS, TSDB_MGMT_TABLE_STREAMS,
TSDB_MNODE_TABLE_CONFIGS, TSDB_MGMT_TABLE_CONFIGS,
TSDB_MNODE_TABLE_CONNS, TSDB_MGMT_TABLE_CONNS,
TSDB_MNODE_TABLE_SCORES, TSDB_MGMT_TABLE_SCORES,
TSDB_MNODE_TABLE_GRANTS, TSDB_MGMT_TABLE_GRANTS,
TSDB_MNODE_TABLE_VNODES, TSDB_MGMT_TABLE_VNODES,
TSDB_MNODE_TABLE_MAX, TSDB_MGMT_TABLE_MAX,
}; };
#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1 #define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1
......
...@@ -26,7 +26,7 @@ struct SDnodeObj; ...@@ -26,7 +26,7 @@ struct SDnodeObj;
int32_t balanceInit(); int32_t balanceInit();
void balanceCleanUp(); void balanceCleanUp();
void balanceNotify(); void balanceNotify();
void balanceUpdateMgmt(); void balanceUpdateMnode();
void balanceReset(); void balanceReset();
int32_t balanceAllocVnodes(struct SVgObj *pVgroup); int32_t balanceAllocVnodes(struct SVgObj *pVgroup);
int32_t balanceDropDnode(struct SDnodeObj *pDnode); int32_t balanceDropDnode(struct SDnodeObj *pDnode);
......
...@@ -28,21 +28,21 @@ extern "C" { ...@@ -28,21 +28,21 @@ extern "C" {
extern int tsRpcHeadSize; extern int tsRpcHeadSize;
typedef struct { typedef struct SRpcIpSet {
int8_t inUse; int8_t inUse;
int8_t numOfIps; int8_t numOfIps;
uint16_t port[TSDB_MAX_REPLICA]; uint16_t port[TSDB_MAX_REPLICA];
char fqdn[TSDB_MAX_REPLICA][TSDB_FQDN_LEN]; char fqdn[TSDB_MAX_REPLICA][TSDB_FQDN_LEN];
} SRpcIpSet; } SRpcIpSet;
typedef struct { typedef struct SRpcConnInfo {
uint32_t clientIp; uint32_t clientIp;
uint16_t clientPort; uint16_t clientPort;
uint32_t serverIp; uint32_t serverIp;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
} SRpcConnInfo; } SRpcConnInfo;
typedef struct { typedef struct SRpcMsg {
uint8_t msgType; uint8_t msgType;
void *pCont; void *pCont;
int contLen; int contLen;
...@@ -51,7 +51,7 @@ typedef struct { ...@@ -51,7 +51,7 @@ typedef struct {
void *ahandle; //app handle set by client, for debug purpose void *ahandle; //app handle set by client, for debug purpose
} SRpcMsg; } SRpcMsg;
typedef struct { typedef struct SRpcInit {
uint16_t localPort; // local port uint16_t localPort; // local port
char *label; // for debug purpose char *label; // for debug purpose
int numOfThreads; // number of threads to handle connections int numOfThreads; // number of threads to handle connections
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_ACCT_H #ifndef TDENGINE_MNODE_ACCT_H
#define TDENGINE_MGMT_ACCT_H #define TDENGINE_MNODE_ACCT_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -22,16 +22,16 @@ extern "C" { ...@@ -22,16 +22,16 @@ extern "C" {
#include "tacct.h" #include "tacct.h"
int32_t mgmtInitAccts(); int32_t mnodeInitAccts();
void mgmtCleanUpAccts(); void mnodeCleanupAccts();
void * mgmtGetAcct(char *acctName); void * mnodeGetAcct(char *acctName);
void * mgmtGetNextAcct(void *pIter, SAcctObj **pAcct); void * mnodeGetNextAcct(void *pIter, SAcctObj **pAcct);
void mgmtIncAcctRef(SAcctObj *pAcct); void mnodeIncAcctRef(SAcctObj *pAcct);
void mgmtDecAcctRef(SAcctObj *pAcct); void mnodeDecAcctRef(SAcctObj *pAcct);
void mgmtAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb); void mnodeAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb);
void mgmtDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb); void mnodeDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb);
void mgmtAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser); void mnodeAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser);
void mgmtDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser); void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_DB_H #ifndef TDENGINE_MNODE_DB_H
#define TDENGINE_MGMT_DB_H #define TDENGINE_MNODE_DB_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -28,26 +28,26 @@ enum _TSDB_DB_STATUS { ...@@ -28,26 +28,26 @@ enum _TSDB_DB_STATUS {
}; };
// api // api
int32_t mgmtInitDbs(); int32_t mnodeInitDbs();
void mgmtCleanUpDbs(); void mnodeCleanupDbs();
SDbObj *mgmtGetDb(char *db); SDbObj *mnodeGetDb(char *db);
SDbObj *mgmtGetDbByTableId(char *db); SDbObj *mnodeGetDbByTableId(char *db);
void * mgmtGetNextDb(void *pIter, SDbObj **pDb); void * mnodeGetNextDb(void *pIter, SDbObj **pDb);
void mgmtIncDbRef(SDbObj *pDb); void mnodeIncDbRef(SDbObj *pDb);
void mgmtDecDbRef(SDbObj *pDb); void mnodeDecDbRef(SDbObj *pDb);
bool mgmtCheckIsMonitorDB(char *db, char *monitordb); bool mnodeCheckIsMonitorDB(char *db, char *monitordb);
void mgmtDropAllDbs(SAcctObj *pAcct); void mnodeDropAllDbs(SAcctObj *pAcct);
// util func // util func
void mgmtAddSuperTableIntoDb(SDbObj *pDb); void mnodeAddSuperTableIntoDb(SDbObj *pDb);
void mgmtRemoveSuperTableFromDb(SDbObj *pDb); void mnodeRemoveSuperTableFromDb(SDbObj *pDb);
void mgmtAddTableIntoDb(SDbObj *pDb); void mnodeAddTableIntoDb(SDbObj *pDb);
void mgmtRemoveTableFromDb(SDbObj *pDb); void mnodeRemoveTableFromDb(SDbObj *pDb);
void mgmtAddVgroupIntoDb(SVgObj *pVgroup); void mnodeAddVgroupIntoDb(SVgObj *pVgroup);
void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup); void mnodeAddVgroupIntoDbTail(SVgObj *pVgroup);
void mgmtRemoveVgroupFromDb(SVgObj *pVgroup); void mnodeRemoveVgroupFromDb(SVgObj *pVgroup);
void mgmtMoveVgroupToTail(SVgObj *pVgroup); void mnodeMoveVgroupToTail(SVgObj *pVgroup);
void mgmtMoveVgroupToHead(SVgObj *pVgroup); void mnodeMoveVgroupToHead(SVgObj *pVgroup);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_DEF_H #ifndef TDENGINE_MNODE_DEF_H
#define TDENGINE_MGMT_DEF_H #define TDENGINE_MNODE_DEF_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -65,7 +65,7 @@ typedef struct SMnodeObj { ...@@ -65,7 +65,7 @@ typedef struct SMnodeObj {
int8_t role; int8_t role;
} SMnodeObj; } SMnodeObj;
typedef struct { typedef struct STableObj {
char *tableId; char *tableId;
int8_t type; int8_t type;
} STableObj; } STableObj;
...@@ -233,26 +233,6 @@ typedef struct { ...@@ -233,26 +233,6 @@ typedef struct {
char payload[]; char payload[];
} SShowObj; } 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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_CLUSTER_H #ifndef TDENGINE_MNODE_DNODE_H
#define TDENGINE_CLUSTER_H #define TDENGINE_MNODE_DNODE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -27,21 +27,21 @@ typedef enum { ...@@ -27,21 +27,21 @@ typedef enum {
TAOS_DN_STATUS_READY TAOS_DN_STATUS_READY
} EDnodeStatus; } EDnodeStatus;
int32_t mgmtInitDnodes(); int32_t mnodeInitDnodes();
void mgmtCleanupDnodes(); void mgmtCleanupDnodes();
char* mgmtGetDnodeStatusStr(int32_t dnodeStatus); char* mnodeGetDnodeStatusStr(int32_t dnodeStatus);
void mgmtMonitorDnodeModule(); void mgmtMonitorDnodeModule();
int32_t mgmtGetDnodesNum(); int32_t mnodeGetDnodesNum();
int32_t mgmtGetOnlinDnodesNum(); int32_t mnodeGetOnlinDnodesNum();
void * mgmtGetNextDnode(void *pIter, SDnodeObj **pDnode); void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode);
void mgmtIncDnodeRef(SDnodeObj *pDnode); void mnodeIncDnodeRef(SDnodeObj *pDnode);
void mgmtDecDnodeRef(SDnodeObj *pDnode); void mnodeDecDnodeRef(SDnodeObj *pDnode);
void * mgmtGetDnode(int32_t dnodeId); void * mnodeGetDnode(int32_t dnodeId);
void * mgmtGetDnodeByEp(char *ep); void * mnodeGetDnodeByEp(char *ep);
void mgmtUpdateDnode(SDnodeObj *pDnode); void mnodeUpdateDnode(SDnodeObj *pDnode);
int32_t mgmtDropDnode(SDnodeObj *pDnode); int32_t mnodeDropDnode(SDnodeObj *pDnode);
extern int32_t tsAccessSquence; extern int32_t tsAccessSquence;
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_LOG_H #ifndef TDENGINE_MNODE_LOG_H
#define TDENGINE_MGMT_LOG_H #define TDENGINE_MNODE_LOG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_MNODE_H #ifndef TDENGINE_MNODE_MNODE_H
#define TDENGINE_MGMT_MNODE_H #define TDENGINE_MNODE_MNODE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -28,25 +28,25 @@ typedef enum { ...@@ -28,25 +28,25 @@ typedef enum {
TAOS_MN_STATUS_READY TAOS_MN_STATUS_READY
} EMnodeStatus; } EMnodeStatus;
int32_t mgmtInitMnodes(); int32_t mnodeInitMnodes();
void mgmtCleanupMnodes(); void mgmtCleanupMnodes();
int32_t mgmtAddMnode(int32_t dnodeId); int32_t mnodeAddMnode(int32_t dnodeId);
int32_t mgmtDropMnode(int32_t dnodeId); int32_t mnodeDropMnode(int32_t dnodeId);
void mgmtDropMnodeLocal(int32_t dnodeId); void mnodeDropMnodeLocal(int32_t dnodeId);
void * mgmtGetMnode(int32_t mnodeId); void * mnodeGetMnode(int32_t mnodeId);
int32_t mgmtGetMnodesNum(); int32_t mnodeGetMnodesNum();
void * mgmtGetNextMnode(void *pIter, struct SMnodeObj **pMnode); void * mnodeGetNextMnode(void *pIter, struct SMnodeObj **pMnode);
void mgmtIncMnodeRef(struct SMnodeObj *pMnode); void mnodeIncMnodeRef(struct SMnodeObj *pMnode);
void mgmtDecMnodeRef(struct SMnodeObj *pMnode); void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
char * mgmtGetMnodeRoleStr(); char * mnodeGetMnodeRoleStr();
void mgmtGetMnodeIpSetForPeer(SRpcIpSet *ipSet); void mnodeGetMnodeIpSetForPeer(SRpcIpSet *ipSet);
void mgmtGetMnodeIpSetForShell(SRpcIpSet *ipSet); void mnodeGetMnodeIpSetForShell(SRpcIpSet *ipSet);
void mgmtGetMnodeInfos(void *mnodes); void mnodeGetMnodeInfos(void *mnodes);
void mgmtUpdateMnodeIpSet(); void mnodeUpdateMnodeIpSet();
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/*
* 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
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_PROFILE_H #ifndef TDENGINE_MNODE_PROFILE_H
#define TDENGINE_MGMT_PROFILE_H #define TDENGINE_MNODE_PROFILE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h" #include "mnodeDef.h"
int32_t mgmtInitProfile(); int32_t mnodeInitProfile();
void mgmtCleanUpProfile(); void mnodeCleanupProfile();
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,15 +13,16 @@ ...@@ -13,15 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_DSERVER_H #ifndef TDENGINE_MNODE_READ_H
#define TDENGINE_MGMT_DSERVER_H #define TDENGINE_MNODE_READ_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h"
int32_t mnodeInitMgmt(); void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
void mgmtCleanupMgmt(); int32_t mnodeProcessRead(SMnodeMsg *pMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,35 +13,22 @@ ...@@ -13,35 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_SHELL_H #ifndef TDENGINE_MNODE_SHELL_H
#define TDENGINE_MGMT_SHELL_H #define TDENGINE_MNODE_SHELL_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h" #include "mnodeDef.h"
int32_t mgmtInitShell(); int32_t mnodeInitShow();
void mgmtCleanUpShell(); void mnodeCleanUpShow();
void mgmtAddShellMsgHandle(uint8_t msgType, void (*fp)(SMnodeMsg *queuedMsg));
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn); typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp); void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp);
void mnodeAddShowRetrieveHandle(uint8_t showType, SShowRetrieveFp 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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -22,16 +22,16 @@ extern "C" { ...@@ -22,16 +22,16 @@ extern "C" {
#include "mnodeDef.h" #include "mnodeDef.h"
int32_t mgmtInitTables(); int32_t mnodeInitTables();
void mgmtCleanUpTables(); void mnodeCleanupTables();
void * mgmtGetTable(char *tableId); void * mnodeGetTable(char *tableId);
void mgmtIncTableRef(void *pTable); void mnodeIncTableRef(void *pTable);
void mgmtDecTableRef(void *pTable); void mnodeDecTableRef(void *pTable);
void * mgmtGetNextChildTable(void *pIter, SChildTableObj **pTable); void * mnodeGetNextChildTable(void *pIter, SChildTableObj **pTable);
void * mgmtGetNextSuperTable(void *pIter, SSuperTableObj **pTable); void * mnodeGetNextSuperTable(void *pIter, SSuperTableObj **pTable);
void mgmtDropAllChildTables(SDbObj *pDropDb); void mnodeDropAllChildTables(SDbObj *pDropDb);
void mgmtDropAllSuperTables(SDbObj *pDropDb); void mnodeDropAllSuperTables(SDbObj *pDropDb);
void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup); void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,23 +13,23 @@ ...@@ -13,23 +13,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_USER_H #ifndef TDENGINE_MNODE_USER_H
#define TDENGINE_MGMT_USER_H #define TDENGINE_MNODE_USER_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h" #include "mnodeDef.h"
int32_t mgmtInitUsers(); int32_t mnodeInitUsers();
void mgmtCleanUpUsers(); void mnodeCleanupUsers();
SUserObj *mgmtGetUser(char *name); SUserObj *mnodeGetUser(char *name);
void * mgmtGetNextUser(void *pIter, SUserObj **pUser); void * mnodeGetNextUser(void *pIter, SUserObj **pUser);
void mgmtIncUserRef(SUserObj *pUser); void mnodeIncUserRef(SUserObj *pUser);
void mgmtDecUserRef(SUserObj *pUser); void mnodeDecUserRef(SUserObj *pUser);
SUserObj *mgmtGetUserFromConn(void *pConn); SUserObj *mnodeGetUserFromConn(void *pConn);
int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass);
void mgmtDropAllUsers(SAcctObj *pAcct); void mnodeDropAllUsers(SAcctObj *pAcct);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,41 +13,41 @@ ...@@ -13,41 +13,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_VGROUP_H #ifndef TDENGINE_MNODE_VGROUP_H
#define TDENGINE_MGMT_VGROUP_H #define TDENGINE_MNODE_VGROUP_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h" struct SMnodeMsg;
int32_t mgmtInitVgroups(); int32_t mnodeInitVgroups();
void mgmtCleanUpVgroups(); void mnodeCleanupVgroups();
SVgObj *mgmtGetVgroup(int32_t vgId); SVgObj *mnodeGetVgroup(int32_t vgId);
void mgmtIncVgroupRef(SVgObj *pVgroup); void mnodeIncVgroupRef(SVgObj *pVgroup);
void mgmtDecVgroupRef(SVgObj *pVgroup); void mnodeDecVgroupRef(SVgObj *pVgroup);
void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg); void mnodeDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg);
void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode); void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode);
void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb); void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb);
void * mgmtGetNextVgroup(void *pIter, SVgObj **pVgroup); void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup);
void mgmtUpdateVgroup(SVgObj *pVgroup); void mnodeUpdateVgroup(SVgObj *pVgroup);
void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *dnodeId, SVnodeLoad *pVload); void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *dnodeId, SVnodeLoad *pVload);
void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb); int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg, SDbObj *pDb);
void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle); void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
void mgmtAlterVgroup(SVgObj *pVgroup, void *ahandle); void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle);
SVgObj *mgmtGetAvailableVgroup(SDbObj *pDb); SVgObj *mnodeGetAvailableVgroup(SDbObj *pDb);
void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable); void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable); void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle); void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle);
void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle); void mnodeSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle);
void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle); void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup); SRpcIpSet mnodeGetIpSetFromVgroup(SVgObj *pVgroup);
SRpcIpSet mgmtGetIpSetFromIp(char *ep); SRpcIpSet mnodeGetIpSetFromIp(char *ep);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,17 +13,16 @@ ...@@ -13,17 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMT_DCLIENT_H #ifndef TDENGINE_MNODE_WRITE_H
#define TDENGINE_MGMT_DCLIENT_H #define TDENGINE_MNODE_WRITE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mnodeDef.h"
int32_t mgmtInitDClient(); void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
void mgmtCleanupDClient(); int32_t mnodeProcessRead(SMnodeMsg *pMsg);
void mgmtAddDClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
void mgmtSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "ttime.h" #include "ttime.h"
#include "tutil.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
...@@ -28,48 +27,48 @@ ...@@ -28,48 +27,48 @@
void * tsAcctSdb = NULL; void * tsAcctSdb = NULL;
static int32_t tsAcctUpdateSize; static int32_t tsAcctUpdateSize;
static void mgmtCreateRootAcct(); static void mnodeCreateRootAcct();
static int32_t mgmtActionAcctDestroy(SSdbOper *pOper) { static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
pthread_mutex_destroy(&pAcct->mutex); pthread_mutex_destroy(&pAcct->mutex);
tfree(pOper->pObj); tfree(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtAcctActionInsert(SSdbOper *pOper) { static int32_t mnodeAcctActionInsert(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo));
pthread_mutex_init(&pAcct->mutex, NULL); pthread_mutex_init(&pAcct->mutex, NULL);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtActionAcctDelete(SSdbOper *pOper) { static int32_t mnodeAcctActionDelete(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
mgmtDropAllUsers(pAcct); mnodeDropAllUsers(pAcct);
mgmtDropAllDbs(pAcct); mnodeDropAllDbs(pAcct);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtActionAcctUpdate(SSdbOper *pOper) { static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
SAcctObj *pSaved = mgmtGetAcct(pAcct->user); SAcctObj *pSaved = mnodeGetAcct(pAcct->user);
if (pAcct != pSaved) { if (pAcct != pSaved) {
memcpy(pSaved, pAcct, tsAcctUpdateSize); memcpy(pSaved, pAcct, tsAcctUpdateSize);
free(pAcct); free(pAcct);
} }
mgmtDecAcctRef(pSaved); mnodeDecAcctRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtActionActionEncode(SSdbOper *pOper) { static int32_t mnodeActionActionEncode(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
memcpy(pOper->rowData, pAcct, tsAcctUpdateSize); memcpy(pOper->rowData, pAcct, tsAcctUpdateSize);
pOper->rowSize = tsAcctUpdateSize; pOper->rowSize = tsAcctUpdateSize;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtActionAcctDecode(SSdbOper *pOper) { static int32_t mnodeAcctActionDecode(SSdbOper *pOper) {
SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj));
if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -78,16 +77,16 @@ static int32_t mgmtActionAcctDecode(SSdbOper *pOper) { ...@@ -78,16 +77,16 @@ static int32_t mgmtActionAcctDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtActionAcctRestored() { static int32_t mnodeAcctActionRestored() {
if (dnodeIsFirstDeploy()) { if (dnodeIsFirstDeploy()) {
mgmtCreateRootAcct(); mnodeCreateRootAcct();
} }
acctInit(); acctInit();
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitAccts() { int32_t mnodeInitAccts() {
SAcctObj tObj; SAcctObj tObj;
tsAcctUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsAcctUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -98,13 +97,13 @@ int32_t mgmtInitAccts() { ...@@ -98,13 +97,13 @@ int32_t mgmtInitAccts() {
.maxRowSize = tsAcctUpdateSize, .maxRowSize = tsAcctUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_STRING, .keyType = SDB_KEY_STRING,
.insertFp = mgmtAcctActionInsert, .insertFp = mnodeAcctActionInsert,
.deleteFp = mgmtActionAcctDelete, .deleteFp = mnodeAcctActionDelete,
.updateFp = mgmtActionAcctUpdate, .updateFp = mnodeAcctActionUpdate,
.encodeFp = mgmtActionActionEncode, .encodeFp = mnodeActionActionEncode,
.decodeFp = mgmtActionAcctDecode, .decodeFp = mnodeAcctActionDecode,
.destroyFp = mgmtActionAcctDestroy, .destroyFp = mnodeAcctActionDestroy,
.restoredFp = mgmtActionAcctRestored .restoredFp = mnodeAcctActionRestored
}; };
tsAcctSdb = sdbOpenTable(&tableDesc); tsAcctSdb = sdbOpenTable(&tableDesc);
...@@ -117,52 +116,52 @@ int32_t mgmtInitAccts() { ...@@ -117,52 +116,52 @@ int32_t mgmtInitAccts() {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void mgmtCleanUpAccts() { void mnodeCleanupAccts() {
sdbCloseTable(tsAcctSdb); sdbCloseTable(tsAcctSdb);
acctCleanUp(); acctCleanUp();
} }
void *mgmtGetAcct(char *name) { void *mnodeGetAcct(char *name) {
return sdbGetRow(tsAcctSdb, name); return sdbGetRow(tsAcctSdb, name);
} }
void *mgmtGetNextAcct(void *pIter, SAcctObj **pAcct) { void *mnodeGetNextAcct(void *pIter, SAcctObj **pAcct) {
return sdbFetchRow(tsAcctSdb, pIter, (void **)pAcct); return sdbFetchRow(tsAcctSdb, pIter, (void **)pAcct);
} }
void mgmtIncAcctRef(SAcctObj *pAcct) { void mnodeIncAcctRef(SAcctObj *pAcct) {
sdbIncRef(tsAcctSdb, pAcct); sdbIncRef(tsAcctSdb, pAcct);
} }
void mgmtDecAcctRef(SAcctObj *pAcct) { void mnodeDecAcctRef(SAcctObj *pAcct) {
sdbDecRef(tsAcctSdb, pAcct); sdbDecRef(tsAcctSdb, pAcct);
} }
void mgmtAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb) { void mnodeAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb) {
atomic_add_fetch_32(&pAcct->acctInfo.numOfDbs, 1); atomic_add_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
pDb->pAcct = pAcct; pDb->pAcct = pAcct;
mgmtIncAcctRef(pAcct); mnodeIncAcctRef(pAcct);
} }
void mgmtDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) { void mnodeDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) {
atomic_sub_fetch_32(&pAcct->acctInfo.numOfDbs, 1); atomic_sub_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
pDb->pAcct = NULL; pDb->pAcct = NULL;
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
void mgmtAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser) { void mnodeAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser) {
atomic_add_fetch_32(&pAcct->acctInfo.numOfUsers, 1); atomic_add_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
pUser->pAcct = pAcct; pUser->pAcct = pAcct;
mgmtIncAcctRef(pAcct); mnodeIncAcctRef(pAcct);
} }
void mgmtDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
atomic_sub_fetch_32(&pAcct->acctInfo.numOfUsers, 1); atomic_sub_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
pUser->pAcct = NULL; pUser->pAcct = NULL;
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
static void mgmtCreateRootAcct() { static void mnodeCreateRootAcct() {
int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb); int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb);
if (numOfAccts != 0) return; if (numOfAccts != 0) return;
......
...@@ -15,22 +15,18 @@ ...@@ -15,22 +15,18 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "trpc.h"
#include "tbalance.h"
#include "tglobal.h" #include "tglobal.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeMnode.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeVgroup.h"
#ifndef _SYNC #ifndef _SYNC
int32_t balanceInit() { return TSDB_CODE_SUCCESS; } int32_t balanceInit() { return TSDB_CODE_SUCCESS; }
void balanceCleanUp() {} void balanceCleanUp() {}
void balanceNotify() {} void balanceNotify() {}
void balanceUpdateMgmt() {} void balanceUpdateMnode() {}
void balanceReset() {} void balanceReset() {}
int32_t balanceAllocVnodes(SVgObj *pVgroup) { int32_t balanceAllocVnodes(SVgObj *pVgroup) {
...@@ -40,12 +36,12 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { ...@@ -40,12 +36,12 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
float vnodeUsage = 1000.0; float vnodeUsage = 1000.0;
while (1) { while (1) {
pIter = mgmtGetNextDnode(pIter, &pDnode); pIter = mnodeGetNextDnode(pIter, &pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
if (pDnode->totalVnodes > 0 && pDnode->openVnodes < pDnode->totalVnodes) { if (pDnode->totalVnodes > 0 && pDnode->openVnodes < pDnode->totalVnodes) {
float openVnodes = pDnode->openVnodes; float openVnodes = pDnode->openVnodes;
if (pDnode->isMgmt) openVnodes += tsMgmtEqualVnodeNum; if (pDnode->isMgmt) openVnodes += tsMnodeEqualVnodeNum;
float usage = openVnodes / pDnode->totalVnodes; float usage = openVnodes / pDnode->totalVnodes;
if (usage <= vnodeUsage) { if (usage <= vnodeUsage) {
...@@ -53,7 +49,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { ...@@ -53,7 +49,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
vnodeUsage = usage; vnodeUsage = usage;
} }
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tutil.h" #include "tutil.h"
#include "tgrant.h" #include "tgrant.h"
...@@ -24,15 +23,17 @@ ...@@ -24,15 +23,17 @@
#include "tname.h" #include "tname.h"
#include "tbalance.h" #include "tbalance.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "mnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mnodeDb.h" #include "mnodeDb.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeShell.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeWrite.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
...@@ -40,23 +41,23 @@ ...@@ -40,23 +41,23 @@
static void * tsDbSdb = NULL; static void * tsDbSdb = NULL;
static int32_t tsDbUpdateSize; static int32_t tsDbUpdateSize;
static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate); static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate);
static void mgmtDropDb(SMnodeMsg *newMsg); static int32_t mnodeDropDb(SMnodeMsg *newMsg);
static int32_t mgmtSetDbDropping(SDbObj *pDb); static int32_t mnodeSetDbDropping(SDbObj *pDb);
static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg);
static void mgmtProcessAlterDbMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg);
static void mgmtProcessDropDbMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg);
static int32_t mgmtDbActionDestroy(SSdbOper *pOper) { static int32_t mnodeDbActionDestroy(SSdbOper *pOper) {
tfree(pOper->pObj); tfree(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionInsert(SSdbOper *pOper) { static int32_t mnodeDbActionInsert(SSdbOper *pOper) {
SDbObj *pDb = pOper->pObj; SDbObj *pDb = pOper->pObj;
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
pDb->pHead = NULL; pDb->pHead = NULL;
pDb->pTail = NULL; pDb->pTail = NULL;
...@@ -65,8 +66,8 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) { ...@@ -65,8 +66,8 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
pDb->numOfSuperTables = 0; pDb->numOfSuperTables = 0;
if (pAcct != NULL) { if (pAcct != NULL) {
mgmtAddDbToAcct(pAcct, pDb); mnodeAddDbToAcct(pAcct, pDb);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
else { else {
mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct); mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct);
...@@ -76,39 +77,39 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) { ...@@ -76,39 +77,39 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionDelete(SSdbOper *pOper) { static int32_t mnodeDbActionDelete(SSdbOper *pOper) {
SDbObj *pDb = pOper->pObj; SDbObj *pDb = pOper->pObj;
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
mgmtDropDbFromAcct(pAcct, pDb); mnodeDropDbFromAcct(pAcct, pDb);
mgmtDropAllChildTables(pDb); mnodeDropAllChildTables(pDb);
mgmtDropAllSuperTables(pDb); mnodeDropAllSuperTables(pDb);
mgmtDropAllDbVgroups(pDb, false); mnodeDropAllDbVgroups(pDb, false);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionUpdate(SSdbOper *pOper) { static int32_t mnodeDbActionUpdate(SSdbOper *pOper) {
SDbObj *pDb = pOper->pObj; SDbObj *pDb = pOper->pObj;
SDbObj *pSaved = mgmtGetDb(pDb->name); SDbObj *pSaved = mnodeGetDb(pDb->name);
if (pDb != pSaved) { if (pDb != pSaved) {
memcpy(pSaved, pDb, pOper->rowSize); memcpy(pSaved, pDb, pOper->rowSize);
free(pDb); free(pDb);
} }
mgmtUpdateAllDbVgroups(pSaved); mnodeUpdateAllDbVgroups(pSaved);
mgmtDecDbRef(pSaved); mnodeDecDbRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionEncode(SSdbOper *pOper) { static int32_t mnodeDbActionEncode(SSdbOper *pOper) {
SDbObj *pDb = pOper->pObj; SDbObj *pDb = pOper->pObj;
memcpy(pOper->rowData, pDb, tsDbUpdateSize); memcpy(pOper->rowData, pDb, tsDbUpdateSize);
pOper->rowSize = tsDbUpdateSize; pOper->rowSize = tsDbUpdateSize;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionDecode(SSdbOper *pOper) { static int32_t mnodeDbActionDecode(SSdbOper *pOper) {
SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj));
if (pDb == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pDb == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -117,11 +118,11 @@ static int32_t mgmtDbActionDecode(SSdbOper *pOper) { ...@@ -117,11 +118,11 @@ static int32_t mgmtDbActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDbActionRestored() { static int32_t mnodeDbActionRestored() {
return 0; return 0;
} }
int32_t mgmtInitDbs() { int32_t mnodeInitDbs() {
SDbObj tObj; SDbObj tObj;
tsDbUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsDbUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -132,13 +133,13 @@ int32_t mgmtInitDbs() { ...@@ -132,13 +133,13 @@ int32_t mgmtInitDbs() {
.maxRowSize = tsDbUpdateSize, .maxRowSize = tsDbUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_STRING, .keyType = SDB_KEY_STRING,
.insertFp = mgmtDbActionInsert, .insertFp = mnodeDbActionInsert,
.deleteFp = mgmtDbActionDelete, .deleteFp = mnodeDbActionDelete,
.updateFp = mgmtDbActionUpdate, .updateFp = mnodeDbActionUpdate,
.encodeFp = mgmtDbActionEncode, .encodeFp = mnodeDbActionEncode,
.decodeFp = mgmtDbActionDecode, .decodeFp = mnodeDbActionDecode,
.destroyFp = mgmtDbActionDestroy, .destroyFp = mnodeDbActionDestroy,
.restoredFp = mgmtDbActionRestored .restoredFp = mnodeDbActionRestored
}; };
tsDbSdb = sdbOpenTable(&tableDesc); tsDbSdb = sdbOpenTable(&tableDesc);
...@@ -147,33 +148,33 @@ int32_t mgmtInitDbs() { ...@@ -147,33 +148,33 @@ int32_t mgmtInitDbs() {
return -1; return -1;
} }
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CREATE_DB, mgmtProcessCreateDbMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_DB, mnodeProcessCreateDbMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_ALTER_DB, mgmtProcessAlterDbMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_ALTER_DB, mnodeProcessAlterDbMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_DROP_DB, mgmtProcessDropDbMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_DB, mnodeProcessDropDbMsg);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_DB, mgmtGetDbMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DB, mnodeGetDbMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_DB, mgmtRetrieveDbs); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DB, mnodeRetrieveDbs);
mTrace("table:dbs table is created"); mTrace("table:dbs table is created");
return 0; return 0;
} }
void *mgmtGetNextDb(void *pIter, SDbObj **pDb) { void *mnodeGetNextDb(void *pIter, SDbObj **pDb) {
return sdbFetchRow(tsDbSdb, pIter, (void **)pDb); return sdbFetchRow(tsDbSdb, pIter, (void **)pDb);
} }
SDbObj *mgmtGetDb(char *db) { SDbObj *mnodeGetDb(char *db) {
return (SDbObj *)sdbGetRow(tsDbSdb, db); return (SDbObj *)sdbGetRow(tsDbSdb, db);
} }
void mgmtIncDbRef(SDbObj *pDb) { void mnodeIncDbRef(SDbObj *pDb) {
return sdbIncRef(tsDbSdb, pDb); return sdbIncRef(tsDbSdb, pDb);
} }
void mgmtDecDbRef(SDbObj *pDb) { void mnodeDecDbRef(SDbObj *pDb) {
return sdbDecRef(tsDbSdb, pDb); return sdbDecRef(tsDbSdb, pDb);
} }
SDbObj *mgmtGetDbByTableId(char *tableId) { SDbObj *mnodeGetDbByTableId(char *tableId) {
char db[TSDB_TABLE_ID_LEN], *pos; char db[TSDB_TABLE_ID_LEN], *pos;
pos = strstr(tableId, TS_PATH_DELIMITER); pos = strstr(tableId, TS_PATH_DELIMITER);
...@@ -181,10 +182,10 @@ SDbObj *mgmtGetDbByTableId(char *tableId) { ...@@ -181,10 +182,10 @@ SDbObj *mgmtGetDbByTableId(char *tableId) {
memset(db, 0, sizeof(db)); memset(db, 0, sizeof(db));
strncpy(db, tableId, pos - tableId); strncpy(db, tableId, pos - tableId);
return mgmtGetDb(db); return mnodeGetDb(db);
} }
static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) { static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { 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, mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE,
TSDB_MAX_CACHE_BLOCK_SIZE); TSDB_MAX_CACHE_BLOCK_SIZE);
...@@ -290,7 +291,7 @@ static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) { ...@@ -290,7 +291,7 @@ static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) { static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = tsCacheBlockSize; if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = tsCacheBlockSize;
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = tsBlocksPerVnode; if (pCfg->totalBlocks < 0) pCfg->totalBlocks = tsBlocksPerVnode;
if (pCfg->maxTables < 0) pCfg->maxTables = tsMaxTablePerVnode; if (pCfg->maxTables < 0) pCfg->maxTables = tsMaxTablePerVnode;
...@@ -307,13 +308,13 @@ static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) { ...@@ -307,13 +308,13 @@ static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->replications < 0) pCfg->replications = tsReplications; if (pCfg->replications < 0) pCfg->replications = tsReplications;
} }
static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
int32_t code = acctCheck(pAcct, ACCT_GRANT_DB); int32_t code = acctCheck(pAcct, ACCT_GRANT_DB);
if (code != 0) return code; if (code != 0) return code;
SDbObj *pDb = mgmtGetDb(pCreate->db); SDbObj *pDb = mnodeGetDb(pCreate->db);
if (pDb != NULL) { if (pDb != NULL) {
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
if (pCreate->ignoreExist) { if (pCreate->ignoreExist) {
mTrace("db:%s, already exist, ignore exist is set", pCreate->db); mTrace("db:%s, already exist, ignore exist is set", pCreate->db);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -347,9 +348,9 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { ...@@ -347,9 +348,9 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
.replications = pCreate->replications .replications = pCreate->replications
}; };
mgmtSetDefaultDbCfg(&pDb->cfg); mnodeSetDefaultDbCfg(&pDb->cfg);
code = mgmtCheckDbCfg(&pDb->cfg); code = mnodeCheckDbCfg(&pDb->cfg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pDb); tfree(pDb);
return code; return code;
...@@ -371,7 +372,7 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { ...@@ -371,7 +372,7 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
return code; return code;
} }
bool mgmtCheckIsMonitorDB(char *db, char *monitordb) { bool mnodeCheckIsMonitorDB(char *db, char *monitordb) {
char dbName[TSDB_DB_NAME_LEN + 1] = {0}; char dbName[TSDB_DB_NAME_LEN + 1] = {0};
extractDBName(db, dbName); extractDBName(db, dbName);
...@@ -397,7 +398,7 @@ void mgmtPrintVgroups(SDbObj *pDb, char *oper) { ...@@ -397,7 +398,7 @@ void mgmtPrintVgroups(SDbObj *pDb, char *oper) {
} }
#endif #endif
void mgmtAddVgroupIntoDb(SVgObj *pVgroup) { void mnodeAddVgroupIntoDb(SVgObj *pVgroup) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
pVgroup->next = pDb->pHead; pVgroup->next = pDb->pHead;
...@@ -410,7 +411,7 @@ void mgmtAddVgroupIntoDb(SVgObj *pVgroup) { ...@@ -410,7 +411,7 @@ void mgmtAddVgroupIntoDb(SVgObj *pVgroup) {
pDb->numOfVgroups++; pDb->numOfVgroups++;
} }
void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup) { void mnodeAddVgroupIntoDbTail(SVgObj *pVgroup) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
pVgroup->next = NULL; pVgroup->next = NULL;
pVgroup->prev = pDb->pTail; pVgroup->prev = pDb->pTail;
...@@ -422,7 +423,7 @@ void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup) { ...@@ -422,7 +423,7 @@ void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup) {
pDb->numOfVgroups++; pDb->numOfVgroups++;
} }
void mgmtRemoveVgroupFromDb(SVgObj *pVgroup) { void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
if (pVgroup->prev) pVgroup->prev->next = pVgroup->next; if (pVgroup->prev) pVgroup->prev->next = pVgroup->next;
if (pVgroup->next) pVgroup->next->prev = pVgroup->prev; if (pVgroup->next) pVgroup->next->prev = pVgroup->prev;
...@@ -431,25 +432,25 @@ void mgmtRemoveVgroupFromDb(SVgObj *pVgroup) { ...@@ -431,25 +432,25 @@ void mgmtRemoveVgroupFromDb(SVgObj *pVgroup) {
pDb->numOfVgroups--; pDb->numOfVgroups--;
} }
void mgmtMoveVgroupToTail(SVgObj *pVgroup) { void mnodeMoveVgroupToTail(SVgObj *pVgroup) {
mgmtRemoveVgroupFromDb(pVgroup); mnodeRemoveVgroupFromDb(pVgroup);
mgmtAddVgroupIntoDbTail(pVgroup); mnodeAddVgroupIntoDbTail(pVgroup);
} }
void mgmtMoveVgroupToHead(SVgObj *pVgroup) { void mnodeMoveVgroupToHead(SVgObj *pVgroup) {
mgmtRemoveVgroupFromDb(pVgroup); mnodeRemoveVgroupFromDb(pVgroup);
mgmtAddVgroupIntoDb(pVgroup); mnodeAddVgroupIntoDb(pVgroup);
} }
void mgmtCleanUpDbs() { void mnodeCleanupDbs() {
sdbCloseTable(tsDbSdb); sdbCloseTable(tsDbSdb);
} }
static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
pShow->bytes[cols] = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
...@@ -583,32 +584,32 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) ...@@ -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->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->numOfRows = pUser->pAcct->acctInfo.numOfDbs; pShow->numOfRows = pUser->pAcct->acctInfo.numOfDbs;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static char *mgmtGetDbStr(char *src) { static char *mnodeGetDbStr(char *src) {
char *pos = strstr(src, TS_PATH_DELIMITER); char *pos = strstr(src, TS_PATH_DELIMITER);
return ++pos; return ++pos;
} }
static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
char * pWrite; char * pWrite;
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextDb(pShow->pIter, &pDb); pShow->pIter = mnodeGetNextDb(pShow->pIter, &pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char* name = mgmtGetDbStr(pDb->name); char* name = mnodeGetDbStr(pDb->name);
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN);
cols++; cols++;
...@@ -706,31 +707,31 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * ...@@ -706,31 +707,31 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols++; cols++;
numOfRows++; numOfRows++;
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return numOfRows; return numOfRows;
} }
void mgmtAddSuperTableIntoDb(SDbObj *pDb) { void mnodeAddSuperTableIntoDb(SDbObj *pDb) {
atomic_add_fetch_32(&pDb->numOfSuperTables, 1); atomic_add_fetch_32(&pDb->numOfSuperTables, 1);
} }
void mgmtRemoveSuperTableFromDb(SDbObj *pDb) { void mnodeRemoveSuperTableFromDb(SDbObj *pDb) {
atomic_add_fetch_32(&pDb->numOfSuperTables, -1); atomic_add_fetch_32(&pDb->numOfSuperTables, -1);
} }
void mgmtAddTableIntoDb(SDbObj *pDb) { void mnodeAddTableIntoDb(SDbObj *pDb) {
atomic_add_fetch_32(&pDb->numOfTables, 1); atomic_add_fetch_32(&pDb->numOfTables, 1);
} }
void mgmtRemoveTableFromDb(SDbObj *pDb) { void mnodeRemoveTableFromDb(SDbObj *pDb) {
atomic_add_fetch_32(&pDb->numOfTables, -1); atomic_add_fetch_32(&pDb->numOfTables, -1);
} }
static int32_t mgmtSetDbDropping(SDbObj *pDb) { static int32_t mnodeSetDbDropping(SDbObj *pDb) {
if (pDb->status) return TSDB_CODE_SUCCESS; if (pDb->status) return TSDB_CODE_SUCCESS;
pDb->status = true; pDb->status = true;
...@@ -748,7 +749,7 @@ static int32_t mgmtSetDbDropping(SDbObj *pDb) { ...@@ -748,7 +749,7 @@ static int32_t mgmtSetDbDropping(SDbObj *pDb) {
return code; return code;
} }
static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
SCMCreateDbMsg *pCreate = pMsg->pCont; SCMCreateDbMsg *pCreate = pMsg->pCont;
pCreate->maxTables = htonl(pCreate->maxTables); pCreate->maxTables = htonl(pCreate->maxTables);
...@@ -768,7 +769,7 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) { ...@@ -768,7 +769,7 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) {
} else if (!pMsg->pUser->writeAuth) { } else if (!pMsg->pUser->writeAuth) {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} else { } else {
code = mgmtCreateDb(pMsg->pUser->pAcct, pCreate); code = mnodeCreateDb(pMsg->pUser->pAcct, pCreate);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("db:%s, is created by %s", pCreate->db, pMsg->pUser->user); mLPrint("db:%s, is created by %s", pCreate->db, pMsg->pUser->user);
} else { } else {
...@@ -776,10 +777,10 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) { ...@@ -776,10 +777,10 @@ static void mgmtProcessCreateDbMsg(SMnodeMsg *pMsg) {
} }
} }
mgmtSendSimpleResp(pMsg->thandle, code); return code;
} }
static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
SDbCfg newCfg = pDb->cfg; SDbCfg newCfg = pDb->cfg;
int32_t maxTables = htonl(pAlter->maxTables); int32_t maxTables = htonl(pAlter->maxTables);
int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize); int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize);
...@@ -876,7 +877,7 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -876,7 +877,7 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_INVALID_OPTION;
} }
if (replications > mgmtGetDnodesNum()) { if (replications > mnodeGetDnodesNum()) {
mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications);
terrno = TSDB_CODE_NO_ENOUGH_DNODES; terrno = TSDB_CODE_NO_ENOUGH_DNODES;
} }
...@@ -890,13 +891,13 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -890,13 +891,13 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
return newCfg; return newCfg;
} }
static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
SDbCfg newCfg = mgmtGetAlterDbOption(pDb, pAlter); SDbCfg newCfg = mnodeGetAlterDbOption(pDb, pAlter);
if (terrno != TSDB_CODE_SUCCESS) { if (terrno != TSDB_CODE_SUCCESS) {
return terrno; return terrno;
} }
int32_t code = mgmtCheckDbCfg(&newCfg); int32_t code = mnodeCheckDbCfg(&newCfg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
...@@ -921,10 +922,10 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -921,10 +922,10 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
pIter = mgmtGetNextVgroup(pIter, &pVgroup); pIter = mnodeGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
mgmtSendCreateVgroupMsg(pVgroup, NULL); mnodeSendCreateVgroupMsg(pVgroup, NULL);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -935,35 +936,27 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -935,35 +936,27 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void mgmtProcessAlterDbMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
SCMAlterDbMsg *pAlter = pMsg->pCont; SCMAlterDbMsg *pAlter = pMsg->pCont;
mTrace("db:%s, alter db msg is received from thandle:%p", pAlter->db, pMsg->thandle); mTrace("db:%s, alter db msg is received from thandle:%p", pAlter->db, pMsg->thandle);
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db);
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) { if (pMsg->pDb == NULL) {
mError("db:%s, failed to alter, invalid db", pAlter->db); mError("db:%s, failed to alter, invalid db", pAlter->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_DB); return TSDB_CODE_INVALID_DB;
return;
} }
int32_t code = mgmtAlterDb(pMsg->pDb, pAlter); int32_t code = mnodeAlterDb(pMsg->pDb, pAlter);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("db:%s, failed to alter, invalid db option", pAlter->db); mError("db:%s, failed to alter, invalid db option", pAlter->db);
mgmtSendSimpleResp(pMsg->thandle, code); return code;
return;
} }
mTrace("db:%s, all vgroups is altered", pMsg->pDb->name); mTrace("db:%s, all vgroups is altered", pMsg->pDb->name);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS;
} }
static void mgmtDropDb(SMnodeMsg *pMsg) { static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
SDbObj *pDb = pMsg->pDb; SDbObj *pDb = pMsg->pDb;
mPrint("db:%s, drop db from sdb", pDb->name); mPrint("db:%s, drop db from sdb", pDb->name);
...@@ -977,64 +970,54 @@ static void mgmtDropDb(SMnodeMsg *pMsg) { ...@@ -977,64 +970,54 @@ static void mgmtDropDb(SMnodeMsg *pMsg) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
} }
mgmtSendSimpleResp(pMsg->thandle, code); return code;
} }
static void mgmtProcessDropDbMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
SCMDropDbMsg *pDrop = pMsg->pCont; SCMDropDbMsg *pDrop = pMsg->pCont;
mTrace("db:%s, drop db msg is received from thandle:%p", pDrop->db, pMsg->thandle); mTrace("db:%s, drop db msg is received from thandle:%p", pDrop->db, pMsg->thandle);
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pDrop->db);
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) { if (pMsg->pDb == NULL) {
if (pDrop->ignoreNotExists) { if (pDrop->ignoreNotExists) {
mTrace("db:%s, db is not exist, think drop success", pDrop->db); mTrace("db:%s, db is not exist, think drop success", pDrop->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS;
return;
} else { } else {
mError("db:%s, failed to drop, invalid db", pDrop->db); mError("db:%s, failed to drop, invalid db", pDrop->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_DB); return TSDB_CODE_INVALID_DB;
return;
} }
} }
if (mgmtCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("db:%s, can't drop monitor database", pDrop->db); mError("db:%s, can't drop monitor database", pDrop->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MONITOR_DB_FORBIDDEN); return TSDB_CODE_MONITOR_DB_FORBIDDEN;
return;
} }
int32_t code = mgmtSetDbDropping(pMsg->pDb); int32_t code = mnodeSetDbDropping(pMsg->pDb);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("db:%s, failed to drop, reason:%s", pDrop->db, tstrerror(code)); mError("db:%s, failed to drop, reason:%s", pDrop->db, tstrerror(code));
mgmtSendSimpleResp(pMsg->thandle, code); return code;
return;
} }
#if 1 #if 1
mgmtDropAllDbVgroups(pMsg->pDb, true); mnodeDropAllDbVgroups(pMsg->pDb, true);
#else #else
SVgObj *pVgroup = pMsg->pDb->pHead; SVgObj *pVgroup = pMsg->pDb->pHead;
if (pVgroup != NULL) { if (pVgroup != NULL) {
mPrint("vgId:%d, will be dropped", pVgroup->vgId); mPrint("vgId:%d, will be dropped", pVgroup->vgId);
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(pMsg); SMnodeMsg *newMsg = mnodeCloneMsg(pMsg);
newMsg->ahandle = pVgroup; newMsg->ahandle = pVgroup;
newMsg->expected = pVgroup->numOfVnodes; newMsg->expected = pVgroup->numOfVnodes;
mgmtDropVgroup(pVgroup, newMsg); mnodeDropVgroup(pVgroup, newMsg);
return; return;
} }
#endif #endif
mTrace("db:%s, all vgroups is dropped", pMsg->pDb->name); mTrace("db:%s, all vgroups is dropped", pMsg->pDb->name);
mgmtDropDb(pMsg); return mnodeDropDb(pMsg);
} }
void mgmtDropAllDbs(SAcctObj *pAcct) { void mnodeDropAllDbs(SAcctObj *pAcct) {
int32_t numOfDbs = 0; int32_t numOfDbs = 0;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
void * pIter = NULL; void * pIter = NULL;
...@@ -1042,7 +1025,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) { ...@@ -1042,7 +1025,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
mPrint("acct:%s, all dbs will be dropped from sdb", pAcct->user); mPrint("acct:%s, all dbs will be dropped from sdb", pAcct->user);
while (1) { while (1) {
pIter = mgmtGetNextDb(pIter, &pDb); pIter = mnodeGetNextDb(pIter, &pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
if (pDb->pAcct == pAcct) { if (pDb->pAcct == pAcct) {
...@@ -1056,7 +1039,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) { ...@@ -1056,7 +1039,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
numOfDbs++; numOfDbs++;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
......
...@@ -25,15 +25,18 @@ ...@@ -25,15 +25,18 @@
#include "tbalance.h" #include "tbalance.h"
#include "tsync.h" #include "tsync.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeWrite.h"
#include "mnodePeer.h"
int32_t tsAccessSquence = 0; int32_t tsAccessSquence = 0;
static void *tsDnodeSdb = NULL; static void *tsDnodeSdb = NULL;
...@@ -41,27 +44,27 @@ static int32_t tsDnodeUpdateSize = 0; ...@@ -41,27 +44,27 @@ static int32_t tsDnodeUpdateSize = 0;
extern void * tsMnodeSdb; extern void * tsMnodeSdb;
extern void * tsVgroupSdb; extern void * tsVgroupSdb;
static int32_t mgmtCreateDnode(char *ep); static int32_t mnodeCreateDnode(char *ep);
static void mgmtProcessCreateDnodeMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg);
static void mgmtProcessDropDnodeMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg);
static void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg);
static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ; static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ;
static void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg); static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *rpcMsg);
static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtDnodeActionDestroy(SSdbOper *pOper) { static int32_t mnodeDnodeActionDestroy(SSdbOper *pOper) {
tfree(pOper->pObj); tfree(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) { static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
if (pDnode->status != TAOS_DN_STATUS_DROPPING) { if (pDnode->status != TAOS_DN_STATUS_DROPPING) {
pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->status = TAOS_DN_STATUS_OFFLINE;
...@@ -70,38 +73,38 @@ static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) { ...@@ -70,38 +73,38 @@ static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionDelete(SSdbOper *pOper) { static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
#ifndef _SYNC #ifndef _SYNC
mgmtDropAllDnodeVgroups(pDnode); mnodeDropAllDnodeVgroups(pDnode);
#endif #endif
mgmtDropMnodeLocal(pDnode->dnodeId); mnodeDropMnodeLocal(pDnode->dnodeId);
balanceNotify(); balanceNotify();
mTrace("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId); mTrace("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionUpdate(SSdbOper *pOper) { static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
SDnodeObj *pSaved = mgmtGetDnode(pDnode->dnodeId); SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId);
if (pDnode != pSaved) { if (pDnode != pSaved) {
memcpy(pSaved, pDnode, pOper->rowSize); memcpy(pSaved, pDnode, pOper->rowSize);
free(pDnode); free(pDnode);
} }
mgmtDecDnodeRef(pSaved); mnodeDecDnodeRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
memcpy(pOper->rowData, pDnode, tsDnodeUpdateSize); memcpy(pOper->rowData, pDnode, tsDnodeUpdateSize);
pOper->rowSize = tsDnodeUpdateSize; pOper->rowSize = tsDnodeUpdateSize;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) { static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) {
SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
if (pDnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pDnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -110,19 +113,19 @@ static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) { ...@@ -110,19 +113,19 @@ static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionRestored() { static int32_t mnodeDnodeActionRestored() {
int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb); int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb);
if (numOfRows <= 0 && dnodeIsFirstDeploy()) { if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
mgmtCreateDnode(tsLocalEp); mnodeCreateDnode(tsLocalEp);
SDnodeObj *pDnode = mgmtGetDnodeByEp(tsLocalEp); SDnodeObj *pDnode = mnodeGetDnodeByEp(tsLocalEp);
mgmtAddMnode(pDnode->dnodeId); mnodeAddMnode(pDnode->dnodeId);
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitDnodes() { int32_t mnodeInitDnodes() {
SDnodeObj tObj; SDnodeObj tObj;
tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -133,13 +136,13 @@ int32_t mgmtInitDnodes() { ...@@ -133,13 +136,13 @@ int32_t mgmtInitDnodes() {
.maxRowSize = tsDnodeUpdateSize, .maxRowSize = tsDnodeUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_AUTO, .keyType = SDB_KEY_AUTO,
.insertFp = mgmtDnodeActionInsert, .insertFp = mnodeDnodeActionInsert,
.deleteFp = mgmtDnodeActionDelete, .deleteFp = mnodeDnodeActionDelete,
.updateFp = mgmtDnodeActionUpdate, .updateFp = mnodeDnodeActionUpdate,
.encodeFp = mgmtDnodeActionEncode, .encodeFp = mnodeDnodeActionEncode,
.decodeFp = mgmtDnodeActionDecode, .decodeFp = mnodeDnodeActionDecode,
.destroyFp = mgmtDnodeActionDestroy, .destroyFp = mnodeDnodeActionDestroy,
.restoredFp = mgmtDnodeActionRestored .restoredFp = mnodeDnodeActionRestored
}; };
tsDnodeSdb = sdbOpenTable(&tableDesc); tsDnodeSdb = sdbOpenTable(&tableDesc);
...@@ -148,19 +151,19 @@ int32_t mgmtInitDnodes() { ...@@ -148,19 +151,19 @@ int32_t mgmtInitDnodes() {
return -1; return -1;
} }
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CREATE_DNODE, mgmtProcessCreateDnodeMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_DNODE, mnodeProcessCreateDnodeMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_DROP_DNODE, mgmtProcessDropDnodeMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_DNODE, mnodeProcessDropDnodeMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CONFIG_DNODE, mgmtProcessCfgDnodeMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CONFIG_DNODE, mnodeProcessCfgDnodeMsg);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP, mgmtProcessCfgDnodeMsgRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP, mnodeProcessCfgDnodeMsgRsp);
dnodeAddServerMsgHandle(TSDB_MSG_TYPE_DM_STATUS, mgmtProcessDnodeStatusMsg); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_STATUS, mnodeProcessDnodeStatusMsg);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_MODULE, mgmtGetModuleMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_MODULE, mnodeGetModuleMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_MODULE, mgmtRetrieveModules); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_MODULE, mnodeRetrieveModules);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_CONFIGS, mgmtGetConfigMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONFIGS, mnodeGetConfigMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_CONFIGS, mgmtRetrieveConfigs); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONFIGS, mnodeRetrieveConfigs);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_VNODES, mgmtGetVnodeMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VNODES, mnodeGetVnodeMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_VNODES, mgmtRetrieveVnodes); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VNODES, mnodeRetrieveVnodes);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_DNODE, mgmtGetDnodeMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DNODE, mnodeGetDnodeMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_DNODE, mgmtRetrieveDnodes); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DNODE, mnodeRetrieveDnodes);
mTrace("table:dnodes table is created"); mTrace("table:dnodes table is created");
return 0; return 0;
...@@ -170,24 +173,24 @@ void mgmtCleanupDnodes() { ...@@ -170,24 +173,24 @@ void mgmtCleanupDnodes() {
sdbCloseTable(tsDnodeSdb); sdbCloseTable(tsDnodeSdb);
} }
void *mgmtGetNextDnode(void *pIter, SDnodeObj **pDnode) { void *mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode) {
return sdbFetchRow(tsDnodeSdb, pIter, (void **)pDnode); return sdbFetchRow(tsDnodeSdb, pIter, (void **)pDnode);
} }
int32_t mgmtGetDnodesNum() { int32_t mnodeGetDnodesNum() {
return sdbGetNumOfRows(tsDnodeSdb); return sdbGetNumOfRows(tsDnodeSdb);
} }
int32_t mgmtGetOnlinDnodesNum(char *ep) { int32_t mnodeGetOnlinDnodesNum(char *ep) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
void * pIter = NULL; void * pIter = NULL;
int32_t onlineDnodes = 0; int32_t onlineDnodes = 0;
while (1) { while (1) {
pIter = mgmtGetNextDnode(pIter, &pDnode); pIter = mnodeGetNextDnode(pIter, &pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
if (pDnode->status != TAOS_DN_STATUS_OFFLINE) onlineDnodes++; if (pDnode->status != TAOS_DN_STATUS_OFFLINE) onlineDnodes++;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -195,22 +198,22 @@ int32_t mgmtGetOnlinDnodesNum(char *ep) { ...@@ -195,22 +198,22 @@ int32_t mgmtGetOnlinDnodesNum(char *ep) {
return onlineDnodes; return onlineDnodes;
} }
void *mgmtGetDnode(int32_t dnodeId) { void *mnodeGetDnode(int32_t dnodeId) {
return sdbGetRow(tsDnodeSdb, &dnodeId); return sdbGetRow(tsDnodeSdb, &dnodeId);
} }
void *mgmtGetDnodeByEp(char *ep) { void *mnodeGetDnodeByEp(char *ep) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
void * pIter = NULL; void * pIter = NULL;
while (1) { while (1) {
pIter = mgmtGetNextDnode(pIter, &pDnode); pIter = mnodeGetNextDnode(pIter, &pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
if (strcmp(ep, pDnode->dnodeEp) == 0) { if (strcmp(ep, pDnode->dnodeEp) == 0) {
sdbFreeIter(pIter); sdbFreeIter(pIter);
return pDnode; return pDnode;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -218,15 +221,15 @@ void *mgmtGetDnodeByEp(char *ep) { ...@@ -218,15 +221,15 @@ void *mgmtGetDnodeByEp(char *ep) {
return NULL; return NULL;
} }
void mgmtIncDnodeRef(SDnodeObj *pDnode) { void mnodeIncDnodeRef(SDnodeObj *pDnode) {
sdbIncRef(tsDnodeSdb, pDnode); sdbIncRef(tsDnodeSdb, pDnode);
} }
void mgmtDecDnodeRef(SDnodeObj *pDnode) { void mnodeDecDnodeRef(SDnodeObj *pDnode) {
sdbDecRef(tsDnodeSdb, pDnode); sdbDecRef(tsDnodeSdb, pDnode);
} }
void mgmtUpdateDnode(SDnodeObj *pDnode) { void mnodeUpdateDnode(SDnodeObj *pDnode) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDnodeSdb, .table = tsDnodeSdb,
...@@ -236,9 +239,7 @@ void mgmtUpdateDnode(SDnodeObj *pDnode) { ...@@ -236,9 +239,7 @@ void mgmtUpdateDnode(SDnodeObj *pDnode) {
sdbUpdateRow(&oper); sdbUpdateRow(&oper);
} }
void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMCfgDnodeMsg *pCmCfgDnode = pMsg->pCont; SCMCfgDnodeMsg *pCmCfgDnode = pMsg->pCont;
if (pCmCfgDnode->ep[0] == 0) { if (pCmCfgDnode->ep[0] == 0) {
strcpy(pCmCfgDnode->ep, tsLocalEp); strcpy(pCmCfgDnode->ep, tsLocalEp);
...@@ -247,36 +248,34 @@ void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg) { ...@@ -247,36 +248,34 @@ void mgmtProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
} }
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} else {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pCmCfgDnode->ep);
SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
strcpy(pMdCfgDnode->config, pCmCfgDnode->config);
SRpcMsg rpcMdCfgDnodeMsg = {
.handle = 0,
.code = 0,
.msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE,
.pCont = pMdCfgDnode,
.contLen = sizeof(SMDCfgDnodeMsg)
};
dnodeSendMsgToDnode(&ipSet, &rpcMdCfgDnodeMsg);
rpcRsp.code = TSDB_CODE_SUCCESS;
} }
if (rpcRsp.code == TSDB_CODE_SUCCESS) { SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep);
mPrint("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user); SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
} strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
strcpy(pMdCfgDnode->config, pCmCfgDnode->config);
SRpcMsg rpcMdCfgDnodeMsg = {
.handle = 0,
.code = 0,
.msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE,
.pCont = pMdCfgDnode,
.contLen = sizeof(SMDCfgDnodeMsg)
};
dnodeSendMsgToDnode(&ipSet, &rpcMdCfgDnodeMsg);
rpcSendResponse(&rpcRsp); mPrint("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);
return TSDB_CODE_SUCCESS;
} }
static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) { static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) {
mPrint("cfg dnode rsp is received"); mPrint("cfg dnode rsp is received");
} }
void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
SDMStatusMsg *pStatus = rpcMsg->pCont; SDMStatusMsg *pStatus = pMsg->pCont;
pStatus->dnodeId = htonl(pStatus->dnodeId); pStatus->dnodeId = htonl(pStatus->dnodeId);
pStatus->moduleStatus = htonl(pStatus->moduleStatus); pStatus->moduleStatus = htonl(pStatus->moduleStatus);
pStatus->lastReboot = htonl(pStatus->lastReboot); pStatus->lastReboot = htonl(pStatus->lastReboot);
...@@ -286,24 +285,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -286,24 +285,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
uint32_t version = htonl(pStatus->version); uint32_t version = htonl(pStatus->version);
if (version != tsVersion) { if (version != tsVersion) {
mError("status msg version:%d not equal with mnode:%d", version, tsVersion); mError("status msg version:%d not equal with mnode:%d", version, tsVersion);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_INVALID_MSG_VERSION); return TSDB_CODE_INVALID_MSG_VERSION;
return ;
} }
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
if (pStatus->dnodeId == 0) { if (pStatus->dnodeId == 0) {
pDnode = mgmtGetDnodeByEp(pStatus->dnodeEp); pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp);
if (pDnode == NULL) { if (pDnode == NULL) {
mTrace("dnode %s not created", pStatus->dnodeEp); mTrace("dnode %s not created", pStatus->dnodeEp);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST); return TSDB_CODE_DNODE_NOT_EXIST;
return;
} }
} else { } else {
pDnode = mgmtGetDnode(pStatus->dnodeId); pDnode = mnodeGetDnode(pStatus->dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp); mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST); return TSDB_CODE_DNODE_NOT_EXIST;
return;
} }
} }
...@@ -327,34 +323,33 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -327,34 +323,33 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
pVload->vgId = htonl(pVload->vgId); pVload->vgId = htonl(pVload->vgId);
pVload->cfgVersion = htonl(pVload->cfgVersion); pVload->cfgVersion = htonl(pVload->cfgVersion);
SVgObj *pVgroup = mgmtGetVgroup(pVload->vgId); SVgObj *pVgroup = mnodeGetVgroup(pVload->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
mPrint("dnode:%d, vgId:%d not exist in mnode, drop it", pDnode->dnodeId, pVload->vgId); mPrint("dnode:%d, vgId:%d not exist in mnode, drop it", pDnode->dnodeId, pVload->vgId);
mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL); mnodeSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
} else { } else {
mgmtUpdateVgroupStatus(pVgroup, pDnode, pVload); mnodeUpdateVgroupStatus(pVgroup, pDnode, pVload);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
} }
if (pDnode->status == TAOS_DN_STATUS_OFFLINE) { if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
mTrace("dnode:%d, from offline to online", pDnode->dnodeId); mTrace("dnode:%d, from offline to online", pDnode->dnodeId);
pDnode->status = TAOS_DN_STATUS_READY; pDnode->status = TAOS_DN_STATUS_READY;
balanceUpdateMgmt(); balanceUpdateMnode();
balanceNotify(); balanceNotify();
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess); int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess);
SDMStatusRsp *pRsp = rpcMallocCont(contLen); SDMStatusRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
mgmtGetMnodeInfos(&pRsp->mnodes); mnodeGetMnodeInfos(&pRsp->mnodes);
pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId); pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt); pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
...@@ -364,25 +359,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -364,25 +359,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
//TODO: set vnode access //TODO: set vnode access
SRpcMsg rpcRsp = { pMsg->rpcRsp.len = contLen;
.handle = rpcMsg->handle, pMsg->rpcRsp.rsp = pRsp;
.code = TSDB_CODE_SUCCESS,
.pCont = pRsp,
.contLen = contLen
};
rpcSendResponse(&rpcRsp); return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtCreateDnode(char *ep) { static int32_t mnodeCreateDnode(char *ep) {
int32_t grantCode = grantCheck(TSDB_GRANT_DNODE); int32_t grantCode = grantCheck(TSDB_GRANT_DNODE);
if (grantCode != TSDB_CODE_SUCCESS) { if (grantCode != TSDB_CODE_SUCCESS) {
return grantCode; return grantCode;
} }
SDnodeObj *pDnode = mgmtGetDnodeByEp(ep); SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
if (pDnode != NULL) { if (pDnode != NULL) {
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort); mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
return TSDB_CODE_DNODE_ALREADY_EXIST; return TSDB_CODE_DNODE_ALREADY_EXIST;
} }
...@@ -413,7 +404,7 @@ static int32_t mgmtCreateDnode(char *ep) { ...@@ -413,7 +404,7 @@ static int32_t mgmtCreateDnode(char *ep) {
return code; return code;
} }
int32_t mgmtDropDnode(SDnodeObj *pDnode) { int32_t mnodeDropDnode(SDnodeObj *pDnode) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDnodeSdb, .table = tsDnodeSdb,
...@@ -429,15 +420,14 @@ int32_t mgmtDropDnode(SDnodeObj *pDnode) { ...@@ -429,15 +420,14 @@ int32_t mgmtDropDnode(SDnodeObj *pDnode) {
return code; return code;
} }
static int32_t mgmtDropDnodeByEp(char *ep) { static int32_t mnodeDropDnodeByEp(char *ep) {
SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
SDnodeObj *pDnode = mgmtGetDnodeByEp(ep);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode:%s, is not exist", ep); mError("dnode:%s, is not exist", ep);
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_DNODE_NOT_EXIST;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) { if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) {
mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep); mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
return TSDB_CODE_NO_REMOVE_MASTER; return TSDB_CODE_NO_REMOVE_MASTER;
...@@ -445,58 +435,56 @@ static int32_t mgmtDropDnodeByEp(char *ep) { ...@@ -445,58 +435,56 @@ static int32_t mgmtDropDnodeByEp(char *ep) {
mPrint("dnode:%d, start to drop it", pDnode->dnodeId); mPrint("dnode:%d, start to drop it", pDnode->dnodeId);
#ifndef _SYNC #ifndef _SYNC
return mgmtDropDnode(pDnode); return mnodeDropDnode(pDnode);
#else #else
return balanceDropDnode(pDnode); return balanceDropDnode(pDnode);
#endif #endif
} }
static void mgmtProcessCreateDnodeMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMCreateDnodeMsg *pCreate = pMsg->pCont; SCMCreateDnodeMsg *pCreate = pMsg->pCont;
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} else { } else {
rpcRsp.code = mgmtCreateDnode(pCreate->ep); int32_t code = mnodeCreateDnode(pCreate->ep);
if (rpcRsp.code == TSDB_CODE_SUCCESS) {
SDnodeObj *pDnode = mgmtGetDnodeByEp(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); mLPrint("dnode:%d, %s is created by %s", pDnode->dnodeId, pCreate->ep, pMsg->pUser->user);
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} else { } 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 int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) {
static void mgmtProcessDropDnodeMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMDropDnodeMsg *pDrop = pMsg->pCont; SCMDropDnodeMsg *pDrop = pMsg->pCont;
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} else { } else {
rpcRsp.code = mgmtDropDnodeByEp(pDrop->ep); int32_t code = mnodeDropDnodeByEp(pDrop->ep);
if (rpcRsp.code == TSDB_CODE_SUCCESS) {
if (code == TSDB_CODE_SUCCESS) {
mLPrint("dnode:%s is dropped by %s", pDrop->ep, pMsg->pUser->user); mLPrint("dnode:%s is dropped by %s", pDrop->ep, pMsg->pUser->user);
} else { } 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 mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
...@@ -547,23 +535,23 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -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->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
} }
pShow->numOfRows = mgmtGetDnodesNum(); pShow->numOfRows = mnodeGetDnodesNum();
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->pIter = NULL; pShow->pIter = NULL;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
int32_t cols = 0; int32_t cols = 0;
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
char *pWrite; char *pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextDnode(pShow->pIter, &pDnode); pShow->pIter = mnodeGetNextDnode(pShow->pIter, &pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
cols = 0; cols = 0;
...@@ -586,7 +574,7 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -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; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char* status = mgmtGetDnodeStatusStr(pDnode->status); char* status = mnodeGetDnodeStatusStr(pDnode->status);
STR_TO_VARSTR(pWrite, status); STR_TO_VARSTR(pWrite, status);
cols++; cols++;
...@@ -596,26 +584,26 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -596,26 +584,26 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
numOfRows++; numOfRows++;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
return numOfRows; return numOfRows;
} }
static bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) { static bool mnodeCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) {
uint32_t status = pDnode->moduleStatus & (1 << moduleType); uint32_t status = pDnode->moduleStatus & (1 << moduleType);
return status > 0; return status > 0;
} }
static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
...@@ -653,21 +641,21 @@ static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC ...@@ -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->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
} }
pShow->numOfRows = mgmtGetDnodesNum() * TSDB_MOD_MAX; pShow->numOfRows = mnodeGetDnodesNum() * TSDB_MOD_MAX;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->pIter = NULL; pShow->pIter = NULL;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
char * pWrite; char * pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
pShow->pIter = mgmtGetNextDnode(pShow->pIter, (SDnodeObj **)&pDnode); pShow->pIter = mnodeGetNextDnode(pShow->pIter, (SDnodeObj **)&pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
for (int32_t moduleType = 0; moduleType < TSDB_MOD_MAX; ++moduleType) { 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 ...@@ -698,34 +686,34 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
bool enable = mgmtCheckModuleInDnode(pDnode, moduleType); bool enable = mnodeCheckModuleInDnode(pDnode, moduleType);
strcpy(pWrite, enable ? "enable" : "disable"); strcpy(pWrite, enable ? "enable" : "disable");
cols++; cols++;
numOfRows++; numOfRows++;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
return numOfRows; return numOfRows;
} }
static bool mgmtCheckConfigShow(SGlobalCfg *cfg) { static bool mnodeCheckConfigShow(SGlobalCfg *cfg) {
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW))
return false; return false;
return true; return true;
} }
static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
...@@ -752,23 +740,23 @@ static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC ...@@ -752,23 +740,23 @@ static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
pShow->numOfRows = 0; pShow->numOfRows = 0;
for (int32_t i = tsGlobalConfigNum - 1; i >= 0; --i) { for (int32_t i = tsGlobalConfigNum - 1; i >= 0; --i) {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (!mgmtCheckConfigShow(cfg)) continue; if (!mnodeCheckConfigShow(cfg)) continue;
pShow->numOfRows++; pShow->numOfRows++;
} }
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->pIter = NULL; pShow->pIter = NULL;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
for (int32_t i = tsGlobalConfigNum - 1; i >= 0 && numOfRows < rows; --i) { for (int32_t i = tsGlobalConfigNum - 1; i >= 0 && numOfRows < rows; --i) {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (!mgmtCheckConfigShow(cfg)) continue; if (!mnodeCheckConfigShow(cfg)) continue;
char *pWrite; char *pWrite;
int32_t cols = 0; int32_t cols = 0;
...@@ -806,13 +794,13 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo ...@@ -806,13 +794,13 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo
return numOfRows; return numOfRows;
} }
static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
...@@ -838,25 +826,25 @@ static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -838,25 +826,25 @@ static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
if (pShow->payloadLen > 0 ) { if (pShow->payloadLen > 0 ) {
pDnode = mgmtGetDnodeByEp(pShow->payload); pDnode = mnodeGetDnodeByEp(pShow->payload);
} else { } else {
void *pIter = mgmtGetNextDnode(NULL, (SDnodeObj **)&pDnode); void *pIter = mnodeGetNextDnode(NULL, (SDnodeObj **)&pDnode);
sdbFreeIter(pIter); sdbFreeIter(pIter);
} }
if (pDnode != NULL) { if (pDnode != NULL) {
pShow->numOfRows += pDnode->openVnodes; pShow->numOfRows += pDnode->openVnodes;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->pIter = pDnode; pShow->pIter = pDnode;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
char * pWrite; char * pWrite;
...@@ -869,7 +857,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -869,7 +857,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
void *pIter = NULL; void *pIter = NULL;
SVgObj *pVgroup; SVgObj *pVgroup;
while (1) { while (1) {
pIter = mgmtGetNextVgroup(pIter, &pVgroup); pIter = mnodeGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { 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 ...@@ -882,12 +870,12 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, mgmtGetMnodeRoleStr(pVgid->role)); strcpy(pWrite, mnodeGetMnodeRoleStr(pVgid->role));
cols++; cols++;
} }
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
} else { } else {
...@@ -898,7 +886,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -898,7 +886,7 @@ static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, voi
return numOfRows; return numOfRows;
} }
char* mgmtGetDnodeStatusStr(int32_t dnodeStatus) { char* mnodeGetDnodeStatusStr(int32_t dnodeStatus) {
switch (dnodeStatus) { switch (dnodeStatus) {
case TAOS_DN_STATUS_OFFLINE: return "offline"; case TAOS_DN_STATUS_OFFLINE: return "offline";
case TAOS_DN_STATUS_DROPPING: return "dropping"; case TAOS_DN_STATUS_DROPPING: return "dropping";
......
/*
* 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);
}
}
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeServer.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
...@@ -33,16 +32,16 @@ ...@@ -33,16 +32,16 @@
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeShell.h" #include "mnodeShow.h"
static void *tsMgmtTmr; void *tsMnodeTmr;
static bool tsMgmtIsRunning = false; static bool tsMgmtIsRunning = false;
static void mnodeInitTimer(); static void mnodeInitTimer();
static void mnodeCleanupTimer(); static void mnodeCleanupTimer();
static bool mnodeNeedStart() ; static bool mnodeNeedStart() ;
int32_t mgmtStartSystem() { int32_t mnodeStartSystem() {
if (tsMgmtIsRunning) { if (tsMgmtIsRunning) {
mPrint("TDengine mgmt module already started..."); mPrint("TDengine mgmt module already started...");
return 0; return 0;
...@@ -54,37 +53,37 @@ int32_t mgmtStartSystem() { ...@@ -54,37 +53,37 @@ int32_t mgmtStartSystem() {
mkdir(tsMnodeDir, 0755); mkdir(tsMnodeDir, 0755);
} }
if (mgmtInitAccts() < 0) { if (mnodeInitAccts() < 0) {
mError("failed to init accts"); mError("failed to init accts");
return -1; return -1;
} }
if (mgmtInitUsers() < 0) { if (mnodeInitUsers() < 0) {
mError("failed to init users"); mError("failed to init users");
return -1; return -1;
} }
if (mgmtInitDnodes() < 0) { if (mnodeInitDnodes() < 0) {
mError("failed to init dnodes"); mError("failed to init dnodes");
return -1; return -1;
} }
if (mgmtInitDbs() < 0) { if (mnodeInitDbs() < 0) {
mError("failed to init dbs"); mError("failed to init dbs");
return -1; return -1;
} }
if (mgmtInitVgroups() < 0) { if (mnodeInitVgroups() < 0) {
mError("failed to init vgroups"); mError("failed to init vgroups");
return -1; return -1;
} }
if (mgmtInitTables() < 0) { if (mnodeInitTables() < 0) {
mError("failed to init tables"); mError("failed to init tables");
return -1; return -1;
} }
if (mgmtInitMnodes() < 0) { if (mnodeInitMnodes() < 0) {
mError("failed to init mnodes"); mError("failed to init mnodes");
return -1; return -1;
} }
...@@ -103,7 +102,8 @@ int32_t mgmtStartSystem() { ...@@ -103,7 +102,8 @@ int32_t mgmtStartSystem() {
return -1; return -1;
} }
if (mnodeInitMgmt() < 0) { if (mnodeInitShow() < 0) {
mError("failed to init show");
return -1; return -1;
} }
...@@ -115,39 +115,28 @@ int32_t mgmtStartSystem() { ...@@ -115,39 +115,28 @@ int32_t mgmtStartSystem() {
return 0; return 0;
} }
int32_t mgmtInitSystem() { int32_t mnodeInitSystem() {
mnodeInitTimer(); mnodeInitTimer();
mnodeInitRead(); if (!mnodeNeedStart()) return 0;
mnodeInitWrite(); return mnodeStartSystem();
if (mnodeNeedStart()) {
if (mgmtStartSystem() != 0) {
return -1;
}
}
return 0;
} }
void mgmtCleanUpSystem() { void mnodeCleanupSystem() {
mPrint("starting to clean up mgmt"); mPrint("starting to clean up mgmt");
tsMgmtIsRunning = false; tsMgmtIsRunning = false;
mnodeCleanupTimer(); mnodeCleanupTimer();
mnodeCleanupRead(); mnodeCleanUpShow();
mnodeCleanupWrite();
mgmtCleanupMgmt();
grantCleanUp(); grantCleanUp();
balanceCleanUp(); balanceCleanUp();
sdbCleanUp(); sdbCleanUp();
mgmtCleanupMnodes(); mgmtCleanupMnodes();
mgmtCleanUpTables(); mnodeCleanupTables();
mgmtCleanUpVgroups(); mnodeCleanupVgroups();
mgmtCleanUpDbs(); mnodeCleanupDbs();
mgmtCleanupDnodes(); mgmtCleanupDnodes();
mgmtCleanUpUsers(); mnodeCleanupUsers();
mgmtCleanUpAccts(); mnodeCleanupAccts();
mPrint("mgmt is cleaned up"); mPrint("mgmt is cleaned up");
} }
...@@ -157,31 +146,21 @@ void mgmtStopSystem() { ...@@ -157,31 +146,21 @@ void mgmtStopSystem() {
return; return;
} }
mnodeCleanupSystem();
mgmtCleanUpSystem();
mPrint("mgmt file is removed"); mPrint("mgmt file is removed");
remove(tsMnodeDir); remove(tsMnodeDir);
} }
void* mnodeGetWqueue(int32_t vgId) {
}
static void mnodeInitTimer() { static void mnodeInitTimer() {
if (tsMgmtTmr != NULL) { if (tsMnodeTmr != NULL) {
tsMgmtTmr = taosTmrInit((tsMaxShellConns)*3, 200, 3600000, "MND"); tsMnodeTmr = taosTmrInit((tsMaxShellConns)*3, 200, 3600000, "MND");
} }
} }
static void mnodeCleanupTimer() { static void mnodeCleanupTimer() {
if (tsMgmtTmr != NULL) { if (tsMnodeTmr != NULL) {
taosTmrCleanUp(tsMgmtTmr); taosTmrCleanUp(tsMnodeTmr);
tsMgmtTmr = NULL; tsMnodeTmr = NULL;
} }
} }
...@@ -196,3 +175,7 @@ static bool mnodeNeedStart() { ...@@ -196,3 +175,7 @@ static bool mnodeNeedStart() {
return false; return false;
} }
bool mnodeIsRunning() {
return tsMgmtIsRunning;
}
\ No newline at end of file
...@@ -28,80 +28,80 @@ ...@@ -28,80 +28,80 @@
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeUser.h" #include "mnodeUser.h"
static void * tsMnodeSdb = NULL; static void * tsMnodeSdb = NULL;
static int32_t tsMnodeUpdateSize = 0; static int32_t tsMnodeUpdateSize = 0;
static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static SRpcIpSet tsMnodeRpcIpSetForShell;
static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); static SRpcIpSet tsMnodeRpcIpSetForPeer;
static SRpcIpSet tsMnodeRpcIpSet;
static SDMMnodeInfos tsMnodeInfos; 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) #if defined(LINUX)
static pthread_rwlock_t tsMnodeLock; static pthread_rwlock_t tsMnodeLock;
#define mgmtMnodeWrLock() pthread_rwlock_wrlock(&tsMnodeLock) #define mnodeMnodeWrLock() pthread_rwlock_wrlock(&tsMnodeLock)
#define mgmtMnodeRdLock() pthread_rwlock_rdlock(&tsMnodeLock) #define mnodeMnodeRdLock() pthread_rwlock_rdlock(&tsMnodeLock)
#define mgmtMnodeUnLock() pthread_rwlock_unlock(&tsMnodeLock) #define mnodeMnodeUnLock() pthread_rwlock_unlock(&tsMnodeLock)
#define mgmtMnodeInitLock() pthread_rwlock_init(&tsMnodeLock, NULL) #define mnodeMnodeInitLock() pthread_rwlock_init(&tsMnodeLock, NULL)
#define mgmtMnodeDestroyLock() pthread_rwlock_destroy(&tsMnodeLock) #define mnodeMnodeDestroyLock() pthread_rwlock_destroy(&tsMnodeLock)
#else #else
static pthread_mutex_t tsMnodeLock; static pthread_mutex_t tsMnodeLock;
#define mgmtMnodeWrLock() pthread_mutex_lock(&tsMnodeLock) #define mnodeMnodeWrLock() pthread_mutex_lock(&tsMnodeLock)
#define mgmtMnodeRdLock() pthread_mutex_lock(&tsMnodeLock) #define mnodeMnodeRdLock() pthread_mutex_lock(&tsMnodeLock)
#define mgmtMnodeUnLock() pthread_mutex_unlock(&tsMnodeLock) #define mnodeMnodeUnLock() pthread_mutex_unlock(&tsMnodeLock)
#define mgmtMnodeInitLock() pthread_mutex_init(&tsMnodeLock, NULL) #define mnodeMnodeInitLock() pthread_mutex_init(&tsMnodeLock, NULL)
#define mgmtMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock) #define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
#endif #endif
static int32_t mgmtMnodeActionDestroy(SSdbOper *pOper) { static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) {
tfree(pOper->pObj); tfree(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionInsert(SSdbOper *pOper) { static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
SDnodeObj *pDnode = mgmtGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST;
pDnode->isMgmt = true; pDnode->isMgmt = true;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionDelete(SSdbOper *pOper) { static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
SDnodeObj *pDnode = mgmtGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST;
pDnode->isMgmt = false; pDnode->isMgmt = false;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
mTrace("mnode:%d, is dropped from sdb", pMnode->mnodeId); mTrace("mnode:%d, is dropped from sdb", pMnode->mnodeId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionUpdate(SSdbOper *pOper) { static int32_t mnodeMnodeActionUpdate(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
SMnodeObj *pSaved = mgmtGetMnode(pMnode->mnodeId); SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId);
if (pMnode != pSaved) { if (pMnode != pSaved) {
memcpy(pSaved, pMnode, pOper->rowSize); memcpy(pSaved, pMnode, pOper->rowSize);
free(pMnode); free(pMnode);
} }
mgmtDecMnodeRef(pSaved); mnodeDecMnodeRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeMnodeActionEncode(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
memcpy(pOper->rowData, pMnode, tsMnodeUpdateSize); memcpy(pOper->rowData, pMnode, tsMnodeUpdateSize);
pOper->rowSize = tsMnodeUpdateSize; pOper->rowSize = tsMnodeUpdateSize;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionDecode(SSdbOper *pOper) { static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) {
SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj));
if (pMnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pMnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -110,24 +110,24 @@ static int32_t mgmtMnodeActionDecode(SSdbOper *pOper) { ...@@ -110,24 +110,24 @@ static int32_t mgmtMnodeActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtMnodeActionRestored() { static int32_t mnodeMnodeActionRestored() {
if (mgmtGetMnodesNum() == 1) { if (mnodeGetMnodesNum() == 1) {
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
void *pIter = mgmtGetNextMnode(NULL, &pMnode); void *pIter = mnodeGetNextMnode(NULL, &pMnode);
if (pMnode != NULL) { if (pMnode != NULL) {
pMnode->role = TAOS_SYNC_ROLE_MASTER; pMnode->role = TAOS_SYNC_ROLE_MASTER;
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
} }
mgmtUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitMnodes() { int32_t mnodeInitMnodes() {
mgmtMnodeInitLock(); mnodeMnodeInitLock();
SMnodeObj tObj; SMnodeObj tObj;
tsMnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsMnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -139,13 +139,13 @@ int32_t mgmtInitMnodes() { ...@@ -139,13 +139,13 @@ int32_t mgmtInitMnodes() {
.maxRowSize = tsMnodeUpdateSize, .maxRowSize = tsMnodeUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_INT, .keyType = SDB_KEY_INT,
.insertFp = mgmtMnodeActionInsert, .insertFp = mnodeMnodeActionInsert,
.deleteFp = mgmtMnodeActionDelete, .deleteFp = mnodeMnodeActionDelete,
.updateFp = mgmtMnodeActionUpdate, .updateFp = mnodeMnodeActionUpdate,
.encodeFp = mgmtMnodeActionEncode, .encodeFp = mnodeMnodeActionEncode,
.decodeFp = mgmtMnodeActionDecode, .decodeFp = mnodeMnodeActionDecode,
.destroyFp = mgmtMnodeActionDestroy, .destroyFp = mnodeMnodeActionDestroy,
.restoredFp = mgmtMnodeActionRestored .restoredFp = mnodeMnodeActionRestored
}; };
tsMnodeSdb = sdbOpenTable(&tableDesc); tsMnodeSdb = sdbOpenTable(&tableDesc);
...@@ -154,8 +154,8 @@ int32_t mgmtInitMnodes() { ...@@ -154,8 +154,8 @@ int32_t mgmtInitMnodes() {
return -1; return -1;
} }
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_MNODE, mgmtGetMnodeMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_MNODE, mnodeGetMnodeMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_MNODE, mgmtRetrieveMnodes); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_MNODE, mnodeRetrieveMnodes);
mTrace("table:mnodes table is created"); mTrace("table:mnodes table is created");
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -163,30 +163,30 @@ int32_t mgmtInitMnodes() { ...@@ -163,30 +163,30 @@ int32_t mgmtInitMnodes() {
void mgmtCleanupMnodes() { void mgmtCleanupMnodes() {
sdbCloseTable(tsMnodeSdb); sdbCloseTable(tsMnodeSdb);
mgmtMnodeDestroyLock(); mnodeMnodeDestroyLock();
} }
int32_t mgmtGetMnodesNum() { int32_t mnodeGetMnodesNum() {
return sdbGetNumOfRows(tsMnodeSdb); return sdbGetNumOfRows(tsMnodeSdb);
} }
void *mgmtGetMnode(int32_t mnodeId) { void *mnodeGetMnode(int32_t mnodeId) {
return sdbGetRow(tsMnodeSdb, &mnodeId); return sdbGetRow(tsMnodeSdb, &mnodeId);
} }
void mgmtIncMnodeRef(SMnodeObj *pMnode) { void mnodeIncMnodeRef(SMnodeObj *pMnode) {
sdbIncRef(tsMnodeSdb, pMnode); sdbIncRef(tsMnodeSdb, pMnode);
} }
void mgmtDecMnodeRef(SMnodeObj *pMnode) { void mnodeDecMnodeRef(SMnodeObj *pMnode) {
sdbDecRef(tsMnodeSdb, pMnode); sdbDecRef(tsMnodeSdb, pMnode);
} }
void *mgmtGetNextMnode(void *pIter, SMnodeObj **pMnode) { void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) {
return sdbFetchRow(tsMnodeSdb, pIter, (void **)pMnode); return sdbFetchRow(tsMnodeSdb, pIter, (void **)pMnode);
} }
char *mgmtGetMnodeRoleStr(int32_t role) { char *mnodeGetMnodeRoleStr(int32_t role) {
switch (role) { switch (role) {
case TAOS_SYNC_ROLE_OFFLINE: case TAOS_SYNC_ROLE_OFFLINE:
return "offline"; return "offline";
...@@ -201,68 +201,79 @@ char *mgmtGetMnodeRoleStr(int32_t role) { ...@@ -201,68 +201,79 @@ char *mgmtGetMnodeRoleStr(int32_t role) {
} }
} }
void mgmtUpdateMnodeIpSet() { void mnodeUpdateMnodeIpSet() {
SRpcIpSet *ipSet = &tsMnodeRpcIpSet; SRpcIpSet *ipSetForShell = &tsMnodeRpcIpSetForShell;
SRpcIpSet *ipSetForPeer = &tsMnodeRpcIpSetForPeer;
SDMMnodeInfos *mnodes = &tsMnodeInfos; SDMMnodeInfos *mnodes = &tsMnodeInfos;
mPrint("update mnodes ipset, numOfIps:%d ", mgmtGetMnodesNum()); mPrint("update mnodes ipset, numOfIps:%d ", mnodeGetMnodesNum());
mgmtMnodeWrLock(); mnodeMnodeWrLock();
memset(ipSet, 0, sizeof(tsMnodeRpcIpSet)); memset(ipSetForShell, 0, sizeof(SRpcIpSet));
memset(ipSetForPeer, 0, sizeof(SRpcIpSet));
memset(mnodes, 0, sizeof(SDMMnodeInfos)); memset(mnodes, 0, sizeof(SDMMnodeInfos));
int32_t index = 0; int32_t index = 0;
void * pIter = NULL; void * pIter = NULL;
while (1) { while (1) {
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
pIter = mgmtGetNextMnode(pIter, &pMnode); pIter = mnodeGetNextMnode(pIter, &pMnode);
if (pMnode == NULL) break; if (pMnode == NULL) break;
SDnodeObj *pDnode = mgmtGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
strcpy(ipSet->fqdn[ipSet->numOfIps], pDnode->dnodeFqdn); strcpy(ipSetForShell->fqdn[ipSetForShell->numOfIps], pDnode->dnodeFqdn);
ipSet->port[ipSet->numOfIps] = htons(pDnode->dnodePort); 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); mnodes->nodeInfos[index].nodeId = htonl(pMnode->mnodeId);
strcpy(mnodes->nodeInfos[index].nodeEp, pDnode->dnodeEp); strcpy(mnodes->nodeInfos[index].nodeEp, pDnode->dnodeEp);
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) { if (pMnode->role == TAOS_SYNC_ROLE_MASTER) {
ipSet->inUse = ipSet->numOfIps; ipSetForShell->inUse = index;
ipSetForPeer->inUse = index;
mnodes->inUse = index; mnodes->inUse = index;
} }
mPrint("mnode:%d, ep:%s %s", index, pDnode->dnodeEp, mPrint("mnode:%d, ep:%s %s", index, pDnode->dnodeEp, pMnode->role == TAOS_SYNC_ROLE_MASTER ? "master" : "");
pMnode->role == TAOS_SYNC_ROLE_MASTER ? "master" : "");
ipSet->numOfIps++;
index++; index++;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
mnodes->nodeNum = index; mnodes->nodeNum = index;
ipSetForPeer->numOfIps = index;
ipSetForPeer->numOfIps = index;
sdbFreeIter(pIter); sdbFreeIter(pIter);
mgmtMnodeUnLock(); mnodeMnodeUnLock();
}
void mnodeGetMnodeIpSetForPeer(SRpcIpSet *ipSet) {
mnodeMnodeRdLock();
*ipSet = tsMnodeRpcIpSetForShell;
mnodeMnodeUnLock();
} }
void mgmtGetMnodeIpSet(SRpcIpSet *ipSet) { void mnodeGetMnodeIpSetForShell(SRpcIpSet *ipSet) {
mgmtMnodeRdLock(); mnodeMnodeRdLock();
*ipSet = tsMnodeRpcIpSet; *ipSet = tsMnodeRpcIpSetForShell;
mgmtMnodeUnLock(); mnodeMnodeUnLock();
} }
void mgmtGetMnodeInfos(void *mnodeInfos) { void mnodeGetMnodeInfos(void *mnodeInfos) {
mgmtMnodeRdLock(); mnodeMnodeRdLock();
*(SDMMnodeInfos *)mnodeInfos = tsMnodeInfos; *(SDMMnodeInfos *)mnodeInfos = tsMnodeInfos;
mgmtMnodeUnLock(); mnodeMnodeUnLock();
} }
int32_t mgmtAddMnode(int32_t dnodeId) { int32_t mnodeAddMnode(int32_t dnodeId) {
SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj));
pMnode->mnodeId = dnodeId; pMnode->mnodeId = dnodeId;
pMnode->createdTime = taosGetTimestampMs(); pMnode->createdTime = taosGetTimestampMs();
...@@ -279,24 +290,24 @@ int32_t mgmtAddMnode(int32_t dnodeId) { ...@@ -279,24 +290,24 @@ int32_t mgmtAddMnode(int32_t dnodeId) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
} }
mgmtUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
return code; return code;
} }
void mgmtDropMnodeLocal(int32_t dnodeId) { void mnodeDropMnodeLocal(int32_t dnodeId) {
SMnodeObj *pMnode = mgmtGetMnode(dnodeId); SMnodeObj *pMnode = mnodeGetMnode(dnodeId);
if (pMnode != NULL) { if (pMnode != NULL) {
SSdbOper oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode}; SSdbOper oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode};
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
mgmtUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
} }
int32_t mgmtDropMnode(int32_t dnodeId) { int32_t mnodeDropMnode(int32_t dnodeId) {
SMnodeObj *pMnode = mgmtGetMnode(dnodeId); SMnodeObj *pMnode = mnodeGetMnode(dnodeId);
if (pMnode == NULL) { if (pMnode == NULL) {
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_DNODE_NOT_EXIST;
} }
...@@ -314,18 +325,18 @@ int32_t mgmtDropMnode(int32_t dnodeId) { ...@@ -314,18 +325,18 @@ int32_t mgmtDropMnode(int32_t dnodeId) {
sdbDecRef(tsMnodeSdb, pMnode); sdbDecRef(tsMnodeSdb, pMnode);
mgmtUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
return code; return code;
} }
static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
sdbUpdateMnodeRoles(); sdbUpdateMnodeRoles();
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
...@@ -364,22 +375,22 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -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->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
} }
pShow->numOfRows = mgmtGetMnodesNum(); pShow->numOfRows = mnodeGetMnodesNum();
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
pShow->pIter = NULL; pShow->pIter = NULL;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
int32_t cols = 0; int32_t cols = 0;
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
char *pWrite; char *pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextMnode(pShow->pIter, &pMnode); pShow->pIter = mnodeGetNextMnode(pShow->pIter, &pMnode);
if (pMnode == NULL) break; if (pMnode == NULL) break;
cols = 0; cols = 0;
...@@ -390,18 +401,18 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -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; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
SDnodeObj *pDnode = mgmtGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE);
} else { } else {
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols] - VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols] - VARSTR_HEADER_SIZE);
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char* roles = mgmtGetMnodeRoleStr(pMnode->role); char* roles = mnodeGetMnodeRoleStr(pMnode->role);
STR_TO_VARSTR(pWrite, roles); STR_TO_VARSTR(pWrite, roles);
cols++; cols++;
...@@ -411,7 +422,7 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -411,7 +422,7 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
numOfRows++; numOfRows++;
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
......
...@@ -23,38 +23,43 @@ ...@@ -23,38 +23,43 @@
#include "tgrant.h" #include "tgrant.h"
#include "tbalance.h" #include "tbalance.h"
#include "tglobal.h" #include "tglobal.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeDb.h" #include "mnodeDb.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeVgroup.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 mnodeAddMgmtMsgHandle(uint8_t msgType, void (*fp)(SMnodeMsg *pMsg)) { void mnodeAddPeerMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) {
tsMnodeProcessMgmtMsgFp[msgType] = fp; tsMnodeProcessPeerMsgFp[msgType] = fp;
} }
int32_t mnodeProcessMgmt(SMnodeMsg *pMsg) { void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) {
SRpcMsg *rpcMsg = &pMsg->rpcMsg; tsMnodeProcessPeerRspFp[msgType] = fp;
if (rpcMsg->pCont == NULL) { }
mError("%p, msg:%s content is null", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]);
int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
if (pMsg->pCont == NULL) {
mError("msg:%s content is null", taosMsg[pMsg->msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet)); SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet));
mgmtGetMnodeIpSetForPeer(ipSet); mnodeGetMnodeIpSetForPeer(ipSet);
rpcRsp->rsp = ipSet; rpcRsp->rsp = ipSet;
rpcRsp->len = sizeof(SRpcIpSet); rpcRsp->len = sizeof(SRpcIpSet);
mTrace("%p, msg:%s will be redireced, inUse:%d", rpcMsg->ahandle, taosMsg[rpcMsg->msgType], ipSet->inUse); mTrace("msg:%s will be redireced, inUse:%d", taosMsg[pMsg->msgType], ipSet->inUse);
for (int32_t i = 0; i < ipSet->numOfIps; ++i) { for (int32_t i = 0; i < ipSet->numOfIps; ++i) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[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) { ...@@ -62,10 +67,20 @@ int32_t mnodeProcessMgmt(SMnodeMsg *pMsg) {
return TSDB_CODE_REDIRECT; return TSDB_CODE_REDIRECT;
} }
if (tsMnodeProcessMgmtMsgFp[rpcMsg->msgType] == NULL) { if (tsMnodeProcessPeerMsgFp[pMsg->msgType] == NULL) {
mError("%p, msg:%s not processed, no handle exist", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]); mError("msg:%s not processed, no handle exist", taosMsg[pMsg->msgType]);
return TSDB_CODE_MSG_NOT_PROCESSED; 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);
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "taosmsg.h" #include "taosmsg.h"
#include "taoserror.h" #include "taoserror.h"
#include "tutil.h" #include "tutil.h"
#include "mnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
...@@ -25,16 +26,17 @@ ...@@ -25,16 +26,17 @@
#include "mnodeDb.h" #include "mnodeDb.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeWrite.h"
int32_t mgmtSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg); int32_t mnodeSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg);
int32_t mgmtKillQuery(char *qidstr, void *pConn); int32_t mnodeKillQuery(char *qidstr, void *pConn);
int32_t mgmtKillStream(char *qidstr, void *pConn); int32_t mnodeKillStream(char *qidstr, void *pConn);
int32_t mgmtKillConnection(char *qidstr, void *pConn); int32_t mnodeKillConnection(char *qidstr, void *pConn);
typedef struct { typedef struct {
char user[TSDB_TABLE_ID_LEN + 1]; char user[TSDB_TABLE_ID_LEN + 1];
...@@ -98,7 +100,7 @@ int32_t mgmtSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg) { ...@@ -98,7 +100,7 @@ int32_t mgmtSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtGetQueries(SShowObj *pShow, void *pConn) { int32_t mnodeGetQueries(SShowObj *pShow, void *pConn) {
// SAcctObj * pAcct = pConn->pAcct; // SAcctObj * pAcct = pConn->pAcct;
// SQueryShow *pQueryShow; // SQueryShow *pQueryShow;
// //
...@@ -145,7 +147,7 @@ int32_t mgmtGetQueries(SShowObj *pShow, void *pConn) { ...@@ -145,7 +147,7 @@ int32_t mgmtGetQueries(SShowObj *pShow, void *pConn) {
return 0; return 0;
} }
int32_t mgmtGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
...@@ -190,11 +192,11 @@ int32_t mgmtGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -190,11 +192,11 @@ int32_t mgmtGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow->pIter = NULL; pShow->pIter = NULL;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtGetQueries(pShow, pConn); mnodeGetQueries(pShow, pConn);
return 0; return 0;
} }
int32_t mgmtKillQuery(char *qidstr, void *pConn) { int32_t mnodeKillQuery(char *qidstr, void *pConn) {
// char *temp, *chr, idstr[64]; // char *temp, *chr, idstr[64];
// strcpy(idstr, qidstr); // strcpy(idstr, qidstr);
// //
...@@ -247,7 +249,7 @@ int32_t mgmtKillQuery(char *qidstr, void *pConn) { ...@@ -247,7 +249,7 @@ int32_t mgmtKillQuery(char *qidstr, void *pConn) {
return TSDB_CODE_INVALID_QUERY_ID; return TSDB_CODE_INVALID_QUERY_ID;
} }
int32_t mgmtRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
char *pWrite; char *pWrite;
int32_t cols = 0; int32_t cols = 0;
...@@ -297,7 +299,7 @@ int32_t mgmtRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -297,7 +299,7 @@ int32_t mgmtRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pCo
return numOfRows; return numOfRows;
} }
int32_t mgmtGetStreams(SShowObj *pShow, void *pConn) { int32_t mnodeGetStreams(SShowObj *pShow, void *pConn) {
// SAcctObj * pAcct = pConn->pAcct; // SAcctObj * pAcct = pConn->pAcct;
// SStreamShow *pStreamShow; // SStreamShow *pStreamShow;
// //
...@@ -344,7 +346,7 @@ int32_t mgmtGetStreams(SShowObj *pShow, void *pConn) { ...@@ -344,7 +346,7 @@ int32_t mgmtGetStreams(SShowObj *pShow, void *pConn) {
return 0; return 0;
} }
int32_t mgmtGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
...@@ -400,11 +402,11 @@ int32_t mgmtGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -400,11 +402,11 @@ int32_t mgmtGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow->pIter = NULL; pShow->pIter = NULL;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtGetStreams(pShow, pConn); mnodeGetStreams(pShow, pConn);
return 0; return 0;
} }
int32_t mgmtRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
char *pWrite; char *pWrite;
int32_t cols = 0; int32_t cols = 0;
...@@ -462,7 +464,7 @@ int32_t mgmtRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -462,7 +464,7 @@ int32_t mgmtRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pCo
return numOfRows; return numOfRows;
} }
int32_t mgmtKillStream(char *qidstr, void *pConn) { int32_t mnodeKillStream(char *qidstr, void *pConn) {
// char *temp, *chr, idstr[64]; // char *temp, *chr, idstr[64];
// strcpy(idstr, qidstr); // strcpy(idstr, qidstr);
// //
...@@ -515,7 +517,7 @@ int32_t mgmtKillStream(char *qidstr, void *pConn) { ...@@ -515,7 +517,7 @@ int32_t mgmtKillStream(char *qidstr, void *pConn) {
return TSDB_CODE_INVALID_STREAM_ID; return TSDB_CODE_INVALID_STREAM_ID;
} }
int32_t mgmtKillConnection(char *qidstr, void *pConn) { int32_t mnodeKillConnection(char *qidstr, void *pConn) {
// void *pConn1 = NULL; // void *pConn1 = NULL;
// char * temp, *chr, idstr[64]; // char * temp, *chr, idstr[64];
// strcpy(idstr, qidstr); // strcpy(idstr, qidstr);
...@@ -562,7 +564,7 @@ int32_t mgmtKillConnection(char *qidstr, void *pConn) { ...@@ -562,7 +564,7 @@ int32_t mgmtKillConnection(char *qidstr, void *pConn) {
} }
int mgmtGetConns(SShowObj *pShow, void *pConn) { int mnodeGetConns(SShowObj *pShow, void *pConn) {
// SAcctObj * pAcct = pConn->pAcct; // SAcctObj * pAcct = pConn->pAcct;
// SConnShow *pConnShow; // SConnShow *pConnShow;
// //
...@@ -597,7 +599,7 @@ int mgmtGetConns(SShowObj *pShow, void *pConn) { ...@@ -597,7 +599,7 @@ int mgmtGetConns(SShowObj *pShow, void *pConn) {
return 0; return 0;
} }
int32_t mgmtGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
...@@ -630,11 +632,11 @@ int32_t mgmtGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -630,11 +632,11 @@ int32_t mgmtGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow->pIter = NULL; pShow->pIter = NULL;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtGetConns(pShow, pConn); mnodeGetConns(pShow, pConn);
return 0; return 0;
} }
int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
char *pWrite; char *pWrite;
int32_t cols = 0; int32_t cols = 0;
...@@ -672,91 +674,94 @@ int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn ...@@ -672,91 +674,94 @@ int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn
return numOfRows; return numOfRows;
} }
void mgmtProcessKillQueryMsg(SMnodeMsg *pMsg) { int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle); // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { // if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; // rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
return; // return;
} // }
SCMKillQueryMsg *pKill = pMsg->pCont; // SCMKillQueryMsg *pKill = pMsg->pCont;
int32_t code; // int32_t code;
if (!pUser->writeAuth) { // if (!pUser->writeAuth) {
code = TSDB_CODE_NO_RIGHTS; // code = TSDB_CODE_NO_RIGHTS;
} else { // } else {
code = mgmtKillQuery(pKill->queryId, pMsg->thandle); // code = mgmtKillQuery(pKill->queryId, pMsg->thandle);
} // }
rpcRsp.code = code; // rpcRsp.code = code;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
mgmtDecUserRef(pUser); // mnodeDecUserRef(pUser);
return TSDB_CODE_SUCCESS;
} }
void mgmtProcessKillStreamMsg(SMnodeMsg *pMsg) { int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle); // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { // if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; // rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
return; // return;
} // }
SCMKillStreamMsg *pKill = pMsg->pCont; // SCMKillStreamMsg *pKill = pMsg->pCont;
int32_t code; // int32_t code;
if (!pUser->writeAuth) { // if (!pUser->writeAuth) {
code = TSDB_CODE_NO_RIGHTS; // code = TSDB_CODE_NO_RIGHTS;
} else { // } else {
code = mgmtKillStream(pKill->queryId, pMsg->thandle); // code = mgmtKillStream(pKill->queryId, pMsg->thandle);
} // }
rpcRsp.code = code; // rpcRsp.code = code;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
mgmtDecUserRef(pUser); // mnodeDecUserRef(pUser);
return TSDB_CODE_SUCCESS;
} }
void mgmtProcessKillConnectionMsg(SMnodeMsg *pMsg) { int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle); // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { // if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; // rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
return; // return;
} // }
SCMKillConnMsg *pKill = pMsg->pCont; // SCMKillConnMsg *pKill = pMsg->pCont;
int32_t code; // int32_t code;
if (!pUser->writeAuth) { // if (!pUser->writeAuth) {
code = TSDB_CODE_NO_RIGHTS; // code = TSDB_CODE_NO_RIGHTS;
} else { // } else {
code = mgmtKillConnection(pKill->queryId, pMsg->thandle); // code = mgmtKillConnection(pKill->queryId, pMsg->thandle);
} // }
rpcRsp.code = code; // rpcRsp.code = code;
rpcSendResponse(&rpcRsp); // rpcSendResponse(&rpcRsp);
mgmtDecUserRef(pUser); // mnodeDecUserRef(pUser);
return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitProfile() { int32_t mnodeInitProfile() {
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_QUERIES, mgmtGetQueryMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_QUERIES, mnodeGetQueryMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_QUERIES, mgmtRetrieveQueries); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_QUERIES, mnodeRetrieveQueries);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_CONNS, mgmtGetConnsMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONNS, mnodeGetConnsMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_CONNS, mgmtRetrieveConns); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONNS, mnodeRetrieveConns);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_STREAMS, mgmtGetStreamMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMS, mnodeGetStreamMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_STREAMS, mgmtRetrieveStreams); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMS, mnodeRetrieveStreams);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mgmtProcessKillQueryMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mnodeProcessKillQueryMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mgmtProcessKillStreamMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mnodeProcessKillStreamMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_KILL_CONN, mgmtProcessKillConnectionMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_CONN, mnodeProcessKillConnectionMsg);
return 0; return 0;
} }
void mgmtCleanUpProfile() { void mnodeCleanupProfile() {
} }
...@@ -24,39 +24,37 @@ ...@@ -24,39 +24,37 @@
#include "mnode.h" #include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mgmtInt.h" #include "mnodeInt.h"
#include "mgmtServer.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mgmtDnode.h" #include "mnodeDnode.h"
#include "mgmtMnode.h" #include "mnodeMnode.h"
#include "mnodeDb.h" #include "mnodeDb.h"
#include "mgmtSdb.h" #include "mnodeSdb.h"
#include "mgmtVgroup.h" #include "mnodeVgroup.h"
#include "mgmtUser.h" #include "mnodeUser.h"
#include "mgmtTable.h" #include "mnodeTable.h"
#include "mgmtShell.h" #include "mnodeShow.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; tsMnodeProcessReadMsgFp[msgType] = fp;
} }
int32_t mnodeProcessRead(SMnodeMsg *pMsg) { int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
SRpcMsg *rpcMsg = &pMsg->rpcMsg; if (pMsg->pCont == NULL) {
if (rpcMsg->pCont == NULL) { mError("msg:%s content is null", taosMsg[pMsg->msgType]);
mError("%p, msg:%s content is null", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet)); SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet));
mgmtGetMnodeIpSetForShell(ipSet); mnodeGetMnodeIpSetForShell(ipSet);
rpcRsp->rsp = ipSet; rpcRsp->rsp = ipSet;
rpcRsp->len = sizeof(SRpcIpSet); rpcRsp->len = sizeof(SRpcIpSet);
mTrace("%p, msg:%s will be redireced, inUse:%d", rpcMsg->ahandle, taosMsg[rpcMsg->msgType], ipSet->inUse); mTrace("msg:%s will be redireced, inUse:%d", taosMsg[pMsg->msgType], ipSet->inUse);
for (int32_t i = 0; i < ipSet->numOfIps; ++i) { for (int32_t i = 0; i < ipSet->numOfIps; ++i) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[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) { ...@@ -64,20 +62,15 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
return TSDB_CODE_REDIRECT; return TSDB_CODE_REDIRECT;
} }
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (tsMnodeProcessReadMsgFp[pMsg->msgType] == NULL) {
mError("%p, msg:%s not processed, grant time expired", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]); mError("msg:%s not processed, no handle exist", taosMsg[pMsg->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]);
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MSG_NOT_PROCESSED;
} }
if (!mnodeInitMsg(pMsg)) { if (!mnodeInitMsg(pMsg)) {
mError("%p, msg:%s not processed, reason:%s", rpcMsg->ahandle, taosMsg[rpcMsg->msgType], tstrerror(terrno)); mError("msg:%s not processed, reason:%s", taosMsg[pMsg->msgType], tstrerror(terrno));
return terrno; return terrno;
} }
return (*tsMgmtProcessShellMsgFp[rpcMsg->msgType])(pMsg); return (*tsMnodeProcessReadMsgFp[pMsg->msgType])(pMsg);
} }
...@@ -189,16 +189,16 @@ void sdbUpdateMnodeRoles() { ...@@ -189,16 +189,16 @@ void sdbUpdateMnodeRoles() {
sdbPrint("update mnodes:%d sync roles", tsSdbObj.cfg.replica); sdbPrint("update mnodes:%d sync roles", tsSdbObj.cfg.replica);
for (int32_t i = 0; i < tsSdbObj.cfg.replica; ++i) { for (int32_t i = 0; i < tsSdbObj.cfg.replica; ++i) {
SMnodeObj *pMnode = mgmtGetMnode(roles.nodeId[i]); SMnodeObj *pMnode = mnodeGetMnode(roles.nodeId[i]);
if (pMnode != NULL) { if (pMnode != NULL) {
pMnode->role = roles.role[i]; pMnode->role = roles.role[i];
sdbPrint("mnode:%d, role:%s", pMnode->mnodeId, mgmtGetMnodeRoleStr(pMnode->role)); sdbPrint("mnode:%d, role:%s", pMnode->mnodeId, mnodeGetMnodeRoleStr(pMnode->role));
if (pMnode->mnodeId == dnodeGetDnodeId()) tsSdbObj.role = pMnode->role; if (pMnode->mnodeId == dnodeGetDnodeId()) tsSdbObj.role = pMnode->role;
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
} }
mgmtUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
} }
static uint32_t sdbGetFileInfo(void *ahandle, char *name, uint32_t *index, int32_t *size, uint64_t *fversion) { 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) { ...@@ -211,7 +211,7 @@ static int sdbGetWalInfo(void *ahandle, char *name, uint32_t *index) {
} }
static void sdbNotifyRole(void *ahandle, int8_t role) { static void sdbNotifyRole(void *ahandle, int8_t role) {
sdbPrint("mnode role changed from %s to %s", mgmtGetMnodeRoleStr(tsSdbObj.role), mgmtGetMnodeRoleStr(role)); sdbPrint("mnode role changed from %s to %s", mnodeGetMnodeRoleStr(tsSdbObj.role), mnodeGetMnodeRoleStr(role));
if (role == TAOS_SYNC_ROLE_MASTER && tsSdbObj.role != TAOS_SYNC_ROLE_MASTER) { if (role == TAOS_SYNC_ROLE_MASTER && tsSdbObj.role != TAOS_SYNC_ROLE_MASTER) {
balanceReset(); balanceReset();
...@@ -256,20 +256,20 @@ void sdbUpdateSync() { ...@@ -256,20 +256,20 @@ void sdbUpdateSync() {
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
pIter = mgmtGetNextMnode(pIter, &pMnode); pIter = mnodeGetNextMnode(pIter, &pMnode);
if (pMnode == NULL) break; if (pMnode == NULL) break;
syncCfg.nodeInfo[index].nodeId = pMnode->mnodeId; syncCfg.nodeInfo[index].nodeId = pMnode->mnodeId;
SDnodeObj *pDnode = mgmtGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
syncCfg.nodeInfo[index].nodePort = pDnode->dnodePort + TSDB_PORT_SYNC; syncCfg.nodeInfo[index].nodePort = pDnode->dnodePort + TSDB_PORT_SYNC;
strcpy(syncCfg.nodeInfo[index].nodeFqdn, pDnode->dnodeEp); strcpy(syncCfg.nodeInfo[index].nodeFqdn, pDnode->dnodeEp);
index++; index++;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
mgmtDecMnodeRef(pMnode); mnodeDecMnodeRef(pMnode);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
} }
...@@ -324,7 +324,7 @@ int32_t sdbInit() { ...@@ -324,7 +324,7 @@ int32_t sdbInit() {
sdbRestoreTables(); sdbRestoreTables();
if (mgmtGetMnodesNum() == 1) { if (mnodeGetMnodesNum() == 1) {
tsSdbObj.role = TAOS_SYNC_ROLE_MASTER; tsSdbObj.role = TAOS_SYNC_ROLE_MASTER;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "tgrant.h" #include "tgrant.h"
#include "tglobal.h" #include "tglobal.h"
#include "tcache.h" #include "tcache.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
...@@ -33,33 +34,38 @@ ...@@ -33,33 +34,38 @@
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeWrite.h"
#include "mnodeRead.h"
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeProcessShowMsg(SMnodeMsg *mnodeMsg);
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn); 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 mnodeFreeShowObj(void *data);
static void mnodeProcessRetrieveMsg(SMnodeMsg *queuedMsg); static bool mnodeCheckQhandle(uint64_t qhandle);
static void mnodeProcessHeartBeatMsg(SMnodeMsg *queuedMsg); static void *mnodeSaveQhandle(void *qhandle, int32_t size);
static void mnodeProcessConnectMsg(SMnodeMsg *queuedMsg); static void mnodeFreeQhandle(void *qhandle, bool forceRemove);
static void mnodeProcessUseMsg(SMnodeMsg *queuedMsg);
static void mnodeFreeShowObj(void *data);
extern void *tsMnodeTmr;
static void *tsQhandleCache = NULL; static void *tsQhandleCache = NULL;
static SShowMetaFp tsMnodeShowMetaFp[TSDB_MNODE_TABLE_MAX] = {0}; static SShowMetaFp tsMnodeShowMetaFp[TSDB_MGMT_TABLE_MAX] = {0};
static SShowRetrieveFp tsMnodeShowRetrieveFp[TSDB_MNODE_TABLE_MAX] = {0}; static SShowRetrieveFp tsMnodeShowRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0};
void mnodeInitShow() { int32_t mnodeInitShow() {
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_SHOW, mnodeProcessShowMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_SHOW, mnodeProcessShowMsg);
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_RETRIEVE, mnodeProcessRetrieveMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_RETRIEVE, mnodeProcessRetrieveMsg);
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_HEARTBEAT, mnodeProcessHeartBeatMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_HEARTBEAT, mnodeProcessHeartBeatMsg);
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg);
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg);
tsQhandleCache = taosCacheInitWithCb(tsMgmtTmr, 10, mnodeFreeShowObj); tsQhandleCache = taosCacheInitWithCb(tsMnodeTmr, 10, mnodeFreeShowObj);
return 0;
} }
void mnodeCleanUpShow() { void mnodeCleanUpShow() {
...@@ -77,46 +83,43 @@ void mnodeAddShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) { ...@@ -77,46 +83,43 @@ void mnodeAddShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
tsMnodeShowRetrieveFp[msgType] = fp; tsMnodeShowRetrieveFp[msgType] = fp;
} }
char *mnodeGetShowType(int32_t showType) { static char *mnodeGetShowType(int32_t showType) {
switch (showType) { switch (showType) {
case TSDB_MNODE_TABLE_ACCT: return "show accounts"; case TSDB_MGMT_TABLE_ACCT: return "show accounts";
case TSDB_MNODE_TABLE_USER: return "show users"; case TSDB_MGMT_TABLE_USER: return "show users";
case TSDB_MNODE_TABLE_DB: return "show databases"; case TSDB_MGMT_TABLE_DB: return "show databases";
case TSDB_MNODE_TABLE_TABLE: return "show tables"; case TSDB_MGMT_TABLE_TABLE: return "show tables";
case TSDB_MNODE_TABLE_DNODE: return "show dnodes"; case TSDB_MGMT_TABLE_DNODE: return "show dnodes";
case TSDB_MNODE_TABLE_MNODE: return "show mnodes"; case TSDB_MGMT_TABLE_MNODE: return "show mnodes";
case TSDB_MNODE_TABLE_VGROUP: return "show vgroups"; case TSDB_MGMT_TABLE_VGROUP: return "show vgroups";
case TSDB_MNODE_TABLE_METRIC: return "show stables"; case TSDB_MGMT_TABLE_METRIC: return "show stables";
case TSDB_MNODE_TABLE_MODULE: return "show modules"; case TSDB_MGMT_TABLE_MODULE: return "show modules";
case TSDB_MNODE_TABLE_QUERIES: return "show queries"; case TSDB_MGMT_TABLE_QUERIES: return "show queries";
case TSDB_MNODE_TABLE_STREAMS: return "show streams"; case TSDB_MGMT_TABLE_STREAMS: return "show streams";
case TSDB_MNODE_TABLE_CONFIGS: return "show configs"; case TSDB_MGMT_TABLE_CONFIGS: return "show configs";
case TSDB_MNODE_TABLE_CONNS: return "show connections"; case TSDB_MGMT_TABLE_CONNS: return "show connections";
case TSDB_MNODE_TABLE_SCORES: return "show scores"; case TSDB_MGMT_TABLE_SCORES: return "show scores";
case TSDB_MNODE_TABLE_GRANTS: return "show grants"; case TSDB_MGMT_TABLE_GRANTS: return "show grants";
case TSDB_MNODE_TABLE_VNODES: return "show vnodes"; case TSDB_MGMT_TABLE_VNODES: return "show vnodes";
default: return "undefined"; default: return "undefined";
} }
} }
static void mnodeProcessShowMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
SCMShowMsg *pShowMsg = pMsg->pCont; SCMShowMsg *pShowMsg = pMsg->pCont;
if (pShowMsg->type >= TSDB_MNODE_TABLE_MAX) { if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_MSG_TYPE); return TSDB_CODE_INVALID_MSG_TYPE;
return;
} }
if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) { if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) {
mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type));
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_OPS_NOT_SUPPORT); return TSDB_CODE_OPS_NOT_SUPPORT;
return;
} }
int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
SCMShowRsp *pShowRsp = rpcMallocCont(size); SCMShowRsp *pShowRsp = rpcMallocCont(size);
if (pShowRsp == NULL) { if (pShowRsp == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen); int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen);
...@@ -127,31 +130,23 @@ static void mnodeProcessShowMsg(SMnodeMsg *pMsg) { ...@@ -127,31 +130,23 @@ static void mnodeProcessShowMsg(SMnodeMsg *pMsg) {
strcpy(pShow->db, pShowMsg->db); strcpy(pShow->db, pShowMsg->db);
memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen); memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen);
pShow = mgmtSaveQhandle(pShow, showObjSize); pShow = mnodeSaveQhandle(pShow, showObjSize);
pShowRsp->qhandle = htobe64((uint64_t) pShow); pShowRsp->qhandle = htobe64((uint64_t) pShow);
mTrace("show:%p, type:%s, start to get meta", pShow, mnodeGetShowType(pShowMsg->type)); mTrace("show:%p, type:%s, start to get meta", pShow, mnodeGetShowType(pShowMsg->type));
int32_t code = (*tsMnodeShowMetaFp[pShowMsg->type])(&pShowRsp->tableMeta, pShow, pMsg->thandle); int32_t code = (*tsMnodeShowMetaFp[pShowMsg->type])(&pShowRsp->tableMeta, pShow, pMsg->thandle);
if (code == 0) { if (code == 0) {
SRpcMsg rpcRsp = { pMsg->rpcRsp.rsp = pShowRsp;
.handle = pMsg->thandle, pMsg->rpcRsp.len = sizeof(SCMShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
.pCont = pShowRsp, return TSDB_CODE_SUCCESS;
.contLen = sizeof(SCMShowRsp) + sizeof(SSchema) * pShow->numOfColumns,
.code = code
};
rpcSendResponse(&rpcRsp);
} else { } else {
mError("show:%p, type:%s, failed to get meta, reason:%s", pShow, mnodeGetShowType(pShowMsg->type), tstrerror(code)); mError("show:%p, type:%s, failed to get meta, reason:%s", pShow, mnodeGetShowType(pShowMsg->type), tstrerror(code));
mgmtFreeQhandle(pShow, false); mnodeFreeQhandle(pShow, true);
SRpcMsg rpcRsp = { return code;
.handle = pMsg->thandle,
.code = code
};
rpcSendResponse(&rpcRsp);
} }
} }
static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
int32_t rowsToRead = 0; int32_t rowsToRead = 0;
int32_t size = 0; int32_t size = 0;
int32_t rowsRead = 0; int32_t rowsRead = 0;
...@@ -162,10 +157,9 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { ...@@ -162,10 +157,9 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
* in case of server restart, apps may hold qhandle created by server before * in case of server restart, apps may hold qhandle created by server before
* restart, which is actually invalid, therefore, signature check is required. * restart, which is actually invalid, therefore, signature check is required.
*/ */
if (!mgmtCheckQhandle(pRetrieve->qhandle)) { if (!mnodeCheckQhandle(pRetrieve->qhandle)) {
mError("retrieve:%p, qhandle:%p is invalid", pRetrieve, pRetrieve->qhandle); mError("retrieve:%p, qhandle:%p is invalid", pRetrieve, pRetrieve->qhandle);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_QHANDLE); return TSDB_CODE_INVALID_QHANDLE;
return;
} }
SShowObj *pShow = (SShowObj *)pRetrieve->qhandle; SShowObj *pShow = (SShowObj *)pRetrieve->qhandle;
...@@ -192,41 +186,37 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { ...@@ -192,41 +186,37 @@ static void mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE)
rowsRead = (*tsMnodeShowRetrieveFp[pShow->type])(pShow, pRsp->data, rowsToRead, pMsg->thandle); rowsRead = (*tsMnodeShowRetrieveFp[pShow->type])(pShow, pRsp->data, rowsToRead, pMsg->thandle);
if (rowsRead < 0) { // TSDB_CODE_ACTION_IN_PROGRESS; if (rowsRead < 0) {
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
mgmtFreeQhandle(pShow, false); mnodeFreeQhandle(pShow, false);
return; assert(false);
return TSDB_CODE_ACTION_IN_PROGRESS;
} }
pRsp->numOfRows = htonl(rowsRead); pRsp->numOfRows = htonl(rowsRead);
pRsp->precision = htonl(TSDB_TIME_PRECISION_MILLI); // millisecond time precision pRsp->precision = htonl(TSDB_TIME_PRECISION_MILLI); // millisecond time precision
SRpcMsg rpcRsp = { pMsg->rpcRsp.rsp = pRsp;
.handle = pMsg->thandle, pMsg->rpcRsp.len = size;
.pCont = pRsp,
.contLen = size,
.code = 0,
.msgType = 0
};
rpcSendResponse(&rpcRsp);
if (rowsToRead == 0) { if (rowsToRead == 0) {
mgmtFreeQhandle(pShow, true); mnodeFreeQhandle(pShow, true);
} else { } else {
mgmtFreeQhandle(pShow, false); mnodeFreeQhandle(pShow, false);
} }
return TSDB_CODE_SUCCESS;
} }
static void mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp)); SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp));
if (pHBRsp == NULL) { if (pHBRsp == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
pHBRsp->onlineDnodes = htonl(mgmtGetOnlinDnodesNum()); pHBRsp->onlineDnodes = htonl(mnodeGetOnlinDnodesNum());
pHBRsp->totalDnodes = htonl(mgmtGetDnodesNum()); pHBRsp->totalDnodes = htonl(mnodeGetDnodesNum());
mgmtGetMnodeIpSet(&pHBRsp->ipList); mnodeGetMnodeIpSetForShell(&pHBRsp->ipList);
/* /*
* TODO * TODO
...@@ -236,29 +226,20 @@ static void mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { ...@@ -236,29 +226,20 @@ static void mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
pHBRsp->streamId = 0; pHBRsp->streamId = 0;
pHBRsp->killConnection = 0; pHBRsp->killConnection = 0;
SRpcMsg rpcRsp = { pMsg->rpcRsp.rsp = pHBRsp;
.handle = pMsg->thandle, pMsg->rpcRsp.len = sizeof(SCMHeartBeatRsp);
.pCont = pHBRsp,
.contLen = sizeof(SCMHeartBeatRsp), return TSDB_CODE_SUCCESS;
.code = 0,
.msgType = 0
};
rpcSendResponse(&rpcRsp);
} }
static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMConnectMsg *pConnectMsg = pMsg->pCont; SCMConnectMsg *pConnectMsg = pMsg->pCont;
int32_t code = TSDB_CODE_SUCCESS;
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
if (rpcGetConnInfo(pMsg->thandle, &connInfo) != 0) { if (rpcGetConnInfo(pMsg->thandle, &connInfo) != 0) {
mError("thandle:%p is already released while process connect msg", pMsg->thandle); mError("thandle:%p is already released while process connect msg", pMsg->thandle);
return; code = TSDB_CODE_INVALID_MSG_CONTENT;
}
int32_t code;
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_GRANT_EXPIRED;
goto connect_over; goto connect_over;
} }
...@@ -273,12 +254,12 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) { ...@@ -273,12 +254,12 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
if (pConnectMsg->db[0]) { if (pConnectMsg->db[0]) {
char dbName[TSDB_TABLE_ID_LEN * 3] = {0}; char dbName[TSDB_TABLE_ID_LEN * 3] = {0};
sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db);
SDbObj *pDb = mgmtGetDb(dbName); SDbObj *pDb = mnodeGetDb(dbName);
if (pDb == NULL) { if (pDb == NULL) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_INVALID_DB;
goto connect_over; goto connect_over;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
} }
SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp));
...@@ -292,92 +273,33 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) { ...@@ -292,92 +273,33 @@ static void mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->writeAuth = pUser->writeAuth;
pConnectRsp->superAuth = pUser->superAuth; pConnectRsp->superAuth = pUser->superAuth;
mgmtGetMnodeIpSet(&pConnectRsp->ipList); mnodeGetMnodeIpSetForShell(&pConnectRsp->ipList);
connect_over: connect_over:
rpcRsp.code = code;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
} else { } else {
mLPrint("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); mLPrint("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
rpcRsp.pCont = pConnectRsp; pMsg->rpcRsp.rsp = pConnectRsp;
rpcRsp.contLen = sizeof(SCMConnectRsp); pMsg->rpcRsp.len = sizeof(SCMConnectRsp);
} }
rpcSendResponse(&rpcRsp);
return code;
} }
static void mnodeProcessUseMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMUseDbMsg *pUseDbMsg = pMsg->pCont; SCMUseDbMsg *pUseDbMsg = pMsg->pCont;
// todo check for priority of current user
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDb(pUseDbMsg->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
if (pMsg->pDb == NULL) { if (pMsg->pDb == NULL) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_INVALID_DB;
} }
rpcRsp.code = code;
rpcSendResponse(&rpcRsp);
}
/** return code;
* 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) { static bool mnodeCheckQhandle(uint64_t qhandle) {
if (pMsg->msgType == TSDB_MSG_TYPE_CM_TABLE_META) {
return mgmtCheckTableMetaMsgReadOnly(pMsg);
}
if (pMsg->msgType == TSDB_MSG_TYPE_CM_STABLE_VGROUP || pMsg->msgType == TSDB_MSG_TYPE_CM_RETRIEVE ||
pMsg->msgType == TSDB_MSG_TYPE_CM_SHOW || pMsg->msgType == TSDB_MSG_TYPE_CM_TABLES_META ||
pMsg->msgType == TSDB_MSG_TYPE_CM_CONNECT) {
return true;
}
return false;
}
static void mgmtProcessUnSupportMsg(SRpcMsg *rpcMsg) {
mError("%s is not processed in mnode shell", taosMsg[rpcMsg->msgType]);
SRpcMsg rpcRsp = {
.msgType = 0,
.pCont = 0,
.contLen = 0,
.code = TSDB_CODE_OPS_NOT_SUPPORT,
.handle = rpcMsg->handle
};
rpcSendResponse(&rpcRsp);
}
void mgmtSendSimpleResp(void *thandle, int32_t code) {
SRpcMsg rpcRsp = {
.msgType = 0,
.pCont = 0,
.contLen = 0,
.code = code,
.handle = thandle
};
rpcSendResponse(&rpcRsp);
}
bool mgmtCheckQhandle(uint64_t qhandle) {
void *pSaved = taosCacheAcquireByData(tsQhandleCache, (void *)qhandle); void *pSaved = taosCacheAcquireByData(tsQhandleCache, (void *)qhandle);
if (pSaved == (void *)qhandle) { if (pSaved == (void *)qhandle) {
mTrace("show:%p, is retrieved", qhandle); mTrace("show:%p, is retrieved", qhandle);
...@@ -388,17 +310,17 @@ bool mgmtCheckQhandle(uint64_t qhandle) { ...@@ -388,17 +310,17 @@ bool mgmtCheckQhandle(uint64_t qhandle) {
} }
} }
void* mgmtSaveQhandle(void *qhandle, int32_t size) { static void *mnodeSaveQhandle(void *qhandle, int32_t size) {
if (tsQhandleCache != NULL) { if (tsQhandleCache != NULL) {
char key[24]; char key[24];
sprintf(key, "show:%p", qhandle); sprintf(key, "show:%p", qhandle);
void *newQhandle = taosCachePut(tsQhandleCache, key, qhandle, size, 60); void *newQhandle = taosCachePut(tsQhandleCache, key, qhandle, size, 60);
free(qhandle); free(qhandle);
mTrace("show:%p, is saved", newQhandle); mTrace("show:%p, is saved", newQhandle);
return newQhandle; return newQhandle;
} }
return NULL; return NULL;
} }
...@@ -408,60 +330,7 @@ static void mnodeFreeShowObj(void *data) { ...@@ -408,60 +330,7 @@ static void mnodeFreeShowObj(void *data) {
mTrace("show:%p, is destroyed", pShow); mTrace("show:%p, is destroyed", pShow);
} }
void mgmtFreeQhandle(void *qhandle, bool forceRemove) { static void mnodeFreeQhandle(void *qhandle, bool forceRemove) {
mTrace("show:%p, is released, force:%s", qhandle, forceRemove ? "true" : "false"); mTrace("show:%p, is released, force:%s", qhandle, forceRemove ? "true" : "false");
taosCacheRelease(tsQhandleCache, &qhandle, forceRemove); 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;
}
...@@ -24,64 +24,68 @@ ...@@ -24,64 +24,68 @@
#include "tname.h" #include "tname.h"
#include "tidpool.h" #include "tidpool.h"
#include "tglobal.h" #include "tglobal.h"
#include "tcompare.h"
#include "tdataformat.h"
#include "tgrant.h"
#include "hash.h" #include "hash.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mnodeDb.h" #include "mnodeDb.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "tgrant.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "tcompare.h" #include "mnodeWrite.h"
#include "tdataformat.h" #include "mnodeRead.h"
#include "mnodePeer.h"
static void * tsChildTableSdb; static void * tsChildTableSdb;
static void * tsSuperTableSdb; static void * tsSuperTableSdb;
static int32_t tsChildTableUpdateSize; static int32_t tsChildTableUpdateSize;
static int32_t tsSuperTableUpdateSize; static int32_t tsSuperTableUpdateSize;
static void * mgmtGetChildTable(char *tableId); static void * mnodeGetChildTable(char *tableId);
static void * mgmtGetSuperTable(char *tableId); static void * mnodeGetSuperTable(char *tableId);
static void * mgmtGetSuperTableByUid(uint64_t uid); static void * mnodeGetSuperTableByUid(uint64_t uid);
static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable); static void mnodeDropAllChildTablesInStable(SSuperTableObj *pStable);
static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable); static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable);
static void mgmtRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable); static void mnodeRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable);
static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static void mgmtProcessCreateTableMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg);
static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg);
static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg); static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg);
static void mgmtProcessDropTableMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessDropTableMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg);
static void mgmtProcessDropSuperTableRsp(SRpcMsg *rpcMsg); static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg);
static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg);
static void mgmtProcessDropChildTableRsp(SRpcMsg *rpcMsg); static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg);
static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg); static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessTableMetaMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *mnodeMsg);
static void mgmtGetSuperTableMeta(SMnodeMsg *pMsg); static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg);
static void mgmtGetChildTableMeta(SMnodeMsg *pMsg); static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg);
static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg); static int32_t mgmtAutoCreateChildTable(SMnodeMsg *pMsg);
static void mgmtProcessAlterTableMsg(SMnodeMsg *queueMsg); static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *mnodeMsg);
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg); static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg);
static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName); static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName);
static void mgmtDestroyChildTable(SChildTableObj *pTable) { static void mgmtDestroyChildTable(SChildTableObj *pTable) {
tfree(pTable->info.tableId); tfree(pTable->info.tableId);
...@@ -90,39 +94,39 @@ static void mgmtDestroyChildTable(SChildTableObj *pTable) { ...@@ -90,39 +94,39 @@ static void mgmtDestroyChildTable(SChildTableObj *pTable) {
tfree(pTable); tfree(pTable);
} }
static int32_t mgmtChildTableActionDestroy(SSdbOper *pOper) { static int32_t mnodeChildTableActionDestroy(SSdbOper *pOper) {
mgmtDestroyChildTable(pOper->pObj); mgmtDestroyChildTable(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) { static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
SChildTableObj *pTable = pOper->pObj; SChildTableObj *pTable = pOper->pObj;
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId); SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId); mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_INVALID_VGROUP_ID;
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
SDbObj *pDb = mgmtGetDb(pVgroup->dbName); SDbObj *pDb = mnodeGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName); mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_INVALID_DB;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct == NULL) { if (pAcct == NULL) {
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_INVALID_ACCT;
} }
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
// add ref // add ref
pTable->superTable = mgmtGetSuperTableByUid(pTable->suid); pTable->superTable = mnodeGetSuperTableByUid(pTable->suid);
mgmtAddTableIntoStable(pTable->superTable, pTable); mnodeAddTableIntoStable(pTable->superTable, pTable);
grantAdd(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1); grantAdd(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1);
pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1);
} else { } else {
...@@ -130,56 +134,56 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) { ...@@ -130,56 +134,56 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) {
pAcct->acctInfo.numOfTimeSeries += (pTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->numOfColumns - 1);
} }
mgmtAddTableIntoDb(pDb); mnodeAddTableIntoDb(pDb);
mgmtAddTableIntoVgroup(pVgroup, pTable); mnodeAddTableIntoVgroup(pVgroup, pTable);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionDelete(SSdbOper *pOper) { static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) {
SChildTableObj *pTable = pOper->pObj; SChildTableObj *pTable = pOper->pObj;
if (pTable->vgId == 0) { if (pTable->vgId == 0) {
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_INVALID_VGROUP_ID;
} }
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId); SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_INVALID_VGROUP_ID;
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
SDbObj *pDb = mgmtGetDb(pVgroup->dbName); SDbObj *pDb = mnodeGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
mError("ctable:%s, vgId:%d not in DB:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName); mError("ctable:%s, vgId:%d not in DB:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_INVALID_DB;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct == NULL) { if (pAcct == NULL) {
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_INVALID_ACCT;
} }
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
grantRestore(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1); grantRestore(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1);
pAcct->acctInfo.numOfTimeSeries -= (pTable->superTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries -= (pTable->superTable->numOfColumns - 1);
mgmtRemoveTableFromStable(pTable->superTable, pTable); mnodeRemoveTableFromStable(pTable->superTable, pTable);
mgmtDecTableRef(pTable->superTable); mnodeDecTableRef(pTable->superTable);
} else { } else {
grantRestore(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1); grantRestore(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1);
pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfColumns - 1);
} }
mgmtRemoveTableFromDb(pDb); mnodeRemoveTableFromDb(pDb);
mgmtRemoveTableFromVgroup(pVgroup, pTable); mnodeRemoveTableFromVgroup(pVgroup, pTable);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionUpdate(SSdbOper *pOper) { static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) {
SChildTableObj *pNew = pOper->pObj; SChildTableObj *pNew = pOper->pObj;
SChildTableObj *pTable = mgmtGetChildTable(pNew->info.tableId); SChildTableObj *pTable = mnodeGetChildTable(pNew->info.tableId);
if (pTable != pNew) { if (pTable != pNew) {
void *oldTableId = pTable->info.tableId; void *oldTableId = pTable->info.tableId;
void *oldSql = pTable->sql; void *oldSql = pTable->sql;
...@@ -192,12 +196,12 @@ static int32_t mgmtChildTableActionUpdate(SSdbOper *pOper) { ...@@ -192,12 +196,12 @@ static int32_t mgmtChildTableActionUpdate(SSdbOper *pOper) {
free(oldSchema); free(oldSchema);
free(oldTableId); free(oldTableId);
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionEncode(SSdbOper *pOper) { static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) {
SChildTableObj *pTable = pOper->pObj; SChildTableObj *pTable = pOper->pObj;
assert(pTable != NULL && pOper->rowData != NULL); assert(pTable != NULL && pOper->rowData != NULL);
...@@ -227,7 +231,7 @@ static int32_t mgmtChildTableActionEncode(SSdbOper *pOper) { ...@@ -227,7 +231,7 @@ static int32_t mgmtChildTableActionEncode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionDecode(SSdbOper *pOper) { static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
assert(pOper->rowData != NULL); assert(pOper->rowData != NULL);
SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj));
if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -264,34 +268,34 @@ static int32_t mgmtChildTableActionDecode(SSdbOper *pOper) { ...@@ -264,34 +268,34 @@ static int32_t mgmtChildTableActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtChildTableActionRestored() { static int32_t mnodeChildTableActionRestored() {
void *pIter = NULL; void *pIter = NULL;
SChildTableObj *pTable = NULL; SChildTableObj *pTable = NULL;
while (1) { while (1) {
pIter = mgmtGetNextChildTable(pIter, &pTable); pIter = mnodeGetNextChildTable(pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
SDbObj *pDb = mgmtGetDbByTableId(pTable->info.tableId); SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId);
if (pDb == NULL) { if (pDb == NULL) {
mError("ctable:%s, failed to get db, discard it", pTable->info.tableId); mError("ctable:%s, failed to get db, discard it", pTable->info.tableId);
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId); SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("ctable:%s, failed to get vgId:%d sid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->sid); mError("ctable:%s, failed to get vgId:%d sid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->sid);
pTable->vgId = 0; pTable->vgId = 0;
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
if (strcmp(pVgroup->dbName, pDb->name) != 0) { if (strcmp(pVgroup->dbName, pDb->name) != 0) {
mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it", mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it",
...@@ -299,7 +303,7 @@ static int32_t mgmtChildTableActionRestored() { ...@@ -299,7 +303,7 @@ static int32_t mgmtChildTableActionRestored() {
pTable->vgId = 0; pTable->vgId = 0;
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -308,24 +312,24 @@ static int32_t mgmtChildTableActionRestored() { ...@@ -308,24 +312,24 @@ static int32_t mgmtChildTableActionRestored() {
pTable->vgId = 0; pTable->vgId = 0;
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
SSuperTableObj *pSuperTable = mgmtGetSuperTableByUid(pTable->suid); SSuperTableObj *pSuperTable = mnodeGetSuperTableByUid(pTable->suid);
if (pSuperTable == NULL) { if (pSuperTable == NULL) {
mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid);
pTable->vgId = 0; pTable->vgId = 0;
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
mgmtDecTableRef(pSuperTable); mnodeDecTableRef(pSuperTable);
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -333,7 +337,7 @@ static int32_t mgmtChildTableActionRestored() { ...@@ -333,7 +337,7 @@ static int32_t mgmtChildTableActionRestored() {
return 0; return 0;
} }
static int32_t mgmtInitChildTables() { static int32_t mnodeInitChildTables() {
SChildTableObj tObj; SChildTableObj tObj;
tsChildTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type; tsChildTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type;
...@@ -344,13 +348,13 @@ static int32_t mgmtInitChildTables() { ...@@ -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, .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, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_VAR_STRING, .keyType = SDB_KEY_VAR_STRING,
.insertFp = mgmtChildTableActionInsert, .insertFp = mnodeChildTableActionInsert,
.deleteFp = mgmtChildTableActionDelete, .deleteFp = mnodeChildTableActionDelete,
.updateFp = mgmtChildTableActionUpdate, .updateFp = mnodeChildTableActionUpdate,
.encodeFp = mgmtChildTableActionEncode, .encodeFp = mnodeChildTableActionEncode,
.decodeFp = mgmtChildTableActionDecode, .decodeFp = mnodeChildTableActionDecode,
.destroyFp = mgmtChildTableActionDestroy, .destroyFp = mnodeChildTableActionDestroy,
.restoredFp = mgmtChildTableActionRestored .restoredFp = mnodeChildTableActionRestored
}; };
tsChildTableSdb = sdbOpenTable(&tableDesc); tsChildTableSdb = sdbOpenTable(&tableDesc);
...@@ -363,11 +367,11 @@ static int32_t mgmtInitChildTables() { ...@@ -363,11 +367,11 @@ static int32_t mgmtInitChildTables() {
return 0; return 0;
} }
static void mgmtCleanUpChildTables() { static void mnodeCleanupChildTables() {
sdbCloseTable(tsChildTableSdb); sdbCloseTable(tsChildTableSdb);
} }
static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) {
pStable->numOfTables++; pStable->numOfTables++;
if (pStable->vgHash == NULL) { if (pStable->vgHash == NULL) {
...@@ -379,16 +383,16 @@ static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCta ...@@ -379,16 +383,16 @@ static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCta
} }
} }
static void mgmtRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { static void mnodeRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable) {
pStable->numOfTables--; pStable->numOfTables--;
if (pStable->vgHash == NULL) return; if (pStable->vgHash == NULL) return;
SVgObj *pVgroup = mgmtGetVgroup(pCtable->vgId); SVgObj *pVgroup = mnodeGetVgroup(pCtable->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
taosHashRemove(pStable->vgHash, (char *)&pCtable->vgId, sizeof(pCtable->vgId)); taosHashRemove(pStable->vgHash, (char *)&pCtable->vgId, sizeof(pCtable->vgId));
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
static void mgmtDestroySuperTable(SSuperTableObj *pStable) { static void mgmtDestroySuperTable(SSuperTableObj *pStable) {
...@@ -401,37 +405,37 @@ static void mgmtDestroySuperTable(SSuperTableObj *pStable) { ...@@ -401,37 +405,37 @@ static void mgmtDestroySuperTable(SSuperTableObj *pStable) {
tfree(pStable); tfree(pStable);
} }
static int32_t mgmtSuperTableActionDestroy(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) {
mgmtDestroySuperTable(pOper->pObj); mgmtDestroySuperTable(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionInsert(SSdbOper *pOper) { static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
SSuperTableObj *pStable = pOper->pObj; SSuperTableObj *pStable = pOper->pObj;
SDbObj *pDb = mgmtGetDbByTableId(pStable->info.tableId); SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId);
if (pDb != NULL) { if (pDb != NULL) {
mgmtAddSuperTableIntoDb(pDb); mnodeAddSuperTableIntoDb(pDb);
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionDelete(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) {
SSuperTableObj *pStable = pOper->pObj; SSuperTableObj *pStable = pOper->pObj;
SDbObj *pDb = mgmtGetDbByTableId(pStable->info.tableId); SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId);
if (pDb != NULL) { if (pDb != NULL) {
mgmtRemoveSuperTableFromDb(pDb); mnodeRemoveSuperTableFromDb(pDb);
mgmtDropAllChildTablesInStable((SSuperTableObj *)pStable); mnodeDropAllChildTablesInStable((SSuperTableObj *)pStable);
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionUpdate(SSdbOper *pOper) { static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
SSuperTableObj *pNew = pOper->pObj; SSuperTableObj *pNew = pOper->pObj;
SSuperTableObj *pTable = mgmtGetSuperTable(pNew->info.tableId); SSuperTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId);
if (pTable != pNew) { if (pTable != pNew) {
void *oldTableId = pTable->info.tableId; void *oldTableId = pTable->info.tableId;
void *oldSchema = pTable->schema; void *oldSchema = pTable->schema;
...@@ -442,11 +446,11 @@ static int32_t mgmtSuperTableActionUpdate(SSdbOper *pOper) { ...@@ -442,11 +446,11 @@ static int32_t mgmtSuperTableActionUpdate(SSdbOper *pOper) {
free(oldTableId); free(oldTableId);
free(oldSchema); free(oldSchema);
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionEncode(SSdbOper *pOper) { static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) {
SSuperTableObj *pStable = pOper->pObj; SSuperTableObj *pStable = pOper->pObj;
assert(pOper->pObj != NULL && pOper->rowData != NULL); assert(pOper->pObj != NULL && pOper->rowData != NULL);
...@@ -469,7 +473,7 @@ static int32_t mgmtSuperTableActionEncode(SSdbOper *pOper) { ...@@ -469,7 +473,7 @@ static int32_t mgmtSuperTableActionEncode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionDecode(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) {
assert(pOper->rowData != NULL); assert(pOper->rowData != NULL);
SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj)); SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj));
if (pStable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pStable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -496,11 +500,11 @@ static int32_t mgmtSuperTableActionDecode(SSdbOper *pOper) { ...@@ -496,11 +500,11 @@ static int32_t mgmtSuperTableActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSuperTableActionRestored() { static int32_t mnodeSuperTableActionRestored() {
return 0; return 0;
} }
static int32_t mgmtInitSuperTables() { static int32_t mnodeInitSuperTables() {
SSuperTableObj tObj; SSuperTableObj tObj;
tsSuperTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type; tsSuperTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type;
...@@ -511,13 +515,13 @@ static int32_t mgmtInitSuperTables() { ...@@ -511,13 +515,13 @@ static int32_t mgmtInitSuperTables() {
.maxRowSize = sizeof(SSuperTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_ID_LEN, .maxRowSize = sizeof(SSuperTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_ID_LEN,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_VAR_STRING, .keyType = SDB_KEY_VAR_STRING,
.insertFp = mgmtSuperTableActionInsert, .insertFp = mnodeSuperTableActionInsert,
.deleteFp = mgmtSuperTableActionDelete, .deleteFp = mnodeSuperTableActionDelete,
.updateFp = mgmtSuperTableActionUpdate, .updateFp = mnodeSuperTableActionUpdate,
.encodeFp = mgmtSuperTableActionEncode, .encodeFp = mnodeSuperTableActionEncode,
.decodeFp = mgmtSuperTableActionDecode, .decodeFp = mnodeSuperTableActionDecode,
.destroyFp = mgmtSuperTableActionDestroy, .destroyFp = mnodeSuperTableActionDestroy,
.restoredFp = mgmtSuperTableActionRestored .restoredFp = mnodeSuperTableActionRestored
}; };
tsSuperTableSdb = sdbOpenTable(&tableDesc); tsSuperTableSdb = sdbOpenTable(&tableDesc);
...@@ -530,63 +534,63 @@ static int32_t mgmtInitSuperTables() { ...@@ -530,63 +534,63 @@ static int32_t mgmtInitSuperTables() {
return 0; return 0;
} }
static void mgmtCleanUpSuperTables() { static void mnodeCleanupSuperTables() {
sdbCloseTable(tsSuperTableSdb); sdbCloseTable(tsSuperTableSdb);
} }
int32_t mgmtInitTables() { int32_t mnodeInitTables() {
int32_t code = mgmtInitSuperTables(); int32_t code = mnodeInitSuperTables();
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
code = mgmtInitChildTables(); code = mnodeInitChildTables();
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_TABLES_META, mgmtProcessMultiTableMetaMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_TABLES_META, mnodeProcessMultiTableMetaMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CREATE_TABLE, mgmtProcessCreateTableMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_TABLE, mnodeProcessCreateTableMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_DROP_TABLE, mgmtProcessDropTableMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_TABLE, mnodeProcessDropTableMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_ALTER_TABLE, mgmtProcessAlterTableMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_ALTER_TABLE, mnodeProcessAlterTableMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_TABLE_META, mgmtProcessTableMetaMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_TABLE_META, mnodeProcessTableMetaMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_STABLE_VGROUP, mgmtProcessSuperTableVgroupMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_STABLE_VGROUP, mnodeProcessSuperTableVgroupMsg);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP, mgmtProcessCreateChildTableRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP, mnodeProcessCreateChildTableRsp);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_DROP_TABLE_RSP, mgmtProcessDropChildTableRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_TABLE_RSP, mnodeProcessDropChildTableRsp);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_DROP_STABLE_RSP, mgmtProcessDropSuperTableRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_STABLE_RSP, mnodeProcessDropSuperTableRsp);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP, mgmtProcessAlterTableRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP, mnodeProcessAlterTableRsp);
dnodeAddServerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_TABLE, mgmtProcessTableCfgMsg); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_TABLE, mnodeProcessTableCfgMsg);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_TABLE, mgmtGetShowTableMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_TABLE, mnodeGetShowTableMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_TABLE, mgmtRetrieveShowTables); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_TABLE, mnodeRetrieveShowTables);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_METRIC, mgmtGetShowSuperTableMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_METRIC, mnodeGetShowSuperTableMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_METRIC, mgmtRetrieveShowSuperTables); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_METRIC, mnodeRetrieveShowSuperTables);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void *mgmtGetChildTable(char *tableId) { static void *mnodeGetChildTable(char *tableId) {
return sdbGetRow(tsChildTableSdb, tableId); return sdbGetRow(tsChildTableSdb, tableId);
} }
static void *mgmtGetSuperTable(char *tableId) { static void *mnodeGetSuperTable(char *tableId) {
return sdbGetRow(tsSuperTableSdb, tableId); return sdbGetRow(tsSuperTableSdb, tableId);
} }
static void *mgmtGetSuperTableByUid(uint64_t uid) { static void *mnodeGetSuperTableByUid(uint64_t uid) {
SSuperTableObj *pStable = NULL; SSuperTableObj *pStable = NULL;
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
pIter = mgmtGetNextSuperTable(pIter, &pStable); pIter = mnodeGetNextSuperTable(pIter, &pStable);
if (pStable == NULL) break; if (pStable == NULL) break;
if (pStable->uid == uid) { if (pStable->uid == uid) {
sdbFreeIter(pIter); sdbFreeIter(pIter);
return pStable; return pStable;
} }
mgmtDecTableRef(pStable); mnodeDecTableRef(pStable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -594,13 +598,13 @@ static void *mgmtGetSuperTableByUid(uint64_t uid) { ...@@ -594,13 +598,13 @@ static void *mgmtGetSuperTableByUid(uint64_t uid) {
return NULL; return NULL;
} }
void *mgmtGetTable(char *tableId) { void *mnodeGetTable(char *tableId) {
void *pTable = mgmtGetSuperTable(tableId); void *pTable = mnodeGetSuperTable(tableId);
if (pTable != NULL) { if (pTable != NULL) {
return pTable; return pTable;
} }
pTable = mgmtGetChildTable(tableId); pTable = mnodeGetChildTable(tableId);
if (pTable != NULL) { if (pTable != NULL) {
return pTable; return pTable;
} }
...@@ -608,15 +612,15 @@ void *mgmtGetTable(char *tableId) { ...@@ -608,15 +612,15 @@ void *mgmtGetTable(char *tableId) {
return NULL; return NULL;
} }
void *mgmtGetNextChildTable(void *pIter, SChildTableObj **pTable) { void *mnodeGetNextChildTable(void *pIter, SChildTableObj **pTable) {
return sdbFetchRow(tsChildTableSdb, pIter, (void **)pTable); return sdbFetchRow(tsChildTableSdb, pIter, (void **)pTable);
} }
void *mgmtGetNextSuperTable(void *pIter, SSuperTableObj **pTable) { void *mnodeGetNextSuperTable(void *pIter, SSuperTableObj **pTable) {
return sdbFetchRow(tsSuperTableSdb, pIter, (void **)pTable); return sdbFetchRow(tsSuperTableSdb, pIter, (void **)pTable);
} }
void mgmtIncTableRef(void *p1) { void mnodeIncTableRef(void *p1) {
STableObj *pTable = (STableObj *)p1; STableObj *pTable = (STableObj *)p1;
if (pTable->type == TSDB_SUPER_TABLE) { if (pTable->type == TSDB_SUPER_TABLE) {
sdbIncRef(tsSuperTableSdb, pTable); sdbIncRef(tsSuperTableSdb, pTable);
...@@ -625,7 +629,7 @@ void mgmtIncTableRef(void *p1) { ...@@ -625,7 +629,7 @@ void mgmtIncTableRef(void *p1) {
} }
} }
void mgmtDecTableRef(void *p1) { void mnodeDecTableRef(void *p1) {
if (p1 == NULL) return; if (p1 == NULL) return;
STableObj *pTable = (STableObj *)p1; STableObj *pTable = (STableObj *)p1;
...@@ -636,9 +640,9 @@ void mgmtDecTableRef(void *p1) { ...@@ -636,9 +640,9 @@ void mgmtDecTableRef(void *p1) {
} }
} }
void mgmtCleanUpTables() { void mnodeCleanupTables() {
mgmtCleanUpChildTables(); mnodeCleanupChildTables();
mgmtCleanUpSuperTables(); mnodeCleanupSuperTables();
} }
// todo move to name.h, add length of table name // todo move to name.h, add length of table name
...@@ -655,113 +659,105 @@ static void mgmtExtractTableName(char* tableId, char* name) { ...@@ -655,113 +659,105 @@ static void mgmtExtractTableName(char* tableId, char* name) {
} }
} }
static void mgmtProcessCreateTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
SCMCreateTableMsg *pCreate = pMsg->pCont; SCMCreateTableMsg *pCreate = pMsg->pCont;
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDb(pCreate->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to create, db not selected", pCreate->tableId); mError("table:%s, failed to create, db not selected", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); return TSDB_CODE_DB_NOT_SELECTED;
return;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pCreate->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
if (pMsg->pTable != NULL && pMsg->retry == 0) { if (pMsg->pTable != NULL && pMsg->retry == 0) {
if (pCreate->getMeta) { if (pCreate->getMeta) {
mTrace("table:%s, continue to get meta", pCreate->tableId); mTrace("table:%s, continue to get meta", pCreate->tableId);
mgmtGetChildTableMeta(pMsg); return mnodeGetChildTableMeta(pMsg);
} else if (pCreate->igExists) { } else if (pCreate->igExists) {
mTrace("table:%s, is already exist", pCreate->tableId); mTrace("table:%s, is already exist", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS;
} else { } else {
mError("table:%s, failed to create, table already exist", pCreate->tableId); 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) { if (pCreate->numOfTags != 0) {
mTrace("table:%s, create msg is received from thandle:%p", pCreate->tableId, pMsg->thandle); mTrace("table:%s, create msg is received from thandle:%p", pCreate->tableId, pMsg->thandle);
mgmtProcessCreateSuperTableMsg(pMsg); return mnodeProcessCreateSuperTableMsg(pMsg);
} else { } else {
mTrace("table:%s, create msg is received from thandle:%p", pCreate->tableId, pMsg->thandle); mTrace("table:%s, create msg is received from thandle:%p", pCreate->tableId, pMsg->thandle);
mgmtProcessCreateChildTableMsg(pMsg); return mnodeProcessCreateChildTableMsg(pMsg);
} }
} }
static void mgmtProcessDropTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
SCMDropTableMsg *pDrop = pMsg->pCont; SCMDropTableMsg *pDrop = pMsg->pCont;
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDbByTableId(pDrop->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to drop table, db not selected", pDrop->tableId); mError("table:%s, failed to drop table, db not selected", pDrop->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); return TSDB_CODE_DB_NOT_SELECTED;
return;
} }
if (mgmtCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("table:%s, failed to drop table, in monitor database", pDrop->tableId); mError("table:%s, failed to drop table, in monitor database", pDrop->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MONITOR_DB_FORBIDDEN); return TSDB_CODE_MONITOR_DB_FORBIDDEN;
return;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pDrop->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
if (pDrop->igNotExists) { if (pDrop->igNotExists) {
mTrace("table:%s, table is not exist, think drop success", pDrop->tableId); mTrace("table:%s, table is not exist, think drop success", pDrop->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS;
return;
} else { } else {
mError("table:%s, failed to drop table, table not exist", pDrop->tableId); mError("table:%s, failed to drop table, table not exist", pDrop->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE); return TSDB_CODE_INVALID_TABLE;
return;
} }
} }
if (pMsg->pTable->type == TSDB_SUPER_TABLE) { if (pMsg->pTable->type == TSDB_SUPER_TABLE) {
mPrint("table:%s, start to drop stable", pDrop->tableId); mPrint("table:%s, start to drop stable", pDrop->tableId);
mgmtProcessDropSuperTableMsg(pMsg); return mnodeProcessDropSuperTableMsg(pMsg);
} else { } else {
mPrint("table:%s, start to drop ctable", pDrop->tableId); mPrint("table:%s, start to drop ctable", pDrop->tableId);
mgmtProcessDropChildTableMsg(pMsg); return mnodeProcessDropChildTableMsg(pMsg);
} }
} }
static void mgmtProcessTableMetaMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
SCMTableInfoMsg *pInfo = pMsg->pCont; SCMTableInfoMsg *pInfo = pMsg->pCont;
pInfo->createFlag = htons(pInfo->createFlag); pInfo->createFlag = htons(pInfo->createFlag);
mTrace("table:%s, table meta msg is received from thandle:%p, createFlag:%d", pInfo->tableId, pMsg->thandle, 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 = mgmtGetDbByTableId(pInfo->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); mError("table:%s, failed to get table meta, db not selected", pInfo->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); return TSDB_CODE_DB_NOT_SELECTED;
return;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pInfo->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
if (!pInfo->createFlag) { if (!pInfo->createFlag) {
mError("table:%s, failed to get table meta, table not exist", pInfo->tableId); 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 { } else {
mgmtAutoCreateChildTable(pMsg); return mgmtAutoCreateChildTable(pMsg);
} }
} else { } else {
if (pMsg->pTable->type != TSDB_SUPER_TABLE) { if (pMsg->pTable->type != TSDB_SUPER_TABLE) {
mgmtGetChildTableMeta(pMsg); return mnodeGetChildTableMeta(pMsg);
} else { } else {
mgmtGetSuperTableMeta(pMsg); return mnodeGetSuperTableMeta(pMsg);
} }
} }
} }
static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
SCMCreateTableMsg *pCreate = pMsg->pCont; SCMCreateTableMsg *pCreate = pMsg->pCont;
SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj)); SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj));
if (pStable == NULL) { if (pStable == NULL) {
mError("table:%s, failed to create, no enough memory", pCreate->tableId); mError("table:%s, failed to create, no enough memory", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
pStable->info.tableId = strdup(pCreate->tableId); pStable->info.tableId = strdup(pCreate->tableId);
...@@ -779,8 +775,7 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -779,8 +775,7 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if (pStable->schema == NULL) { if (pStable->schema == NULL) {
free(pStable); free(pStable);
mError("table:%s, failed to create, no schema input", pCreate->tableId); mError("table:%s, failed to create, no schema input", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE); return TSDB_CODE_INVALID_TABLE;
return;
} }
memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
...@@ -805,20 +800,20 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -805,20 +800,20 @@ static void mgmtProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mgmtDestroySuperTable(pStable); mgmtDestroySuperTable(pStable);
mError("table:%s, failed to create, sdb error", pCreate->tableId); mError("table:%s, failed to create, sdb error", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SDB_ERROR); return TSDB_CODE_SDB_ERROR;
} else { } else {
mLPrint("table:%s, is created, tags:%d fields:%d", pStable->info.tableId, pStable->numOfTags, pStable->numOfColumns); 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 mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable; SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable;
if (pStable->numOfTables != 0) { if (pStable->numOfTables != 0) {
SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash); SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash);
while (taosHashIterNext(pIter)) { while (taosHashIterNext(pIter)) {
int32_t *pVgId = taosHashIterGet(pIter); int32_t *pVgId = taosHashIterGet(pIter);
SVgObj *pVgroup = mgmtGetVgroup(*pVgId); SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
SMDDropSTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropSTableMsg)); SMDDropSTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropSTableMsg));
...@@ -828,14 +823,14 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -828,14 +823,14 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
mgmtExtractTableName(pStable->info.tableId, pDrop->tableId); mgmtExtractTableName(pStable->info.tableId, pDrop->tableId);
mPrint("stable:%s, send drop stable msg to vgId:%d", pStable->info.tableId, pVgroup->vgId); mPrint("stable:%s, send drop stable msg to vgId:%d", pStable->info.tableId, pVgroup->vgId);
SRpcIpSet ipSet = mgmtGetIpSetFromVgroup(pVgroup); SRpcIpSet ipSet = mnodeGetIpSetFromVgroup(pVgroup);
SRpcMsg rpcMsg = {.pCont = pDrop, .contLen = sizeof(SMDDropSTableMsg), .msgType = TSDB_MSG_TYPE_MD_DROP_STABLE}; SRpcMsg rpcMsg = {.pCont = pDrop, .contLen = sizeof(SMDDropSTableMsg), .msgType = TSDB_MSG_TYPE_MD_DROP_STABLE};
dnodeSendMsgToDnode(&ipSet, &rpcMsg); dnodeSendMsgToDnode(&ipSet, &rpcMsg);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
taosHashDestroyIter(pIter); taosHashDestroyIter(pIter);
mgmtDropAllChildTablesInStable(pStable); mnodeDropAllChildTablesInStable(pStable);
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -846,10 +841,10 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -846,10 +841,10 @@ static void mgmtProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
mLPrint("stable:%s, is dropped from sdb, result:%s", pStable->info.tableId, tstrerror(code)); mLPrint("stable:%s, is dropped from sdb, result:%s", pStable->info.tableId, tstrerror(code));
mgmtSendSimpleResp(pMsg->thandle, code); return code;
} }
static int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName) { static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName) {
SSchema *schema = (SSchema *) pStable->schema; SSchema *schema = (SSchema *) pStable->schema;
for (int32_t tag = 0; tag < pStable->numOfTags; tag++) { for (int32_t tag = 0; tag < pStable->numOfTags; tag++) {
if (strcasecmp(schema[pStable->numOfColumns + tag].name, tagName) == 0) { if (strcasecmp(schema[pStable->numOfColumns + tag].name, tagName) == 0) {
...@@ -860,19 +855,19 @@ static int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *t ...@@ -860,19 +855,19 @@ static int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *t
return -1; return -1;
} }
static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) { static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) {
if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) { if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) {
mError("stable:%s, add tag, too many tags", pStable->info.tableId); mError("stable:%s, add tag, too many tags", pStable->info.tableId);
return TSDB_CODE_TOO_MANY_TAGS; return TSDB_CODE_TOO_MANY_TAGS;
} }
for (int32_t i = 0; i < ntags; i++) { for (int32_t i = 0; i < ntags; i++) {
if (mgmtFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_TAG_ALREAY_EXIST;
} }
if (mgmtFindSuperTableTagIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_FIELD_ALREAY_EXIST;
} }
...@@ -906,8 +901,8 @@ static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], i ...@@ -906,8 +901,8 @@ static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], i
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
int32_t col = mgmtFindSuperTableTagIndex(pStable, tagName); int32_t col = mnodeFindSuperTableTagIndex(pStable, tagName);
if (col < 0) { if (col < 0) {
mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName); mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName);
return TSDB_CODE_TAG_NOT_EXIST; return TSDB_CODE_TAG_NOT_EXIST;
...@@ -933,8 +928,8 @@ static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { ...@@ -933,8 +928,8 @@ static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTagName, char *newTagName) { static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTagName, char *newTagName) {
int32_t col = mgmtFindSuperTableTagIndex(pStable, oldTagName); int32_t col = mnodeFindSuperTableTagIndex(pStable, oldTagName);
if (col < 0) { if (col < 0) {
mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName); mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName);
return TSDB_CODE_TAG_NOT_EXIST; return TSDB_CODE_TAG_NOT_EXIST;
...@@ -946,7 +941,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag ...@@ -946,7 +941,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag
return TSDB_CODE_COL_NAME_TOO_LONG; return TSDB_CODE_COL_NAME_TOO_LONG;
} }
if (mgmtFindSuperTableTagIndex(pStable, newTagName) >= 0) { if (mnodeFindSuperTableTagIndex(pStable, newTagName) >= 0) {
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_TAG_ALREAY_EXIST;
} }
...@@ -969,7 +964,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag ...@@ -969,7 +964,7 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName) { static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName) {
SSchema *schema = (SSchema *) pStable->schema; SSchema *schema = (SSchema *) pStable->schema;
for (int32_t col = 0; col < pStable->numOfColumns; col++) { for (int32_t col = 0; col < pStable->numOfColumns; col++) {
if (strcasecmp(schema[col].name, colName) == 0) { if (strcasecmp(schema[col].name, colName) == 0) {
...@@ -980,19 +975,19 @@ static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colN ...@@ -980,19 +975,19 @@ static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colN
return -1; return -1;
} }
static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) { static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) {
if (ncols <= 0) { if (ncols <= 0) {
mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId); mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
for (int32_t i = 0; i < ncols; i++) { for (int32_t i = 0; i < ncols; i++) {
if (mgmtFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_FIELD_ALREAY_EXIST;
} }
if (mgmtFindSuperTableTagIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_TAG_ALREAY_EXIST;
} }
...@@ -1013,10 +1008,10 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc ...@@ -1013,10 +1008,10 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
pStable->numOfColumns += ncols; pStable->numOfColumns += ncols;
pStable->sversion++; pStable->sversion++;
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables); pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -1034,8 +1029,8 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc ...@@ -1034,8 +1029,8 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, char *colName) { static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, char *colName) {
int32_t col = mgmtFindSuperTableColumnIndex(pStable, colName); int32_t col = mnodeFindSuperTableColumnIndex(pStable, colName);
if (col <= 0) { if (col <= 0) {
mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName); mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName);
return TSDB_CODE_FIELD_NOT_EXIST; return TSDB_CODE_FIELD_NOT_EXIST;
...@@ -1050,10 +1045,10 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch ...@@ -1050,10 +1045,10 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns); int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
pStable->schema = realloc(pStable->schema, schemaSize); pStable->schema = realloc(pStable->schema, schemaSize);
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables; pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables;
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -1072,8 +1067,8 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch ...@@ -1072,8 +1067,8 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
} }
// show super tables // show super tables
static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED;
int32_t cols = 0; int32_t cols = 0;
...@@ -1118,12 +1113,12 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, ...@@ -1118,12 +1113,12 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
pShow->numOfRows = pDb->numOfSuperTables; pShow->numOfRows = pDb->numOfSuperTables;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return 0; return 0;
} }
// retrieve super tables // retrieve super tables
int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
char * pWrite; char * pWrite;
int32_t cols = 0; int32_t cols = 0;
...@@ -1131,7 +1126,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v ...@@ -1131,7 +1126,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
char prefix[20] = {0}; char prefix[20] = {0};
int32_t prefixLen; int32_t prefixLen;
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return 0; if (pDb == NULL) return 0;
strcpy(prefix, pDb->name); strcpy(prefix, pDb->name);
...@@ -1142,10 +1137,10 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v ...@@ -1142,10 +1137,10 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
char stableName[TSDB_TABLE_NAME_LEN + 1] = {0}; char stableName[TSDB_TABLE_NAME_LEN + 1] = {0};
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextSuperTable(pShow->pIter, &pTable); pShow->pIter = mnodeGetNextSuperTable(pShow->pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
if (strncmp(pTable->info.tableId, prefix, prefixLen)) { if (strncmp(pTable->info.tableId, prefix, prefixLen)) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -1153,7 +1148,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v ...@@ -1153,7 +1148,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
mgmtExtractTableName(pTable->info.tableId, stableName); mgmtExtractTableName(pTable->info.tableId, stableName);
if (pShow->payloadLen > 0 && patternMatch(pShow->payload, stableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) { if (pShow->payloadLen > 0 && patternMatch(pShow->payload, stableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -1185,16 +1180,16 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v ...@@ -1185,16 +1180,16 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
cols++; cols++;
numOfRows++; numOfRows++;
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return numOfRows; return numOfRows;
} }
void mgmtDropAllSuperTables(SDbObj *pDropDb) { void mnodeDropAllSuperTables(SDbObj *pDropDb) {
void * pIter= NULL; void * pIter= NULL;
int32_t numOfTables = 0; int32_t numOfTables = 0;
int32_t dbNameLen = strlen(pDropDb->name); int32_t dbNameLen = strlen(pDropDb->name);
...@@ -1203,7 +1198,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) { ...@@ -1203,7 +1198,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
mPrint("db:%s, all super tables will be dropped from sdb", pDropDb->name); mPrint("db:%s, all super tables will be dropped from sdb", pDropDb->name);
while (1) { while (1) {
pIter = mgmtGetNextSuperTable(pIter, &pTable); pIter = mnodeGetNextSuperTable(pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) { if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) {
...@@ -1216,7 +1211,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) { ...@@ -1216,7 +1211,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
numOfTables ++; numOfTables ++;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -1224,7 +1219,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) { ...@@ -1224,7 +1219,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
mPrint("db:%s, all super tables:%d is dropped from sdb", pDropDb->name, numOfTables); mPrint("db:%s, all super tables:%d is dropped from sdb", pDropDb->name, numOfTables);
} }
static int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTable) { static int32_t mnodeSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTable) {
int32_t numOfCols = pTable->numOfColumns + pTable->numOfTags; int32_t numOfCols = pTable->numOfColumns + pTable->numOfTags;
assert(numOfCols <= TSDB_MAX_COLUMNS); assert(numOfCols <= TSDB_MAX_COLUMNS);
...@@ -1239,7 +1234,7 @@ static int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTa ...@@ -1239,7 +1234,7 @@ static int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTa
return (pTable->numOfColumns + pTable->numOfTags) * sizeof(SSchema); return (pTable->numOfColumns + pTable->numOfTags) * sizeof(SSchema);
} }
static void mgmtGetSuperTableMeta(SMnodeMsg *pMsg) { static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16));
pMeta->uid = htobe64(pTable->uid); pMeta->uid = htobe64(pTable->uid);
...@@ -1249,21 +1244,19 @@ static void mgmtGetSuperTableMeta(SMnodeMsg *pMsg) { ...@@ -1249,21 +1244,19 @@ static void mgmtGetSuperTableMeta(SMnodeMsg *pMsg) {
pMeta->numOfTags = (uint8_t)pTable->numOfTags; pMeta->numOfTags = (uint8_t)pTable->numOfTags;
pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns); pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns);
pMeta->tableType = pTable->info.type; pMeta->tableType = pTable->info.type;
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable); pMeta->contLen = sizeof(STableMetaMsg) + mnodeSetSchemaFromSuperTable(pMeta->schema, pTable);
strncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN); 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); 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); mTrace("stable:%s, uid:%" PRIu64 " table meta is retrieved", pTable->info.tableId, pTable->uid);
return TSDB_CODE_SUCCESS;
} }
static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
SCMSTableVgroupMsg *pInfo = pMsg->pCont; SCMSTableVgroupMsg *pInfo = pMsg->pCont;
int32_t numOfTable = htonl(pInfo->numOfTables); int32_t numOfTable = htonl(pInfo->numOfTables);
...@@ -1271,17 +1264,16 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { ...@@ -1271,17 +1264,16 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + 32 * sizeof(SCMVgroupInfo) + sizeof(SVgroupsInfo); int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + 32 * sizeof(SCMVgroupInfo) + sizeof(SVgroupsInfo);
for (int32_t i = 0; i < numOfTable; ++i) { for (int32_t i = 0; i < numOfTable; ++i) {
char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN) * i; char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN) * i;
SSuperTableObj *pTable = mgmtGetSuperTable(stableName); SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
if (pTable->vgHash != NULL) { if (pTable->vgHash != NULL) {
contLen += (taosHashGetSize(pTable->vgHash) * sizeof(SCMVgroupInfo) + sizeof(SVgroupsInfo)); contLen += (taosHashGetSize(pTable->vgHash) * sizeof(SCMVgroupInfo) + sizeof(SVgroupsInfo));
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen); SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
pRsp->numOfTables = htonl(numOfTable); pRsp->numOfTables = htonl(numOfTable);
...@@ -1289,14 +1281,14 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { ...@@ -1289,14 +1281,14 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
for (int32_t i = 0; i < numOfTable; ++i) { for (int32_t i = 0; i < numOfTable; ++i) {
char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN) * i; char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN) * i;
SSuperTableObj *pTable = mgmtGetSuperTable(stableName); SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
SVgroupsInfo *pVgroupInfo = (SVgroupsInfo *)msg; SVgroupsInfo *pVgroupInfo = (SVgroupsInfo *)msg;
SHashMutableIterator *pIter = taosHashCreateIter(pTable->vgHash); SHashMutableIterator *pIter = taosHashCreateIter(pTable->vgHash);
int32_t vgSize = 0; int32_t vgSize = 0;
while (taosHashIterNext(pIter)) { while (taosHashIterNext(pIter)) {
int32_t *pVgId = taosHashIterGet(pIter); int32_t *pVgId = taosHashIterGet(pIter);
SVgObj * pVgroup = mgmtGetVgroup(*pVgId); SVgObj * pVgroup = mnodeGetVgroup(*pVgId);
if (pVgroup == NULL) continue; if (pVgroup == NULL) continue;
pVgroupInfo->vgroups[vgSize].vgId = htonl(pVgroup->vgId); pVgroupInfo->vgroups[vgSize].vgId = htonl(pVgroup->vgId);
...@@ -1311,7 +1303,7 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { ...@@ -1311,7 +1303,7 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
} }
vgSize++; vgSize++;
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
taosHashDestroyIter(pIter); taosHashDestroyIter(pIter);
...@@ -1322,14 +1314,13 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { ...@@ -1322,14 +1314,13 @@ static void mgmtProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
msg += sizeof(SVgroupsInfo) + vgSize * sizeof(SCMVgroupInfo); msg += sizeof(SVgroupsInfo) + vgSize * sizeof(SCMVgroupInfo);
} }
SRpcMsg rpcRsp = {0}; pMsg->rpcRsp.rsp = pRsp;
rpcRsp.handle = pMsg->thandle; pMsg->rpcRsp.len = msg - (char *)pRsp;
rpcRsp.pCont = pRsp;
rpcRsp.contLen = msg - (char*) pRsp; return TSDB_CODE_SUCCESS;
rpcSendResponse(&rpcRsp);
} }
static void mgmtProcessDropSuperTableRsp(SRpcMsg *rpcMsg) { static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg) {
mPrint("drop stable rsp received, result:%s", tstrerror(rpcMsg->code)); mPrint("drop stable rsp received, result:%s", tstrerror(rpcMsg->code));
} }
...@@ -1400,7 +1391,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb ...@@ -1400,7 +1391,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb
return pCreate; return pCreate;
} }
static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj *pVgroup, int32_t tid) { static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj *pVgroup, int32_t tid) {
SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj));
if (pTable == NULL) { if (pTable == NULL) {
mError("table:%s, failed to alloc memory", pCreate->tableId); mError("table:%s, failed to alloc memory", pCreate->tableId);
...@@ -1421,14 +1412,14 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj ...@@ -1421,14 +1412,14 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
STagData *pTagData = (STagData *) pCreate->schema; // it is a tag key STagData *pTagData = (STagData *) pCreate->schema; // it is a tag key
SSuperTableObj *pSuperTable = mgmtGetSuperTable(pTagData->name); SSuperTableObj *pSuperTable = mnodeGetSuperTable(pTagData->name);
if (pSuperTable == NULL) { if (pSuperTable == NULL) {
mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name); mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name);
free(pTable); free(pTable);
terrno = TSDB_CODE_INVALID_TABLE; terrno = TSDB_CODE_INVALID_TABLE;
return NULL; return NULL;
} }
mgmtDecTableRef(pSuperTable); mnodeDecTableRef(pSuperTable);
pTable->suid = pSuperTable->uid; pTable->suid = pSuperTable->uid;
pTable->uid = (((uint64_t)pTable->vgId) << 40) + ((((uint64_t)pTable->sid) & ((1ul << 24) - 1ul)) << 16) + 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 ...@@ -1487,20 +1478,18 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj
return pTable; return pTable;
} }
static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
SCMCreateTableMsg *pCreate = pMsg->pCont; SCMCreateTableMsg *pCreate = pMsg->pCont;
int32_t code = grantCheck(TSDB_GRANT_TIMESERIES); int32_t code = grantCheck(TSDB_GRANT_TIMESERIES);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("table:%s, failed to create, grant timeseries failed", pCreate->tableId); mError("table:%s, failed to create, grant timeseries failed", pCreate->tableId);
mgmtSendSimpleResp(pMsg->thandle, code); return code;
return;
} }
SVgObj *pVgroup = mgmtGetAvailableVgroup(pMsg->pDb); SVgObj *pVgroup = mnodeGetAvailableVgroup(pMsg->pDb);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mTrace("table:%s, start to create a new vgroup", pCreate->tableId); mTrace("table:%s, start to create a new vgroup", pCreate->tableId);
mgmtCreateVgroup(mgmtCloneQueuedMsg(pMsg), pMsg->pDb); return mnodeCreateVgroup(pMsg, pMsg->pDb);
return;
} }
if (pMsg->retry == 0) { if (pMsg->retry == 0) {
...@@ -1508,39 +1497,34 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) { ...@@ -1508,39 +1497,34 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
int32_t sid = taosAllocateId(pVgroup->idPool); int32_t sid = taosAllocateId(pVgroup->idPool);
if (sid <= 0) { if (sid <= 0) {
mTrace("tables:%s, no enough sid in vgId:%d", pCreate->tableId, pVgroup->vgId); mTrace("tables:%s, no enough sid in vgId:%d", pCreate->tableId, pVgroup->vgId);
mgmtCreateVgroup(mgmtCloneQueuedMsg(pMsg), pMsg->pDb); return mnodeCreateVgroup(pMsg, pMsg->pDb);
return;
} }
pMsg->pTable = (STableObj *)mgmtDoCreateChildTable(pCreate, pVgroup, sid); pMsg->pTable = (STableObj *)mnodeDoCreateChildTable(pCreate, pVgroup, sid);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
mgmtSendSimpleResp(pMsg->thandle, terrno); return terrno;
return;
} }
mgmtIncTableRef(pMsg->pTable); mnodeIncTableRef(pMsg->pTable);
} }
} else { } else {
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pCreate->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
} }
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
mgmtSendSimpleResp(pMsg->thandle, terrno); return terrno;
return;
} }
SMDCreateTableMsg *pMDCreate = mgmtBuildCreateChildTableMsg(pCreate, (SChildTableObj *) pMsg->pTable); SMDCreateTableMsg *pMDCreate = mgmtBuildCreateChildTableMsg(pCreate, (SChildTableObj *) pMsg->pTable);
if (pMDCreate == NULL) { if (pMDCreate == NULL) {
mgmtSendSimpleResp(pMsg->thandle, terrno); return terrno;
return;
} }
SRpcIpSet ipSet = mgmtGetIpSetFromVgroup(pVgroup); SRpcIpSet ipSet = mnodeGetIpSetFromVgroup(pVgroup);
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(pMsg); pMsg->ahandle = pMsg->pTable;
newMsg->ahandle = pMsg->pTable; pMsg->maxRetry = 10;
newMsg->maxRetry = 10;
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.handle = newMsg, .handle = pMsg,
.pCont = pMDCreate, .pCont = pMDCreate,
.contLen = htonl(pMDCreate->contLen), .contLen = htonl(pMDCreate->contLen),
.code = 0, .code = 0,
...@@ -1548,22 +1532,22 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) { ...@@ -1548,22 +1532,22 @@ static void mgmtProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
}; };
dnodeSendMsgToDnode(&ipSet, &rpcMsg); dnodeSendMsgToDnode(&ipSet, &rpcMsg);
return TSDB_CODE_ACTION_IN_PROGRESS;
} }
static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
if (pMsg->pVgroup == NULL) pMsg->pVgroup = mgmtGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (pMsg->pVgroup == NULL) { if (pMsg->pVgroup == NULL) {
mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId); mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_OTHERS); return TSDB_CODE_OTHERS;
return;
} }
SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg)); SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg));
if (pDrop == NULL) { if (pDrop == NULL) {
mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId); mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
strcpy(pDrop->tableId, pTable->info.tableId); strcpy(pDrop->tableId, pTable->info.tableId);
...@@ -1572,13 +1556,12 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) { ...@@ -1572,13 +1556,12 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) {
pDrop->sid = htonl(pTable->sid); pDrop->sid = htonl(pTable->sid);
pDrop->uid = htobe64(pTable->uid); pDrop->uid = htobe64(pTable->uid);
SRpcIpSet ipSet = mgmtGetIpSetFromVgroup(pMsg->pVgroup); SRpcIpSet ipSet = mnodeGetIpSetFromVgroup(pMsg->pVgroup);
mPrint("table:%s, send drop ctable msg", pDrop->tableId); mPrint("table:%s, send drop ctable msg", pDrop->tableId);
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(pMsg); pMsg->ahandle = pMsg->pTable;
newMsg->ahandle = pMsg->pTable;
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.handle = newMsg, .handle = pMsg,
.pCont = pDrop, .pCont = pDrop,
.contLen = sizeof(SMDDropTableMsg), .contLen = sizeof(SMDDropTableMsg),
.code = 0, .code = 0,
...@@ -1586,13 +1569,15 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) { ...@@ -1586,13 +1569,15 @@ static void mgmtProcessDropChildTableMsg(SMnodeMsg *pMsg) {
}; };
dnodeSendMsgToDnode(&ipSet, &rpcMsg); dnodeSendMsgToDnode(&ipSet, &rpcMsg);
return TSDB_CODE_ACTION_IN_PROGRESS;
} }
static int32_t mgmtModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) { static int32_t mnodeModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) {
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_OPS_NOT_SUPPORT;
} }
static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) { static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) {
SSchema *schema = (SSchema *) pTable->schema; SSchema *schema = (SSchema *) pTable->schema;
for (int32_t col = 0; col < pTable->numOfColumns; col++) { for (int32_t col = 0; col < pTable->numOfColumns; col++) {
if (strcasecmp(schema[col].name, colName) == 0) { if (strcasecmp(schema[col].name, colName) == 0) {
...@@ -1603,14 +1588,14 @@ static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colN ...@@ -1603,14 +1588,14 @@ static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colN
return -1; return -1;
} }
static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) { static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) {
if (ncols <= 0) { if (ncols <= 0) {
mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId); mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
for (int32_t i = 0; i < ncols; i++) { for (int32_t i = 0; i < ncols; i++) {
if (mgmtFindNormalTableColumnIndex(pTable, schema[i].name) > 0) { if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) {
mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name); mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_FIELD_ALREAY_EXIST;
} }
...@@ -1629,10 +1614,10 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc ...@@ -1629,10 +1614,10 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
pTable->numOfColumns += ncols; pTable->numOfColumns += ncols;
pTable->sversion++; pTable->sversion++;
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries += ncols; pAcct->acctInfo.numOfTimeSeries += ncols;
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -1650,8 +1635,8 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc ...@@ -1650,8 +1635,8 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, char *colName) { static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, char *colName) {
int32_t col = mgmtFindNormalTableColumnIndex(pTable, colName); int32_t col = mnodeFindNormalTableColumnIndex(pTable, colName);
if (col <= 0) { if (col <= 0) {
mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName); mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName);
return TSDB_CODE_FIELD_NOT_EXIST; return TSDB_CODE_FIELD_NOT_EXIST;
...@@ -1661,10 +1646,10 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch ...@@ -1661,10 +1646,10 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
pTable->numOfColumns--; pTable->numOfColumns--;
pTable->sversion++; pTable->sversion++;
SAcctObj *pAcct = mgmtGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries--; pAcct->acctInfo.numOfTimeSeries--;
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -1682,7 +1667,7 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch ...@@ -1682,7 +1667,7 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pTable) { static int32_t mnodeSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pTable) {
int32_t numOfCols = pTable->numOfColumns; int32_t numOfCols = pTable->numOfColumns;
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
strcpy(pSchema->name, pTable->schema[i].name); strcpy(pSchema->name, pTable->schema[i].name);
...@@ -1695,7 +1680,7 @@ static int32_t mgmtSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pT ...@@ -1695,7 +1680,7 @@ static int32_t mgmtSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pT
return numOfCols * sizeof(SSchema); return numOfCols * sizeof(SSchema);
} }
static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
SDbObj *pDb = pMsg->pDb; SDbObj *pDb = pMsg->pDb;
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
...@@ -1710,28 +1695,28 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { ...@@ -1710,28 +1695,28 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta->tversion = htons(pTable->superTable->tversion); pMeta->tversion = htons(pTable->superTable->tversion);
pMeta->numOfTags = (int8_t)pTable->superTable->numOfTags; pMeta->numOfTags = (int8_t)pTable->superTable->numOfTags;
pMeta->numOfColumns = htons((int16_t)pTable->superTable->numOfColumns); pMeta->numOfColumns = htons((int16_t)pTable->superTable->numOfColumns);
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable->superTable); pMeta->contLen = sizeof(STableMetaMsg) + mnodeSetSchemaFromSuperTable(pMeta->schema, pTable->superTable);
} else { } else {
pMeta->sversion = htons(pTable->sversion); pMeta->sversion = htons(pTable->sversion);
pMeta->tversion = 0; pMeta->tversion = 0;
pMeta->numOfTags = 0; pMeta->numOfTags = 0;
pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns); pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns);
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromNormalTable(pMeta->schema, pTable); pMeta->contLen = sizeof(STableMetaMsg) + mnodeSetSchemaFromNormalTable(pMeta->schema, pTable);
} }
if (pMsg->pVgroup == NULL) pMsg->pVgroup = mgmtGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (pMsg->pVgroup == NULL) { if (pMsg->pVgroup == NULL) {
mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId); mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_INVALID_VGROUP_ID;
} }
for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = mgmtGetDnode(pMsg->pVgroup->vnodeGid[i].dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMsg->pVgroup->vnodeGid[i].dnodeId);
if (pDnode == NULL) break; if (pDnode == NULL) break;
strcpy(pMeta->vgroup.ipAddr[i].fqdn, pDnode->dnodeFqdn); strcpy(pMeta->vgroup.ipAddr[i].fqdn, pDnode->dnodeFqdn);
pMeta->vgroup.ipAddr[i].port = htons(pDnode->dnodePort + TSDB_PORT_DNODESHELL); pMeta->vgroup.ipAddr[i].port = htons(pDnode->dnodePort + TSDB_PORT_DNODESHELL);
pMeta->vgroup.numOfIps++; pMeta->vgroup.numOfIps++;
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
pMeta->vgroup.vgId = htonl(pMsg->pVgroup->vgId); pMeta->vgroup.vgId = htonl(pMsg->pVgroup->vgId);
...@@ -1740,7 +1725,7 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { ...@@ -1740,7 +1725,7 @@ static int32_t mgmtDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) { static int32_t mgmtAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMTableInfoMsg *pInfo = pMsg->pCont; SCMTableInfoMsg *pInfo = pMsg->pCont;
STagData* pTag = (STagData*)pInfo->tags; STagData* pTag = (STagData*)pInfo->tags;
...@@ -1748,8 +1733,7 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) { ...@@ -1748,8 +1733,7 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen); SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen);
if (pCreateMsg == NULL) { if (pCreateMsg == NULL) {
mError("table:%s, failed to create table while get meta info, no enough memory", pInfo->tableId); 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 TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId)); strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId));
...@@ -1760,34 +1744,33 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) { ...@@ -1760,34 +1744,33 @@ static void mgmtAutoCreateChildTable(SMnodeMsg *pMsg) {
memcpy(pCreateMsg->schema, pInfo->tags, contLen - sizeof(SCMCreateTableMsg)); memcpy(pCreateMsg->schema, pInfo->tags, contLen - sizeof(SCMCreateTableMsg));
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(pMsg); pMsg->msgType = TSDB_MSG_TYPE_CM_CREATE_TABLE;
newMsg->msgType = TSDB_MSG_TYPE_CM_CREATE_TABLE; rpcFreeCont(pMsg->pCont);
newMsg->pCont = pCreateMsg; pMsg->pCont = pCreateMsg;
pMsg->contLen = contLen;
mTrace("table:%s, start to create on demand, stable:%s", pInfo->tableId, pInfo->tags); mTrace("table:%s, start to create on demand, stable:%s", pInfo->tableId, pInfo->tags);
mgmtAddToShellQueue(newMsg);
return TSDB_CODE_ACTION_NEED_REPROCESSED;
} }
static void mgmtGetChildTableMeta(SMnodeMsg *pMsg) { static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) {
STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16));
if (pMeta == NULL) { if (pMeta == NULL) {
mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId); mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
mgmtDoGetChildTableMeta(pMsg, pMeta); mnodeDoGetChildTableMeta(pMsg, pMeta);
SRpcMsg rpcRsp = { pMsg->rpcRsp.len = pMeta->contLen;
.handle = pMsg->thandle, pMsg->rpcRsp.rsp = pMeta;
.pCont = pMeta,
.contLen = pMeta->contLen,
};
pMeta->contLen = htons(pMeta->contLen); pMeta->contLen = htons(pMeta->contLen);
rpcSendResponse(&rpcRsp);
return TSDB_CODE_SUCCESS;
} }
void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) { void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfTables = 0; int32_t numOfTables = 0;
SChildTableObj *pTable = NULL; SChildTableObj *pTable = NULL;
...@@ -1795,7 +1778,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) { ...@@ -1795,7 +1778,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
mPrint("vgId:%d, all child tables will be dropped from sdb", pVgroup->vgId); mPrint("vgId:%d, all child tables will be dropped from sdb", pVgroup->vgId);
while (1) { while (1) {
pIter = mgmtGetNextChildTable(pIter, &pTable); pIter = mnodeGetNextChildTable(pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
if (pTable->vgId == pVgroup->vgId) { if (pTable->vgId == pVgroup->vgId) {
...@@ -1807,7 +1790,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) { ...@@ -1807,7 +1790,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
numOfTables++; numOfTables++;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -1815,7 +1798,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) { ...@@ -1815,7 +1798,7 @@ void mgmtDropAllChildTablesInVgroups(SVgObj *pVgroup) {
mPrint("vgId:%d, all child tables is dropped from sdb", pVgroup->vgId); mPrint("vgId:%d, all child tables is dropped from sdb", pVgroup->vgId);
} }
void mgmtDropAllChildTables(SDbObj *pDropDb) { void mnodeDropAllChildTables(SDbObj *pDropDb) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfTables = 0; int32_t numOfTables = 0;
int32_t dbNameLen = strlen(pDropDb->name); int32_t dbNameLen = strlen(pDropDb->name);
...@@ -1824,7 +1807,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) { ...@@ -1824,7 +1807,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
mPrint("db:%s, all child tables will be dropped from sdb", pDropDb->name); mPrint("db:%s, all child tables will be dropped from sdb", pDropDb->name);
while (1) { while (1) {
pIter = mgmtGetNextChildTable(pIter, &pTable); pIter = mnodeGetNextChildTable(pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) { if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) {
...@@ -1836,7 +1819,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) { ...@@ -1836,7 +1819,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
numOfTables++; numOfTables++;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -1844,7 +1827,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) { ...@@ -1844,7 +1827,7 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
mPrint("db:%s, all child tables:%d is dropped from sdb", pDropDb->name, numOfTables); mPrint("db:%s, all child tables:%d is dropped from sdb", pDropDb->name, numOfTables);
} }
static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) { static void mnodeDropAllChildTablesInStable(SSuperTableObj *pStable) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfTables = 0; int32_t numOfTables = 0;
SChildTableObj *pTable = NULL; SChildTableObj *pTable = NULL;
...@@ -1852,7 +1835,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) { ...@@ -1852,7 +1835,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
mPrint("stable:%s, all child tables will dropped from sdb", pStable->info.tableId, numOfTables); mPrint("stable:%s, all child tables will dropped from sdb", pStable->info.tableId, numOfTables);
while (1) { while (1) {
pIter = mgmtGetNextChildTable(pIter, &pTable); pIter = mnodeGetNextChildTable(pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
if (pTable->superTable == pStable) { if (pTable->superTable == pStable) {
...@@ -1865,7 +1848,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) { ...@@ -1865,7 +1848,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
numOfTables++; numOfTables++;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -1873,42 +1856,39 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) { ...@@ -1873,42 +1856,39 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
mPrint("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables); mPrint("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables);
} }
static SChildTableObj* mgmtGetTableByPos(int32_t vnode, int32_t sid) { static SChildTableObj* mnodeGetTableByPos(int32_t vnode, int32_t sid) {
SVgObj *pVgroup = mgmtGetVgroup(vnode); SVgObj *pVgroup = mnodeGetVgroup(vnode);
if (pVgroup == NULL) return NULL; if (pVgroup == NULL) return NULL;
SChildTableObj *pTable = pVgroup->tableList[sid - 1]; SChildTableObj *pTable = pVgroup->tableList[sid - 1];
mgmtIncTableRef((STableObj *)pTable); mnodeIncTableRef((STableObj *)pTable);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
return pTable; return pTable;
} }
static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg) { static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
SDMConfigTableMsg *pCfg = (SDMConfigTableMsg *) rpcMsg->pCont; SDMConfigTableMsg *pCfg = (SDMConfigTableMsg *) pMsg->pCont;
pCfg->dnode = htonl(pCfg->dnode); pCfg->dnode = htonl(pCfg->dnode);
pCfg->vnode = htonl(pCfg->vnode); pCfg->vnode = htonl(pCfg->vnode);
pCfg->sid = htonl(pCfg->sid); pCfg->sid = htonl(pCfg->sid);
mTrace("dnode:%s, vnode:%d, sid:%d, receive table config msg", taosIpStr(pCfg->dnode), pCfg->vnode, pCfg->sid); mTrace("dnode:%s, vnode:%d, sid:%d, receive table config msg", taosIpStr(pCfg->dnode), pCfg->vnode, pCfg->sid);
SChildTableObj *pTable = mgmtGetTableByPos(pCfg->vnode, pCfg->sid); SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vnode, pCfg->sid);
if (pTable == NULL) { if (pTable == NULL) {
mError("dnode:%s, vnode:%d, sid:%d, table not found", taosIpStr(pCfg->dnode), pCfg->vnode, pCfg->sid); 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 TSDB_CODE_NOT_ACTIVE_TABLE;
return;
} }
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SUCCESS);
SMDCreateTableMsg *pMDCreate = NULL; SMDCreateTableMsg *pMDCreate = NULL;
pMDCreate = mgmtBuildCreateChildTableMsg(NULL, (SChildTableObj *) pTable); pMDCreate = mgmtBuildCreateChildTableMsg(NULL, (SChildTableObj *) pTable);
if (pMDCreate == NULL) { if (pMDCreate == NULL) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
return; return terrno;
} }
SDnodeObj *pDnode = mgmtGetDnode(pCfg->dnode); SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnode);
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = NULL, .handle = NULL,
.pCont = pMDCreate, .pCont = pMDCreate,
...@@ -1918,32 +1898,33 @@ static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg) { ...@@ -1918,32 +1898,33 @@ static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg) {
}; };
dnodeSendMsgToDnode(&ipSet, &rpcRsp); dnodeSendMsgToDnode(&ipSet, &rpcRsp);
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
return TSDB_CODE_SUCCESS;
} }
// handle drop child response // handle drop child response
static void mgmtProcessDropChildTableRsp(SRpcMsg *rpcMsg) { static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
if (rpcMsg->handle == NULL) return; if (rpcMsg->handle == NULL) return;
SMnodeMsg *queueMsg = rpcMsg->handle; SMnodeMsg *mnodeMsg = rpcMsg->handle;
queueMsg->received++; mnodeMsg->received++;
SChildTableObj *pTable = queueMsg->ahandle; SChildTableObj *pTable = mnodeMsg->ahandle;
mPrint("table:%s, drop table rsp received, thandle:%p result:%s", pTable->info.tableId, queueMsg->thandle, tstrerror(rpcMsg->code)); mPrint("table:%s, drop table rsp received, thandle:%p result:%s", pTable->info.tableId, mnodeMsg->thandle, tstrerror(rpcMsg->code));
if (rpcMsg->code != TSDB_CODE_SUCCESS) { if (rpcMsg->code != TSDB_CODE_SUCCESS) {
mError("table:%s, failed to drop in dnode, reason:%s", pTable->info.tableId, tstrerror(rpcMsg->code)); mError("table:%s, failed to drop in dnode, reason:%s", pTable->info.tableId, tstrerror(rpcMsg->code));
mgmtSendSimpleResp(queueMsg->thandle, rpcMsg->code); dnodeSendRpcMnodeWriteRsp(mnodeMsg, rpcMsg->code);
free(queueMsg); mnodeDecTableRef(pTable);
mgmtDecTableRef(pTable);
return; return;
} }
if (queueMsg->pVgroup == NULL) queueMsg->pVgroup = mgmtGetVgroup(pTable->vgId); if (mnodeMsg->pVgroup == NULL) mnodeMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (queueMsg->pVgroup == NULL) { if (mnodeMsg->pVgroup == NULL) {
mError("table:%s, failed to get vgroup", pTable->info.tableId); 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; return;
} }
...@@ -1956,39 +1937,38 @@ static void mgmtProcessDropChildTableRsp(SRpcMsg *rpcMsg) { ...@@ -1956,39 +1937,38 @@ static void mgmtProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("table:%s, update ctables sdb error", pTable->info.tableId); mError("table:%s, update ctables sdb error", pTable->info.tableId);
mgmtSendSimpleResp(queueMsg->thandle, TSDB_CODE_SDB_ERROR); dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SDB_ERROR);
return; return;
} }
if (queueMsg->pVgroup->numOfTables <= 0) { if (mnodeMsg->pVgroup->numOfTables <= 0) {
mPrint("vgId:%d, all tables is dropped, drop vgroup", queueMsg->pVgroup->vgId); mPrint("vgId:%d, all tables is dropped, drop vgroup", mnodeMsg->pVgroup->vgId);
mgmtDropVgroup(queueMsg->pVgroup, NULL); mnodeDropVgroup(mnodeMsg->pVgroup, NULL);
} }
mgmtSendSimpleResp(queueMsg->thandle, TSDB_CODE_SUCCESS); dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SUCCESS);
mgmtFreeQueuedMsg(queueMsg);
} }
// handle create table response from dnode // handle create table response from dnode
// if failed, drop the table cached // if failed, drop the table cached
static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
if (rpcMsg->handle == NULL) return; if (rpcMsg->handle == NULL) return;
SMnodeMsg *queueMsg = rpcMsg->handle; SMnodeMsg *mnodeMsg = rpcMsg->handle;
queueMsg->received++; mnodeMsg->received++;
SChildTableObj *pTable = queueMsg->ahandle; SChildTableObj *pTable = mnodeMsg->ahandle;
mTrace("table:%s, create table rsp received, thandle:%p result:%s", pTable->info.tableId, queueMsg->thandle, mTrace("table:%s, create table rsp received, thandle:%p result:%s", pTable->info.tableId, mnodeMsg->thandle,
tstrerror(rpcMsg->code)); tstrerror(rpcMsg->code));
if (rpcMsg->code != TSDB_CODE_SUCCESS) { if (rpcMsg->code != TSDB_CODE_SUCCESS) {
if (queueMsg->retry++ < queueMsg->maxRetry) { if (mnodeMsg->retry++ < mnodeMsg->maxRetry) {
mTrace("table:%s, create table rsp received, retry:%d thandle:%p result:%s", pTable->info.tableId, mTrace("table:%s, create table rsp received, retry:%d thandle:%p result:%s", pTable->info.tableId,
queueMsg->retry, queueMsg->thandle, tstrerror(rpcMsg->code)); mnodeMsg->retry, mnodeMsg->thandle, tstrerror(rpcMsg->code));
mgmtDealyedAddToShellQueue(queueMsg); dnodeDelayReprocessMnodeWriteMsg(mnodeMsg);
} else { } else {
mError("table:%s, failed to create in dnode, thandle:%p result:%s", pTable->info.tableId, mError("table:%s, failed to create in dnode, thandle:%p result:%s", pTable->info.tableId,
queueMsg->thandle, tstrerror(rpcMsg->code)); mnodeMsg->thandle, tstrerror(rpcMsg->code));
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -1997,38 +1977,35 @@ static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { ...@@ -1997,38 +1977,35 @@ static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
}; };
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
mgmtSendSimpleResp(queueMsg->thandle, rpcMsg->code); dnodeSendRpcMnodeWriteRsp(mnodeMsg, rpcMsg->code);
mgmtFreeQueuedMsg(queueMsg);
} }
} else { } else {
mTrace("table:%s, created in dnode, thandle:%p result:%s", pTable->info.tableId, queueMsg->thandle, mTrace("table:%s, created in dnode, thandle:%p result:%s", pTable->info.tableId, mnodeMsg->thandle,
tstrerror(rpcMsg->code)); tstrerror(rpcMsg->code));
SCMCreateTableMsg *pCreate = queueMsg->pCont; SCMCreateTableMsg *pCreate = mnodeMsg->pCont;
if (pCreate->getMeta) { if (pCreate->getMeta) {
mTrace("table:%s, continue to get meta", pTable->info.tableId); mTrace("table:%s, continue to get meta", pTable->info.tableId);
queueMsg->retry = 0; mnodeMsg->retry = 0;
mgmtAddToShellQueue(queueMsg); dnodeReprocessMnodeWriteMsg(mnodeMsg);
} else { } else {
mgmtSendSimpleResp(queueMsg->thandle, rpcMsg->code); dnodeSendRpcMnodeWriteRsp(mnodeMsg, rpcMsg->code);
mgmtFreeQueuedMsg(queueMsg);
} }
} }
} }
// not implemented yet // not implemented yet
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg) { static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg) {
mTrace("alter table rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code)); mTrace("alter table rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code));
} }
static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
SCMMultiTableInfoMsg *pInfo = pMsg->pCont; SCMMultiTableInfoMsg *pInfo = pMsg->pCont;
pInfo->numOfTables = htonl(pInfo->numOfTables); pInfo->numOfTables = htonl(pInfo->numOfTables);
int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice
SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen); SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen);
if (pMultiMeta == NULL) { if (pMultiMeta == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} }
pMultiMeta->contLen = sizeof(SMultiTableMeta); pMultiMeta->contLen = sizeof(SMultiTableMeta);
...@@ -2036,12 +2013,12 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { ...@@ -2036,12 +2013,12 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
for (int32_t t = 0; t < pInfo->numOfTables; ++t) { for (int32_t t = 0; t < pInfo->numOfTables; ++t) {
char * tableId = (char *)(pInfo->tableIds + t * TSDB_TABLE_ID_LEN + 1); char * tableId = (char *)(pInfo->tableIds + t * TSDB_TABLE_ID_LEN + 1);
SChildTableObj *pTable = mgmtGetChildTable(tableId); SChildTableObj *pTable = mnodeGetChildTable(tableId);
if (pTable == NULL) continue; if (pTable == NULL) continue;
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDbByTableId(tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(tableId);
if (pMsg->pDb == NULL) { if (pMsg->pDb == NULL) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -2050,35 +2027,33 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { ...@@ -2050,35 +2027,33 @@ static void mgmtProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
totalMallocLen *= 2; totalMallocLen *= 2;
pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen); pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen);
if (pMultiMeta == NULL) { if (pMultiMeta == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); mnodeDecTableRef(pTable);
mgmtDecTableRef(pTable); return TSDB_CODE_SERV_OUT_OF_MEMORY;
return;
} else { } else {
t--; t--;
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
} }
STableMetaMsg *pMeta = (STableMetaMsg *)(pMultiMeta->metas + pMultiMeta->contLen); STableMetaMsg *pMeta = (STableMetaMsg *)(pMultiMeta->metas + pMultiMeta->contLen);
int32_t code = mgmtDoGetChildTableMeta(pMsg, pMeta); int32_t code = mnodeDoGetChildTableMeta(pMsg, pMeta);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
pMultiMeta->numOfTables ++; pMultiMeta->numOfTables ++;
pMultiMeta->contLen += pMeta->contLen; pMultiMeta->contLen += pMeta->contLen;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
SRpcMsg rpcRsp = {0}; pMsg->rpcRsp.rsp = pMultiMeta;
rpcRsp.handle = pMsg->thandle; pMsg->rpcRsp.len = pMultiMeta->contLen;
rpcRsp.pCont = pMultiMeta;
rpcRsp.contLen = pMultiMeta->contLen; return TSDB_CODE_SUCCESS;
rpcSendResponse(&rpcRsp);
} }
static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED;
int32_t cols = 0; int32_t cols = 0;
...@@ -2119,7 +2094,7 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void ...@@ -2119,7 +2094,7 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
pShow->numOfRows = pDb->numOfTables; pShow->numOfRows = pDb->numOfTables;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return 0; return 0;
} }
...@@ -2131,8 +2106,8 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_ ...@@ -2131,8 +2106,8 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_
} }
} }
static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return 0; if (pDb == NULL) return 0;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -2145,12 +2120,12 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, ...@@ -2145,12 +2120,12 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
int32_t prefixLen = strlen(prefix); int32_t prefixLen = strlen(prefix);
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextChildTable(pShow->pIter, &pTable); pShow->pIter = mnodeGetNextChildTable(pShow->pIter, &pTable);
if (pTable == NULL) break; if (pTable == NULL) break;
// not belong to current db // not belong to current db
if (strncmp(pTable->info.tableId, prefix, prefixLen)) { if (strncmp(pTable->info.tableId, prefix, prefixLen)) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -2160,7 +2135,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, ...@@ -2160,7 +2135,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
mgmtExtractTableName(pTable->info.tableId, tableName); mgmtExtractTableName(pTable->info.tableId, tableName);
if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) { if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
continue; continue;
} }
...@@ -2195,40 +2170,37 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, ...@@ -2195,40 +2170,37 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
cols++; cols++;
numOfRows++; numOfRows++;
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
const int32_t NUM_OF_COLUMNS = 4; const int32_t NUM_OF_COLUMNS = 4;
mgmtVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow); mgmtVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow);
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return numOfRows; return numOfRows;
} }
static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
SCMAlterTableMsg *pAlter = pMsg->pCont; SCMAlterTableMsg *pAlter = pMsg->pCont;
mTrace("table:%s, alter table msg is received from thandle:%p", pAlter->tableId, pMsg->thandle); mTrace("table:%s, alter table msg is received from thandle:%p", pAlter->tableId, pMsg->thandle);
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDbByTableId(pAlter->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to alter table, db not selected", pAlter->tableId); mError("table:%s, failed to alter table, db not selected", pAlter->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); return TSDB_CODE_DB_NOT_SELECTED;
return;
} }
if (mgmtCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("table:%s, failed to alter table, its log db", pAlter->tableId); mError("table:%s, failed to alter table, its log db", pAlter->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MONITOR_DB_FORBIDDEN); return TSDB_CODE_MONITOR_DB_FORBIDDEN;
return;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pAlter->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId); mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE); return TSDB_CODE_INVALID_TABLE;
return;
} }
pAlter->type = htons(pAlter->type); pAlter->type = htons(pAlter->type);
...@@ -2237,8 +2209,7 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) { ...@@ -2237,8 +2209,7 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
if (pAlter->numOfCols > 2) { if (pAlter->numOfCols > 2) {
mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols); mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_APP_ERROR); return TSDB_CODE_APP_ERROR;
return;
} }
for (int32_t i = 0; i < pAlter->numOfCols; ++i) { for (int32_t i = 0; i < pAlter->numOfCols; ++i) {
...@@ -2250,15 +2221,15 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) { ...@@ -2250,15 +2221,15 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
mTrace("table:%s, start to alter stable", pAlter->tableId); mTrace("table:%s, start to alter stable", pAlter->tableId);
if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
code = mgmtAddSuperTableTag(pTable, pAlter->schema, 1); code = mnodeAddSuperTableTag(pTable, pAlter->schema, 1);
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
code = mgmtDropSuperTableTag(pTable, pAlter->schema[0].name); code = mnodeDropSuperTableTag(pTable, pAlter->schema[0].name);
} else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
code = mgmtModifySuperTableTagName(pTable, pAlter->schema[0].name, pAlter->schema[1].name); code = mnodeModifySuperTableTagName(pTable, pAlter->schema[0].name, pAlter->schema[1].name);
} else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
code = mgmtAddSuperTableColumn(pMsg->pDb, pTable, pAlter->schema, 1); code = mnodeAddSuperTableColumn(pMsg->pDb, pTable, pAlter->schema, 1);
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
code = mgmtDropSuperTableColumn(pMsg->pDb, pTable, pAlter->schema[0].name); code = mnodeDropSuperTableColumn(pMsg->pDb, pTable, pAlter->schema[0].name);
} else { } else {
} }
} else { } else {
...@@ -2266,14 +2237,14 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) { ...@@ -2266,14 +2237,14 @@ static void mgmtProcessAlterTableMsg(SMnodeMsg *pMsg) {
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
char *tagVal = (char*)(pAlter->schema + pAlter->numOfCols); char *tagVal = (char*)(pAlter->schema + pAlter->numOfCols);
code = mgmtModifyChildTableTagValue(pTable, pAlter->schema[0].name, tagVal); code = mnodeModifyChildTableTagValue(pTable, pAlter->schema[0].name, tagVal);
} else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
code = mgmtAddNormalTableColumn(pMsg->pDb, pTable, pAlter->schema, 1); code = mnodeAddNormalTableColumn(pMsg->pDb, pTable, pAlter->schema, 1);
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
code = mgmtDropNormalTableColumn(pMsg->pDb, pTable, pAlter->schema[0].name); code = mnodeDropNormalTableColumn(pMsg->pDb, pTable, pAlter->schema[0].name);
} else { } else {
} }
} }
mgmtSendSimpleResp(pMsg->thandle, code); return code;
} }
...@@ -21,36 +21,39 @@ ...@@ -21,36 +21,39 @@
#include "tglobal.h" #include "tglobal.h"
#include "tgrant.h" #include "tgrant.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeWrite.h"
#include "mnodePeer.h"
static void * tsUserSdb = NULL; static void * tsUserSdb = NULL;
static int32_t tsUserUpdateSize = 0; static int32_t tsUserUpdateSize = 0;
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static void mgmtProcessCreateUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg);
static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg);
static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg);
static void mgmtProcessAuthMsg(SRpcMsg *rpcMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg);
static int32_t mgmtUserActionDestroy(SSdbOper *pOper) { static int32_t mnodeUserActionDestroy(SSdbOper *pOper) {
tfree(pOper->pObj); tfree(pOper->pObj);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionInsert(SSdbOper *pOper) { static int32_t mnodeUserActionInsert(SSdbOper *pOper) {
SUserObj *pUser = pOper->pObj; SUserObj *pUser = pOper->pObj;
SAcctObj *pAcct = mgmtGetAcct(pUser->acct); SAcctObj *pAcct = mnodeGetAcct(pUser->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
mgmtAddUserToAcct(pAcct, pUser); mnodeAddUserToAcct(pAcct, pUser);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} else { } else {
mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct); mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_INVALID_ACCT;
...@@ -59,37 +62,37 @@ static int32_t mgmtUserActionInsert(SSdbOper *pOper) { ...@@ -59,37 +62,37 @@ static int32_t mgmtUserActionInsert(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionDelete(SSdbOper *pOper) { static int32_t mnodeUserActionDelete(SSdbOper *pOper) {
SUserObj *pUser = pOper->pObj; SUserObj *pUser = pOper->pObj;
SAcctObj *pAcct = mgmtGetAcct(pUser->acct); SAcctObj *pAcct = mnodeGetAcct(pUser->acct);
if (pAcct != NULL) { if (pAcct != NULL) {
mgmtDropUserFromAcct(pAcct, pUser); mnodeDropUserFromAcct(pAcct, pUser);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionUpdate(SSdbOper *pOper) { static int32_t mnodeUserActionUpdate(SSdbOper *pOper) {
SUserObj *pUser = pOper->pObj; SUserObj *pUser = pOper->pObj;
SUserObj *pSaved = mgmtGetUser(pUser->user); SUserObj *pSaved = mnodeGetUser(pUser->user);
if (pUser != pSaved) { if (pUser != pSaved) {
memcpy(pSaved, pUser, tsUserUpdateSize); memcpy(pSaved, pUser, tsUserUpdateSize);
free(pUser); free(pUser);
} }
mgmtDecUserRef(pSaved); mnodeDecUserRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionEncode(SSdbOper *pOper) { static int32_t mnodeUserActionEncode(SSdbOper *pOper) {
SUserObj *pUser = pOper->pObj; SUserObj *pUser = pOper->pObj;
memcpy(pOper->rowData, pUser, tsUserUpdateSize); memcpy(pOper->rowData, pUser, tsUserUpdateSize);
pOper->rowSize = tsUserUpdateSize; pOper->rowSize = tsUserUpdateSize;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionDecode(SSdbOper *pOper) { static int32_t mnodeUserActionDecode(SSdbOper *pOper) {
SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj));
if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -98,19 +101,19 @@ static int32_t mgmtUserActionDecode(SSdbOper *pOper) { ...@@ -98,19 +101,19 @@ static int32_t mgmtUserActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtUserActionRestored() { static int32_t mnodeUserActionRestored() {
if (dnodeIsFirstDeploy()) { if (dnodeIsFirstDeploy()) {
SAcctObj *pAcct = mgmtGetAcct("root"); SAcctObj *pAcct = mnodeGetAcct("root");
mgmtCreateUser(pAcct, "root", "taosdata"); mnodeCreateUser(pAcct, "root", "taosdata");
mgmtCreateUser(pAcct, "monitor", tsInternalPass); mnodeCreateUser(pAcct, "monitor", tsInternalPass);
mgmtCreateUser(pAcct, "_root", tsInternalPass); mnodeCreateUser(pAcct, "_root", tsInternalPass);
mgmtDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitUsers() { int32_t mnodeInitUsers() {
SUserObj tObj; SUserObj tObj;
tsUserUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsUserUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -121,13 +124,13 @@ int32_t mgmtInitUsers() { ...@@ -121,13 +124,13 @@ int32_t mgmtInitUsers() {
.maxRowSize = tsUserUpdateSize, .maxRowSize = tsUserUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_STRING, .keyType = SDB_KEY_STRING,
.insertFp = mgmtUserActionInsert, .insertFp = mnodeUserActionInsert,
.deleteFp = mgmtUserActionDelete, .deleteFp = mnodeUserActionDelete,
.updateFp = mgmtUserActionUpdate, .updateFp = mnodeUserActionUpdate,
.encodeFp = mgmtUserActionEncode, .encodeFp = mnodeUserActionEncode,
.decodeFp = mgmtUserActionDecode, .decodeFp = mnodeUserActionDecode,
.destroyFp = mgmtUserActionDestroy, .destroyFp = mnodeUserActionDestroy,
.restoredFp = mgmtUserActionRestored .restoredFp = mnodeUserActionRestored
}; };
tsUserSdb = sdbOpenTable(&tableDesc); tsUserSdb = sdbOpenTable(&tableDesc);
...@@ -136,38 +139,38 @@ int32_t mgmtInitUsers() { ...@@ -136,38 +139,38 @@ int32_t mgmtInitUsers() {
return -1; return -1;
} }
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CREATE_USER, mgmtProcessCreateUserMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_USER, mnodeProcessCreateUserMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_ALTER_USER, mgmtProcessAlterUserMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_ALTER_USER, mnodeProcessAlterUserMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_DROP_USER, mgmtProcessDropUserMsg); mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_USER, mnodeProcessDropUserMsg);
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_USER, mgmtGetUserMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_USER, mnodeGetUserMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_USER, mgmtRetrieveUsers); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mnodeRetrieveUsers);
dnodeAddServerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mgmtProcessAuthMsg); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg);
mTrace("table:%s, hash is created", tableDesc.tableName); mTrace("table:%s, hash is created", tableDesc.tableName);
return 0; return 0;
} }
void mgmtCleanUpUsers() { void mnodeCleanupUsers() {
sdbCloseTable(tsUserSdb); sdbCloseTable(tsUserSdb);
} }
SUserObj *mgmtGetUser(char *name) { SUserObj *mnodeGetUser(char *name) {
return (SUserObj *)sdbGetRow(tsUserSdb, name); return (SUserObj *)sdbGetRow(tsUserSdb, name);
} }
void *mgmtGetNextUser(void *pIter, SUserObj **pUser) { void *mnodeGetNextUser(void *pIter, SUserObj **pUser) {
return sdbFetchRow(tsUserSdb, pIter, (void **)pUser); return sdbFetchRow(tsUserSdb, pIter, (void **)pUser);
} }
void mgmtIncUserRef(SUserObj *pUser) { void mnodeIncUserRef(SUserObj *pUser) {
return sdbIncRef(tsUserSdb, pUser); return sdbIncRef(tsUserSdb, pUser);
} }
void mgmtDecUserRef(SUserObj *pUser) { void mnodeDecUserRef(SUserObj *pUser) {
return sdbDecRef(tsUserSdb, pUser); return sdbDecRef(tsUserSdb, pUser);
} }
static int32_t mgmtUpdateUser(SUserObj *pUser) { static int32_t mnodeUpdateUser(SUserObj *pUser) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsUserSdb, .table = tsUserSdb,
...@@ -182,7 +185,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) { ...@@ -182,7 +185,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
return code; return code;
} }
int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) {
int32_t code = acctCheck(pAcct, ACCT_GRANT_USER); int32_t code = acctCheck(pAcct, ACCT_GRANT_USER);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
...@@ -196,10 +199,10 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { ...@@ -196,10 +199,10 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return TSDB_CODE_INVALID_PASS_FORMAT; return TSDB_CODE_INVALID_PASS_FORMAT;
} }
SUserObj *pUser = mgmtGetUser(name); SUserObj *pUser = mnodeGetUser(name);
if (pUser != NULL) { if (pUser != NULL) {
mTrace("user:%s, is already there", name); mTrace("user:%s, is already there", name);
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_USER_ALREADY_EXIST; return TSDB_CODE_USER_ALREADY_EXIST;
} }
...@@ -235,7 +238,7 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { ...@@ -235,7 +238,7 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return code; return code;
} }
static int32_t mgmtDropUser(SUserObj *pUser) { static int32_t mnodeDropUser(SUserObj *pUser) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsUserSdb, .table = tsUserSdb,
...@@ -250,8 +253,8 @@ static int32_t mgmtDropUser(SUserObj *pUser) { ...@@ -250,8 +253,8 @@ static int32_t mgmtDropUser(SUserObj *pUser) {
return code; return code;
} }
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_NO_USER_FROM_CONN; return TSDB_CODE_NO_USER_FROM_CONN;
} }
...@@ -289,18 +292,18 @@ static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon ...@@ -289,18 +292,18 @@ static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon
pShow->numOfRows = pUser->pAcct->acctInfo.numOfUsers; pShow->numOfRows = pUser->pAcct->acctInfo.numOfUsers;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
return 0; return 0;
} }
static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
int32_t cols = 0; int32_t cols = 0;
char *pWrite; char *pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pIter = mgmtGetNextUser(pShow->pIter, &pUser); pShow->pIter = mnodeGetNextUser(pShow->pIter, &pUser);
if (pUser == NULL) break; if (pUser == NULL) break;
cols = 0; cols = 0;
...@@ -327,30 +330,30 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void ...@@ -327,30 +330,30 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
cols++; cols++;
numOfRows++; numOfRows++;
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
return numOfRows; return numOfRows;
} }
SUserObj *mgmtGetUserFromConn(void *pConn) { SUserObj *mnodeGetUserFromConn(void *pConn) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
if (rpcGetConnInfo(pConn, &connInfo) == 0) { if (rpcGetConnInfo(pConn, &connInfo) == 0) {
return mgmtGetUser(connInfo.user); return mnodeGetUser(connInfo.user);
} else { } else {
mError("can not get user from conn:%p", pConn); mError("can not get user from conn:%p", pConn);
return NULL; return NULL;
} }
} }
static void mgmtProcessCreateUserMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
int32_t code; int32_t code;
SUserObj *pOperUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
if (pOperUser->superAuth) { if (pOperUser->superAuth) {
SCMCreateUserMsg *pCreate = pMsg->pCont; SCMCreateUserMsg *pCreate = pMsg->pCont;
code = mgmtCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass); code = mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("user:%s, is created by %s", pCreate->user, pOperUser->user); mLPrint("user:%s, is created by %s", pCreate->user, pOperUser->user);
} }
...@@ -359,24 +362,22 @@ static void mgmtProcessCreateUserMsg(SMnodeMsg *pMsg) { ...@@ -359,24 +362,22 @@ static void mgmtProcessCreateUserMsg(SMnodeMsg *pMsg) {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
mgmtSendSimpleResp(pMsg->thandle, code); return code;
} }
static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
int32_t code; int32_t code;
SUserObj *pOperUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
SCMAlterUserMsg *pAlter = pMsg->pCont; SCMAlterUserMsg *pAlter = pMsg->pCont;
SUserObj *pUser = mgmtGetUser(pAlter->user); SUserObj *pUser = mnodeGetUser(pAlter->user);
if (pUser == NULL) { if (pUser == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_USER); return TSDB_CODE_INVALID_USER;
return;
} }
if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_NO_RIGHTS); mnodeDecUserRef(pUser);
mgmtDecUserRef(pUser); return TSDB_CODE_NO_RIGHTS;
return;
} }
if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) {
...@@ -398,14 +399,12 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) { ...@@ -398,14 +399,12 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) {
if (hasRight) { if (hasRight) {
memset(pUser->pass, 0, sizeof(pUser->pass)); memset(pUser->pass, 0, sizeof(pUser->pass));
taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass); taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass);
code = mgmtUpdateUser(pUser); code = mnodeUpdateUser(pUser);
mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); mError("user:%s, no rights to alter user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
mgmtSendSimpleResp(pMsg->thandle, code);
} else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { } else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) {
bool hasRight = false; bool hasRight = false;
...@@ -441,38 +440,35 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) { ...@@ -441,38 +440,35 @@ static void mgmtProcessAlterUserMsg(SMnodeMsg *pMsg) {
pUser->writeAuth = 1; pUser->writeAuth = 1;
} }
code = mgmtUpdateUser(pUser); code = mnodeUpdateUser(pUser);
mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); mError("user:%s, no rights to alter user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
mgmtSendSimpleResp(pMsg->thandle, code);
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); 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 mgmtProcessDropUserMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) {
int32_t code; int32_t code;
SUserObj *pOperUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
SCMDropUserMsg *pDrop = pMsg->pCont; SCMDropUserMsg *pDrop = pMsg->pCont;
SUserObj *pUser = mgmtGetUser(pDrop->user); SUserObj *pUser = mnodeGetUser(pDrop->user);
if (pUser == NULL) { if (pUser == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_USER); return TSDB_CODE_INVALID_USER;
return;
} }
if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 ||
(strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_NO_RIGHTS); mnodeDecUserRef(pUser);
mgmtDecUserRef(pUser); return TSDB_CODE_NO_RIGHTS;
return ;
} }
bool hasRight = false; bool hasRight = false;
...@@ -491,7 +487,7 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) { ...@@ -491,7 +487,7 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) {
} }
if (hasRight) { if (hasRight) {
code = mgmtDropUser(pUser); code = mnodeDropUser(pUser);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} }
...@@ -499,18 +495,18 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) { ...@@ -499,18 +495,18 @@ static void mgmtProcessDropUserMsg(SMnodeMsg *pMsg) {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
mgmtSendSimpleResp(pMsg->thandle, code); mnodeDecUserRef(pUser);
mgmtDecUserRef(pUser); return code;
} }
void mgmtDropAllUsers(SAcctObj *pAcct) { void mnodeDropAllUsers(SAcctObj *pAcct) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfUsers = 0; int32_t numOfUsers = 0;
int32_t acctNameLen = strlen(pAcct->user); int32_t acctNameLen = strlen(pAcct->user);
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
while (1) { while (1) {
pIter = mgmtGetNextUser(pIter, &pUser); pIter = mnodeGetNextUser(pIter, &pUser);
if (pUser == NULL) break; if (pUser == NULL) break;
if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) {
...@@ -523,7 +519,7 @@ void mgmtDropAllUsers(SAcctObj *pAcct) { ...@@ -523,7 +519,7 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
numOfUsers++; numOfUsers++;
} }
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -531,14 +527,14 @@ void mgmtDropAllUsers(SAcctObj *pAcct) { ...@@ -531,14 +527,14 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
mTrace("acct:%s, all users:%d is dropped from sdb", pAcct->user, numOfUsers); mTrace("acct:%s, all users:%d is dropped from sdb", pAcct->user, numOfUsers);
} }
int32_t mgmtRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
*secret = 0; *secret = 0;
mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_NOT_READY)); mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_NOT_READY));
return TSDB_CODE_NOT_READY; return TSDB_CODE_NOT_READY;
} }
SUserObj *pUser = mgmtGetUser(user); SUserObj *pUser = mnodeGetUser(user);
if (pUser == NULL) { if (pUser == NULL) {
*secret = 0; *secret = 0;
mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_INVALID_USER)); 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 ...@@ -549,21 +545,18 @@ int32_t mgmtRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char
*ckey = 0; *ckey = 0;
memcpy(secret, pUser->pass, TSDB_KEY_LEN); memcpy(secret, pUser->pass, TSDB_KEY_LEN);
mgmtDecUserRef(pUser); mnodeDecUserRef(pUser);
mTrace("user:%s, auth info is returned", user); mTrace("user:%s, auth info is returned", user);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
static void mgmtProcessAuthMsg(SRpcMsg *rpcMsg) { static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = rpcMsg->handle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SDMAuthMsg *pAuthMsg = pMsg->pCont;
SDMAuthMsg *pAuthMsg = rpcMsg->pCont;
SDMAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SDMAuthRsp)); SDMAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SDMAuthRsp));
rpcRsp.code = mgmtRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey); pMsg->rpcRsp.rsp = pAuthRsp;
rpcRsp.pCont = pAuthRsp; pMsg->rpcRsp.len = sizeof(SDMAuthRsp);
rpcRsp.contLen = sizeof(SDMAuthRsp);
rpcSendResponse(&rpcRsp); return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey);
} }
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
#include "ttime.h" #include "ttime.h"
#include "tbalance.h" #include "tbalance.h"
#include "tglobal.h" #include "tglobal.h"
#include "dnode.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "dnode.h"
#include "mnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeDb.h" #include "mnodeDb.h"
...@@ -32,21 +33,22 @@ ...@@ -32,21 +33,22 @@
#include "mnodeMnode.h" #include "mnodeMnode.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShell.h" #include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodePeer.h"
static void *tsVgroupSdb = NULL; static void *tsVgroupSdb = NULL;
static int32_t tsVgUpdateSize = 0; static int32_t tsVgUpdateSize = 0;
static int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg);
static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg);
static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) ; static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ;
static void mgmtSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle); static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle);
static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) { static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
if (pVgroup->idPool) { if (pVgroup->idPool) {
taosIdPoolCleanUp(pVgroup->idPool); taosIdPoolCleanUp(pVgroup->idPool);
...@@ -60,11 +62,11 @@ static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) { ...@@ -60,11 +62,11 @@ static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) { static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
// refer to db // refer to db
SDbObj *pDb = mgmtGetDb(pVgroup->dbName); SDbObj *pDb = mnodeGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
return TSDB_CODE_INVALID_DB; return TSDB_CODE_INVALID_DB;
} }
...@@ -88,40 +90,40 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) { ...@@ -88,40 +90,40 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) {
} }
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pVgroup->vnodeGid[i].dnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
pVgroup->vnodeGid[i].pDnode = pDnode; pVgroup->vnodeGid[i].pDnode = pDnode;
atomic_add_fetch_32(&pDnode->openVnodes, 1); atomic_add_fetch_32(&pDnode->openVnodes, 1);
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
} }
mgmtAddVgroupIntoDb(pVgroup); mnodeAddVgroupIntoDb(pVgroup);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtVgroupActionDelete(SSdbOper *pOper) { static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
if (pVgroup->pDb != NULL) { if (pVgroup->pDb != NULL) {
mgmtRemoveVgroupFromDb(pVgroup); mnodeRemoveVgroupFromDb(pVgroup);
} }
mgmtDecDbRef(pVgroup->pDb); mnodeDecDbRef(pVgroup->pDb);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pVgroup->vnodeGid[i].dnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
atomic_sub_fetch_32(&pDnode->openVnodes, 1); atomic_sub_fetch_32(&pDnode->openVnodes, 1);
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void mgmtVgroupUpdateIdPool(SVgObj *pVgroup) { static void mnodeVgroupUpdateIdPool(SVgObj *pVgroup) {
int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool); int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool);
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
if (pDb != NULL) { if (pDb != NULL) {
...@@ -135,9 +137,9 @@ static void mgmtVgroupUpdateIdPool(SVgObj *pVgroup) { ...@@ -135,9 +137,9 @@ static void mgmtVgroupUpdateIdPool(SVgObj *pVgroup) {
} }
} }
static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) {
SVgObj *pNew = pOper->pObj; SVgObj *pNew = pOper->pObj;
SVgObj *pVgroup = mgmtGetVgroup(pNew->vgId); SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId);
if (pVgroup != pNew) { if (pVgroup != pNew) {
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
...@@ -151,24 +153,24 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { ...@@ -151,24 +153,24 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
free(pNew); free(pNew);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pVgroup->vnodeGid[i].dnodeId);
pVgroup->vnodeGid[i].pDnode = pDnode; pVgroup->vnodeGid[i].pDnode = pDnode;
if (pDnode != NULL) { if (pDnode != NULL) {
atomic_add_fetch_32(&pDnode->openVnodes, 1); atomic_add_fetch_32(&pDnode->openVnodes, 1);
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
} }
} }
mgmtVgroupUpdateIdPool(pVgroup); mnodeVgroupUpdateIdPool(pVgroup);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
mTrace("vgId:%d, is updated, numOfVnode:%d", pVgroup->vgId, pVgroup->numOfVnodes); mTrace("vgId:%d, is updated, numOfVnode:%d", pVgroup->vgId, pVgroup->numOfVnodes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) { static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
memcpy(pOper->rowData, pVgroup, tsVgUpdateSize); memcpy(pOper->rowData, pVgroup, tsVgUpdateSize);
SVgObj *pTmpVgroup = pOper->rowData; SVgObj *pTmpVgroup = pOper->rowData;
...@@ -181,7 +183,7 @@ static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) { ...@@ -181,7 +183,7 @@ static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtVgroupActionDecode(SSdbOper *pOper) { static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) {
SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj));
if (pVgroup == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pVgroup == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
...@@ -190,11 +192,11 @@ static int32_t mgmtVgroupActionDecode(SSdbOper *pOper) { ...@@ -190,11 +192,11 @@ static int32_t mgmtVgroupActionDecode(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtVgroupActionRestored() { static int32_t mnodeVgroupActionRestored() {
return 0; return 0;
} }
int32_t mgmtInitVgroups() { int32_t mnodeInitVgroups() {
SVgObj tObj; SVgObj tObj;
tsVgUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; tsVgUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
...@@ -205,13 +207,13 @@ int32_t mgmtInitVgroups() { ...@@ -205,13 +207,13 @@ int32_t mgmtInitVgroups() {
.maxRowSize = tsVgUpdateSize, .maxRowSize = tsVgUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_AUTO, .keyType = SDB_KEY_AUTO,
.insertFp = mgmtVgroupActionInsert, .insertFp = mnodeVgroupActionInsert,
.deleteFp = mgmtVgroupActionDelete, .deleteFp = mnodeVgroupActionDelete,
.updateFp = mgmtVgroupActionUpdate, .updateFp = mnodeVgroupActionUpdate,
.encodeFp = mgmtVgroupActionEncode, .encodeFp = mnodeVgroupActionEncode,
.decodeFp = mgmtVgroupActionDecode, .decodeFp = mnodeVgroupActionDecode,
.destroyFp = mgmtVgroupActionDestroy, .destroyFp = mnodeVgroupActionDestroy,
.restoredFp = mgmtVgroupActionRestored, .restoredFp = mnodeVgroupActionRestored,
}; };
tsVgroupSdb = sdbOpenTable(&tableDesc); tsVgroupSdb = sdbOpenTable(&tableDesc);
...@@ -220,30 +222,30 @@ int32_t mgmtInitVgroups() { ...@@ -220,30 +222,30 @@ int32_t mgmtInitVgroups() {
return -1; return -1;
} }
mnodeAddShowMetaHandle(TSDB_MNODE_TABLE_VGROUP, mgmtGetVgroupMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta);
mnodeAddShowRetrieveHandle(TSDB_MNODE_TABLE_VGROUP, mgmtRetrieveVgroups); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mgmtProcessCreateVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp);
dnodeAddClientRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mgmtProcessDropVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mnodeProcessDropVnodeRsp);
dnodeAddServerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mgmtProcessVnodeCfgMsg); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mnodeProcessVnodeCfgMsg);
mTrace("table:vgroups is created"); mTrace("table:vgroups is created");
return 0; return 0;
} }
void mgmtIncVgroupRef(SVgObj *pVgroup) { void mnodeIncVgroupRef(SVgObj *pVgroup) {
return sdbIncRef(tsVgroupSdb, pVgroup); return sdbIncRef(tsVgroupSdb, pVgroup);
} }
void mgmtDecVgroupRef(SVgObj *pVgroup) { void mnodeDecVgroupRef(SVgObj *pVgroup) {
return sdbDecRef(tsVgroupSdb, pVgroup); return sdbDecRef(tsVgroupSdb, pVgroup);
} }
SVgObj *mgmtGetVgroup(int32_t vgId) { SVgObj *mnodeGetVgroup(int32_t vgId) {
return (SVgObj *)sdbGetRow(tsVgroupSdb, &vgId); return (SVgObj *)sdbGetRow(tsVgroupSdb, &vgId);
} }
void mgmtUpdateVgroup(SVgObj *pVgroup) { void mnodeUpdateVgroup(SVgObj *pVgroup) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsVgroupSdb, .table = tsVgroupSdb,
...@@ -251,10 +253,10 @@ void mgmtUpdateVgroup(SVgObj *pVgroup) { ...@@ -251,10 +253,10 @@ void mgmtUpdateVgroup(SVgObj *pVgroup) {
}; };
sdbUpdateRow(&oper); sdbUpdateRow(&oper);
mgmtSendCreateVgroupMsg(pVgroup, NULL); mnodeSendCreateVgroupMsg(pVgroup, NULL);
} }
void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload) { void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload) {
bool dnodeExist = false; bool dnodeExist = false;
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
...@@ -269,9 +271,9 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo ...@@ -269,9 +271,9 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
} }
if (!dnodeExist) { if (!dnodeExist) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
mError("vgId:%d, dnode:%d not exist in mnode, drop it", pVload->vgId, pDnode->dnodeId); mError("vgId:%d, dnode:%d not exist in mnode, drop it", pVload->vgId, pDnode->dnodeId);
mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL); mnodeSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
return; return;
} }
...@@ -285,19 +287,19 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo ...@@ -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", 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, pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion,
pVgroup->numOfVnodes); pVgroup->numOfVnodes);
mgmtSendCreateVgroupMsg(pVgroup, NULL); mnodeSendCreateVgroupMsg(pVgroup, NULL);
} }
} }
SVgObj *mgmtGetAvailableVgroup(SDbObj *pDb) { SVgObj *mnodeGetAvailableVgroup(SDbObj *pDb) {
return pDb->pHead; return pDb->pHead;
} }
void *mgmtGetNextVgroup(void *pIter, SVgObj **pVgroup) { void *mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup) {
return sdbFetchRow(tsVgroupSdb, pIter, (void **)pVgroup); return sdbFetchRow(tsVgroupSdb, pIter, (void **)pVgroup);
} }
void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj)); SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj));
strcpy(pVgroup->dbName, pDb->name); strcpy(pVgroup->dbName, pDb->name);
pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->numOfVnodes = pDb->cfg.replications;
...@@ -305,9 +307,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { ...@@ -305,9 +307,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if (balanceAllocVnodes(pVgroup) != 0) { if (balanceAllocVnodes(pVgroup) != 0) {
mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes);
free(pVgroup); free(pVgroup);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_NO_ENOUGH_DNODES); mnodeCleanupMsg(pMsg);
mgmtFreeQueuedMsg(pMsg); return TSDB_CODE_NO_ENOUGH_DNODES;
return;
} }
SSdbOper oper = { SSdbOper oper = {
...@@ -321,9 +322,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { ...@@ -321,9 +322,8 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pVgroup); tfree(pVgroup);
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SDB_ERROR); mnodeCleanupMsg(pMsg);
mgmtFreeQueuedMsg(pMsg); return TSDB_CODE_SDB_ERROR;
return;
} }
mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); 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) { ...@@ -333,15 +333,17 @@ void mgmtCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
pMsg->ahandle = pVgroup; pMsg->ahandle = pVgroup;
pMsg->expected = pVgroup->numOfVnodes; pMsg->expected = pVgroup->numOfVnodes;
mgmtSendCreateVgroupMsg(pVgroup, pMsg); mnodeSendCreateVgroupMsg(pVgroup, pMsg);
return TSDB_CODE_ACTION_IN_PROGRESS;
} }
void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) { void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
if (ahandle != NULL) { if (ahandle != NULL) {
mgmtSendDropVgroupMsg(pVgroup, ahandle); mnodeSendDropVgroupMsg(pVgroup, ahandle);
} else { } else {
mTrace("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes); mTrace("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes);
mgmtSendDropVgroupMsg(pVgroup, NULL); mnodeSendDropVgroupMsg(pVgroup, NULL);
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsVgroupSdb, .table = tsVgroupSdb,
...@@ -351,12 +353,12 @@ void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) { ...@@ -351,12 +353,12 @@ void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) {
} }
} }
void mgmtCleanUpVgroups() { void mnodeCleanupVgroups() {
sdbCloseTable(tsVgroupSdb); sdbCloseTable(tsVgroupSdb);
} }
int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) { if (pDb == NULL) {
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_DB_NOT_SELECTED;
} }
...@@ -380,15 +382,15 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -380,15 +382,15 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
STableObj *pTable = NULL; STableObj *pTable = NULL;
if (pShow->payloadLen > 0 ) { if (pShow->payloadLen > 0 ) {
pTable = mgmtGetTable(pShow->payload); pTable = mnodeGetTable(pShow->payload);
if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) {
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_INVALID_TABLE_ID;
} }
mgmtDecTableRef(pTable); mnodeDecTableRef(pTable);
pVgroup = mgmtGetVgroup(((SChildTableObj*)pTable)->vgId); pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId);
if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID;
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica;
} else { } else {
SVgObj *pVgroup = pDb->pHead; SVgObj *pVgroup = pDb->pHead;
...@@ -434,19 +436,19 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -434,19 +436,19 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow->pIter = pVgroup; pShow->pIter = pVgroup;
} }
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return 0; return 0;
} }
int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
int32_t maxReplica = 0; int32_t maxReplica = 0;
int32_t cols = 0; int32_t cols = 0;
char * pWrite; char * pWrite;
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return 0; if (pDb == NULL) return 0;
pVgroup = pDb->pHead; pVgroup = pDb->pHead;
...@@ -483,7 +485,7 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -483,7 +485,7 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char *role = mgmtGetMnodeRoleStr(pVgroup->vnodeGid[i].role); char *role = mnodeGetMnodeRoleStr(pVgroup->vnodeGid[i].role);
STR_TO_VARSTR(pWrite, role); STR_TO_VARSTR(pWrite, role);
cols++; cols++;
} else { } else {
...@@ -502,12 +504,12 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -502,12 +504,12 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
mgmtDecDbRef(pDb); mnodeDecDbRef(pDb);
return numOfRows; return numOfRows;
} }
void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] == NULL) { if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] == NULL) {
pVgroup->tableList[pTable->sid - 1] = pTable; pVgroup->tableList[pTable->sid - 1] = pTable;
taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid); taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid);
...@@ -515,21 +517,21 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { ...@@ -515,21 +517,21 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
} }
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) { if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) {
mgmtMoveVgroupToTail(pVgroup); mnodeMoveVgroupToTail(pVgroup);
} }
mgmtIncVgroupRef(pVgroup); mnodeIncVgroupRef(pVgroup);
} }
void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] != NULL) { if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] != NULL) {
pVgroup->tableList[pTable->sid - 1] = NULL; pVgroup->tableList[pTable->sid - 1] = NULL;
taosFreeId(pVgroup->idPool, pTable->sid); taosFreeId(pVgroup->idPool, pTable->sid);
pVgroup->numOfTables--; pVgroup->numOfTables--;
} }
mgmtMoveVgroupToHead(pVgroup); mnodeMoveVgroupToHead(pVgroup);
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
...@@ -571,7 +573,7 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { ...@@ -571,7 +573,7 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
return pVnode; return pVnode;
} }
SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) { SRpcIpSet mnodeGetIpSetFromVgroup(SVgObj *pVgroup) {
SRpcIpSet ipSet = { SRpcIpSet ipSet = {
.numOfIps = pVgroup->numOfVnodes, .numOfIps = pVgroup->numOfVnodes,
.inUse = 0, .inUse = 0,
...@@ -583,7 +585,7 @@ SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) { ...@@ -583,7 +585,7 @@ SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) {
return ipSet; return ipSet;
} }
SRpcIpSet mgmtGetIpSetFromIp(char *ep) { SRpcIpSet mnodeGetIpSetFromIp(char *ep) {
SRpcIpSet ipSet; SRpcIpSet ipSet;
ipSet.numOfIps = 1; ipSet.numOfIps = 1;
...@@ -593,7 +595,7 @@ SRpcIpSet mgmtGetIpSetFromIp(char *ep) { ...@@ -593,7 +595,7 @@ SRpcIpSet mgmtGetIpSetFromIp(char *ep) {
return ipSet; return ipSet;
} }
void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) { void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
mTrace("vgId:%d, send create vnode:%d msg, ahandle:%p", pVgroup->vgId, pVgroup->vgId, ahandle); mTrace("vgId:%d, send create vnode:%d msg, ahandle:%p", pVgroup->vgId, pVgroup->vgId, ahandle);
SMDCreateVnodeMsg *pCreate = mgmtBuildCreateVnodeMsg(pVgroup); SMDCreateVnodeMsg *pCreate = mgmtBuildCreateVnodeMsg(pVgroup);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
...@@ -606,34 +608,33 @@ void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) { ...@@ -606,34 +608,33 @@ void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
dnodeSendMsgToDnode(ipSet, &rpcMsg); dnodeSendMsgToDnode(ipSet, &rpcMsg);
} }
void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) { void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) {
mTrace("vgId:%d, send create all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle); mTrace("vgId:%d, send create all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp);
mgmtSendCreateVnodeMsg(pVgroup, &ipSet, ahandle); mnodeSendCreateVnodeMsg(pVgroup, &ipSet, ahandle);
} }
} }
static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
if (rpcMsg->handle == NULL) return; if (rpcMsg->handle == NULL) return;
SMnodeMsg *queueMsg = rpcMsg->handle; SMnodeMsg *mnodeMsg = rpcMsg->handle;
queueMsg->received++; mnodeMsg->received++;
if (rpcMsg->code == TSDB_CODE_SUCCESS) { if (rpcMsg->code == TSDB_CODE_SUCCESS) {
queueMsg->code = rpcMsg->code; mnodeMsg->code = rpcMsg->code;
queueMsg->successed++; mnodeMsg->successed++;
} }
SVgObj *pVgroup = queueMsg->ahandle; SVgObj *pVgroup = mnodeMsg->ahandle;
mTrace("vgId:%d, create vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p", 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, queueMsg->expected, pVgroup->vgId, tstrerror(rpcMsg->code), mnodeMsg->received, mnodeMsg->successed, mnodeMsg->expected,
queueMsg->thandle, rpcMsg->handle); mnodeMsg->thandle, rpcMsg->handle);
if (queueMsg->received != queueMsg->expected) return; if (mnodeMsg->received != mnodeMsg->expected) return;
if (queueMsg->received == queueMsg->successed) { if (mnodeMsg->received == mnodeMsg->successed) {
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(queueMsg); dnodeReprocessMnodeWriteMsg(mnodeMsg);
mgmtAddToShellQueue(newMsg);
} else { } else {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -644,11 +645,9 @@ static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { ...@@ -644,11 +645,9 @@ static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
if (code != 0) { if (code != 0) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
} }
mgmtSendSimpleResp(queueMsg->thandle, rpcMsg->code);
}
mgmtFreeQueuedMsg(queueMsg); dnodeSendRpcMnodeWriteRsp(mnodeMsg, code);
}
} }
static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) { static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) {
...@@ -659,7 +658,7 @@ static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) { ...@@ -659,7 +658,7 @@ static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) {
return pDrop; return pDrop;
} }
void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) { void mnodeSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) {
SMDDropVnodeMsg *pDrop = mgmtBuildDropVnodeMsg(vgId); SMDDropVnodeMsg *pDrop = mgmtBuildDropVnodeMsg(vgId);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.handle = ahandle, .handle = ahandle,
...@@ -671,32 +670,32 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) { ...@@ -671,32 +670,32 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) {
dnodeSendMsgToDnode(ipSet, &rpcMsg); dnodeSendMsgToDnode(ipSet, &rpcMsg);
} }
static void mgmtSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle) { static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle) {
mTrace("vgId:%d, send drop all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle); mTrace("vgId:%d, send drop all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp);
mTrace("vgId:%d, send drop vnode msg to dnode:%d, ahandle:%p", pVgroup->vgId, pVgroup->vnodeGid[i].dnodeId, ahandle); mTrace("vgId:%d, send drop vnode msg to dnode:%d, ahandle:%p", pVgroup->vgId, pVgroup->vnodeGid[i].dnodeId, ahandle);
mgmtSendDropVnodeMsg(pVgroup->vgId, &ipSet, ahandle); mnodeSendDropVnodeMsg(pVgroup->vgId, &ipSet, ahandle);
} }
} }
static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) { static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
mTrace("drop vnode rsp is received, handle:%p", rpcMsg->handle); mTrace("drop vnode rsp is received, handle:%p", rpcMsg->handle);
if (rpcMsg->handle == NULL) return; if (rpcMsg->handle == NULL) return;
SMnodeMsg *queueMsg = rpcMsg->handle; SMnodeMsg *mnodeMsg = rpcMsg->handle;
queueMsg->received++; mnodeMsg->received++;
if (rpcMsg->code == TSDB_CODE_SUCCESS) { if (rpcMsg->code == TSDB_CODE_SUCCESS) {
queueMsg->code = rpcMsg->code; mnodeMsg->code = rpcMsg->code;
queueMsg->successed++; mnodeMsg->successed++;
} }
SVgObj *pVgroup = queueMsg->ahandle; SVgObj *pVgroup = mnodeMsg->ahandle;
mTrace("vgId:%d, drop vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p", 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, queueMsg->expected, pVgroup->vgId, tstrerror(rpcMsg->code), mnodeMsg->received, mnodeMsg->successed, mnodeMsg->expected,
queueMsg->thandle, rpcMsg->handle); mnodeMsg->thandle, rpcMsg->handle);
if (queueMsg->received != queueMsg->expected) return; if (mnodeMsg->received != mnodeMsg->expected) return;
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -708,41 +707,35 @@ static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) { ...@@ -708,41 +707,35 @@ static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
} }
SMnodeMsg *newMsg = mgmtCloneQueuedMsg(queueMsg); dnodeReprocessMnodeWriteMsg(mnodeMsg);
mgmtAddToShellQueue(newMsg);
queueMsg->pCont = NULL;
mgmtFreeQueuedMsg(queueMsg);
} }
static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) { static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) {
SDMConfigVnodeMsg *pCfg = (SDMConfigVnodeMsg *) rpcMsg->pCont; SDMConfigVnodeMsg *pCfg = (SDMConfigVnodeMsg *) pMsg->pCont;
pCfg->dnodeId = htonl(pCfg->dnodeId); pCfg->dnodeId = htonl(pCfg->dnodeId);
pCfg->vgId = htonl(pCfg->vgId); pCfg->vgId = htonl(pCfg->vgId);
SDnodeObj *pDnode = mgmtGetDnode(pCfg->dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId); mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE); return TSDB_CODE_NOT_ACTIVE_VNODE;
return;
} }
mgmtDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
SVgObj *pVgroup = mgmtGetVgroup(pCfg->vgId); SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId); mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE); return TSDB_CODE_NOT_ACTIVE_VNODE;
return;
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SUCCESS); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
mnodeSendCreateVnodeMsg(pVgroup, &ipSet, NULL);
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp); return TSDB_CODE_SUCCESS;
mgmtSendCreateVnodeMsg(pVgroup, &ipSet, NULL);
} }
void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) { void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
void * pIter = NULL; void * pIter = NULL;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
int32_t numOfVgroups = 0; int32_t numOfVgroups = 0;
...@@ -750,11 +743,11 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) { ...@@ -750,11 +743,11 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
mPrint("dnode:%d, all vgroups will be dropped from sdb", pDropDnode->dnodeId); mPrint("dnode:%d, all vgroups will be dropped from sdb", pDropDnode->dnodeId);
while (1) { while (1) {
pIter = mgmtGetNextVgroup(pIter, &pVgroup); pIter = mnodeGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) { if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) {
mgmtDropAllChildTablesInVgroups(pVgroup); mnodeDropAllChildTablesInVgroups(pVgroup);
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_LOCAL, .type = SDB_OPER_LOCAL,
.table = tsVgroupSdb, .table = tsVgroupSdb,
...@@ -763,7 +756,7 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) { ...@@ -763,7 +756,7 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
numOfVgroups++; numOfVgroups++;
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -771,21 +764,21 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) { ...@@ -771,21 +764,21 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
mPrint("dnode:%d, all vgroups is dropped from sdb", pDropDnode->dnodeId); mPrint("dnode:%d, all vgroups is dropped from sdb", pDropDnode->dnodeId);
} }
void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb) { void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb) {
void * pIter = NULL; void * pIter = NULL;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
mPrint("db:%s, all vgroups will be update in sdb", pAlterDb->name); mPrint("db:%s, all vgroups will be update in sdb", pAlterDb->name);
while (1) { while (1) {
pIter = mgmtGetNextVgroup(pIter, &pVgroup); pIter = mnodeGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
if (pVgroup->pDb == pAlterDb) { if (pVgroup->pDb == pAlterDb) {
mgmtVgroupUpdateIdPool(pVgroup); mnodeVgroupUpdateIdPool(pVgroup);
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
...@@ -793,14 +786,14 @@ void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb) { ...@@ -793,14 +786,14 @@ void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb) {
mPrint("db:%s, all vgroups is updated in sdb", pAlterDb->name); mPrint("db:%s, all vgroups is updated in sdb", pAlterDb->name);
} }
void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) { void mnodeDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfVgroups = 0; int32_t numOfVgroups = 0;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
mPrint("db:%s, all vgroups will be dropped from sdb", pDropDb->name); mPrint("db:%s, all vgroups will be dropped from sdb", pDropDb->name);
while (1) { while (1) {
pIter = mgmtGetNextVgroup(pIter, &pVgroup); pIter = mnodeGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
if (pVgroup->pDb == pDropDb) { if (pVgroup->pDb == pDropDb) {
...@@ -813,11 +806,11 @@ void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) { ...@@ -813,11 +806,11 @@ void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) {
numOfVgroups++; numOfVgroups++;
if (sendMsg) { if (sendMsg) {
mgmtSendDropVgroupMsg(pVgroup, NULL); mnodeSendDropVgroupMsg(pVgroup, NULL);
} }
} }
mgmtDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
} }
sdbFreeIter(pIter); sdbFreeIter(pIter);
......
...@@ -19,12 +19,11 @@ ...@@ -19,12 +19,11 @@
#include "tsched.h" #include "tsched.h"
#include "tbalance.h" #include "tbalance.h"
#include "tgrant.h" #include "tgrant.h"
#include "ttimer.h"
#include "tglobal.h" #include "tglobal.h"
#include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
#include "mnodeInt.h" #include "mnodeInt.h"
#include "mnodeServer.h"
#include "mnodeAcct.h" #include "mnodeAcct.h"
#include "mnodeDnode.h" #include "mnodeDnode.h"
#include "mnodeMnode.h" #include "mnodeMnode.h"
...@@ -33,29 +32,28 @@ ...@@ -33,29 +32,28 @@
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeUser.h" #include "mnodeUser.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeShell.h" #include "mnodeShow.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 *pMsg)) { void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) {
tsMnodeProcessWriteMsgFp[msgType] = fp; tsMnodeProcessWriteMsgFp[msgType] = fp;
} }
int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
SRpcMsg *rpcMsg = &pMsg->rpcMsg; if (pMsg->pCont == NULL) {
if (rpcMsg->pCont == NULL) { mError("msg:%s content is null", taosMsg[pMsg->msgType]);
mError("%p, msg:%s content is null", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet)); SRpcIpSet *ipSet = rpcMallocCont(sizeof(SRpcIpSet));
mgmtGetMnodeIpSetForShell(ipSet); mnodeGetMnodeIpSetForShell(ipSet);
rpcRsp->rsp = ipSet; rpcRsp->rsp = ipSet;
rpcRsp->len = sizeof(SRpcIpSet); rpcRsp->len = sizeof(SRpcIpSet);
mTrace("%p, msg:%s will be redireced, inUse:%d", rpcMsg->ahandle, taosMsg[rpcMsg->msgType], ipSet->inUse); mTrace("msg:%s will be redireced, inUse:%d", taosMsg[pMsg->msgType], ipSet->inUse);
for (int32_t i = 0; i < ipSet->numOfIps; ++i) { for (int32_t i = 0; i < ipSet->numOfIps; ++i) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[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) { ...@@ -63,34 +61,20 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
return TSDB_CODE_REDIRECT; return TSDB_CODE_REDIRECT;
} }
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (tsMnodeProcessWriteMsgFp[pMsg->msgType] == NULL) {
mError("%p, msg:%s not processed, grant time expired", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]); mError("msg:%s not processed, no handle exist", taosMsg[pMsg->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]);
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MSG_NOT_PROCESSED;
} }
if (!mnodeInitMsg(pMsg)) { if (!mnodeInitMsg(pMsg)) {
mError("%p, msg:%s not processed, reason:%s", rpcMsg->ahandle, taosMsg[rpcMsg->msgType], tstrerror(terrno)); mError("msg:%s not processed, reason:%s", taosMsg[pMsg->msgType], tstrerror(terrno));
return terrno; return terrno;
} }
if (!pMsg->pUser->writeAuth) { if (!pMsg->pUser->writeAuth) {
mError("%p, msg:%s not processed, no rights", rpcMsg->ahandle, taosMsg[rpcMsg->msgType]); mError("%p, msg:%s not processed, no rights", taosMsg[pMsg->msgType]);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_NO_RIGHTS;
} }
return (*tsMnodeProcessWriteMsgFp[rpcMsg->msgType])(pMsg); return (*tsMnodeProcessWriteMsgFp[pMsg->msgType])(pMsg);
} }
static void mgmtDoDealyedAddToShellQueue(void *param, void *tmrId) {
mgmtAddToShellQueue(param);
}
void mgmtDealyedAddToShellQueue(SMnodeMsg *queuedMsg) {
void *unUsed = NULL;
taosTmrReset(mgmtDoDealyedAddToShellQueue, 300, queuedMsg, tsMgmtTmr, &unUsed);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册