From 2905864579924bc437c2962c3350a9a410ee24ea Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 19 Feb 2020 23:48:17 +0800 Subject: [PATCH] fix compile errors --- src/CMakeLists.txt | 12 +- src/client/src/tscServer.c | 35 +- src/client/src/tscSql.c | 5 +- src/client/src/tscSystem.c | 6 +- src/dnode/CMakeLists.txt | 5 +- src/dnode/src/dnodeShell.c | 20 +- src/dnode/src/dnodeVnodeMgmt.c | 24 +- src/inc/mnode.h | 8 +- src/kit/shell/CMakeLists.txt | 1 + src/kit/taosdemo/CMakeLists.txt | 1 + src/kit/taosdump/CMakeLists.txt | 1 + src/mnode/CMakeLists.txt | 2 +- src/mnode/inc/mgmtDb.h | 2 - src/mnode/inc/mgmtDnodeInt.h | 4 +- src/mnode/inc/mgmtNormalTable.h | 2 +- src/mnode/inc/mgmtTable.h | 1 + src/mnode/inc/mgmtUtil.h | 3 +- src/mnode/src/mgmtAcct.c | 3 +- src/mnode/src/mgmtChildTable.c | 166 +- src/mnode/src/mgmtDb.c | 30 +- src/mnode/src/mgmtDnodeInt.c | 678 +++---- src/mnode/src/mgmtNormalTable.c | 23 +- src/mnode/src/mgmtShell.c | 2407 ++++++++++++----------- src/mnode/src/mgmtStreamTable.c | 30 +- src/mnode/src/mgmtSuperTable.c | 108 +- src/mnode/src/mgmtTable.c | 127 +- src/mnode/src/mgmtUtil.c | 52 +- src/mnode/src/mgmtVgroup.c | 24 +- src/plugins/http/CMakeLists.txt | 1 + src/plugins/http/src/gcHandle.c | 1 + src/plugins/http/src/httpHandle.c | 1 + src/plugins/http/src/httpJson.c | 4 +- src/plugins/http/src/httpResp.c | 4 +- src/plugins/http/src/httpSession.c | 1 + src/plugins/http/src/httpSystem.c | 1 + src/plugins/http/src/httpUtil.c | 1 + src/plugins/http/src/restHandle.c | 4 +- src/plugins/http/src/restJson.c | 2 +- src/plugins/http/src/tgHandle.c | 1 + src/plugins/http/src/tgJson.c | 1 + src/plugins/monitor/CMakeLists.txt | 1 + src/plugins/monitor/src/monitorSystem.c | 1 + src/sdb/src/sdbEngine.c | 4 + 43 files changed, 1801 insertions(+), 2007 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d4951b891..a85df15776 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,11 +4,11 @@ PROJECT(TDengine) ADD_SUBDIRECTORY(os) ADD_SUBDIRECTORY(util) ADD_SUBDIRECTORY(rpc) -#ADD_SUBDIRECTORY(client) -#ADD_SUBDIRECTORY(kit) -#ADD_SUBDIRECTORY(plugins) -#ADD_SUBDIRECTORY(sdb) -#ADD_SUBDIRECTORY(mnode) -#ADD_SUBDIRECTORY(dnode) +ADD_SUBDIRECTORY(client) +ADD_SUBDIRECTORY(kit) +ADD_SUBDIRECTORY(plugins) +ADD_SUBDIRECTORY(sdb) +ADD_SUBDIRECTORY(mnode) +ADD_SUBDIRECTORY(dnode) #ADD_SUBDIRECTORY(vnode) #ADD_SUBDIRECTORY(connector/jdbc) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index fe385c3077..a295f6fc97 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -57,7 +57,7 @@ void tscPrintMgmtIp() { tscError("invalid mgmt IP list:%d", tscMgmtIpList.numOfIps); } else { for (int i = 0; i < tscMgmtIpList.numOfIps; ++i) { - tscTrace("mgmt index:%d ip:%s", i, tscMgmtIpList.ipStr[i]); + tscTrace("mgmt index:%d ip:%d", i, tscMgmtIpList.ip[i]); } } } @@ -66,7 +66,7 @@ void tscSetMgmtIpListFromCluster(SIpList *pIpList) { tscMgmtIpList.numOfIps = pIpList->numOfIps; if (memcmp(tscMgmtIpList.ip, pIpList->ip, pIpList->numOfIps * 4) != 0) { for (int i = 0; i < pIpList->numOfIps; ++i) { - tinet_ntoa(tscMgmtIpList.ipStr[i], pIpList->ip[i]); + //tinet_ntoa(tscMgmtIpList.ipStr[i], pIpList->ip[i]); tscMgmtIpList.ip[i] = pIpList->ip[i]; } tscTrace("cluster mgmt IP list:"); @@ -77,9 +77,7 @@ void tscSetMgmtIpListFromCluster(SIpList *pIpList) { void tscSetMgmtIpListFromEdge() { if (tscMgmtIpList.numOfIps != 2) { tscMgmtIpList.numOfIps = 2; - strcpy(tscMgmtIpList.ipStr[0], tsMasterIp); tscMgmtIpList.ip[0] = inet_addr(tsMasterIp); - strcpy(tscMgmtIpList.ipStr[1], tsMasterIp); tscMgmtIpList.ip[1] = inet_addr(tsMasterIp); tscTrace("edge mgmt IP list:"); tscPrintMgmtIp(); @@ -351,17 +349,14 @@ int tscSendMsgToServer(SSqlObj *pSql) { uint64_t signature = (uint64_t)pSql->signature; //if (tscUpdateVnodeMsg[pSql->cmd.command]) (*tscUpdateVnodeMsg[pSql->cmd.command])(pSql, pStart); - int ret; - if (pSql->cmd.command < TSDB_SQL_MGMT) - ret = rpcSendRequest(pTscMgmtConn, pSql->cmd.msgType, pStart, pSql->cmd.payloadLen, pSql); - else - ret = rpcSendRequest(pVnodeConn, pSql->cmd.msgType, pStart, pSql->cmd.payloadLen, pSql); - - if (ret >= 0) { - code = 0; + if (pSql->cmd.command < TSDB_SQL_MGMT) { + rpcSendRequest(pTscMgmtConn, tscMgmtIpList, pSql->cmd.msgType, pStart, pSql->cmd.payloadLen, pSql); + } else { + SRpcIpSet rpcSet = tscMgmtIpList; + rpcSendRequest(pVnodeConn, rpcSet, pSql->cmd.msgType, pStart, pSql->cmd.payloadLen, pSql); } - tscTrace("%p send msg ret:%d code:%d sig:%p", pSql, ret, code, signature); + tscTrace("%p send msg code:%d sig:%p", pSql, code, signature); } } @@ -1327,7 +1322,7 @@ void tscKillMetricQuery(SSqlObj *pSql) { * sub-queries not correctly released and master sql object of metric query reaches an abnormal state. */ pSql->pSubs[i]->res.code = TSDB_CODE_QUERY_CANCELLED; - taosStopRpcConn(pSql->pSubs[i]->thandle); + //taosStopRpcConn(pSql->pSubs[i]->thandle); } pSql->numOfSubs = 0; @@ -1491,9 +1486,9 @@ void tscUpdateVnodeInSubmitMsg(SSqlObj *pSql, char *buf) { pMsg = buf + tsRpcHeadSize; pShellMsg = (SShellSubmitMsg *)pMsg; - pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pSql->index].vnode); - tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pSql->index].ip), - htons(pShellMsg->vnode)); + //pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pSql->index].vnode); + //tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pSql->index].ip), + // htons(pShellMsg->vnode)); } int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { @@ -1511,13 +1506,13 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pShellMsg = (SShellSubmitMsg *)pMsg; pShellMsg->import = htons(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT) ? 0 : 1); - pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pMeterMeta->index].vnode); + //pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pMeterMeta->index].vnode); pShellMsg->numOfSid = htonl(pSql->cmd.numOfTablesInSubmit); // number of meters to be inserted // pSql->cmd.payloadLen is set during parse sql routine, so we do not use it here pSql->cmd.msgType = TSDB_MSG_TYPE_DNODE_SUBMIT; - tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pMeterMeta->index].ip), - htons(pShellMsg->vnode)); + //tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pMeterMeta->index].ip), + // htons(pShellMsg->vnode)); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index ddccbccb23..0ea4c64204 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -65,11 +65,8 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const if (ip && ip[0]) { tscMgmtIpList.numOfIps = 3; - strcpy(tscMgmtIpList.ipStr[0], ip); tscMgmtIpList.ip[0] = inet_addr(ip); - strcpy(tscMgmtIpList.ipStr[1], tsMasterIp); tscMgmtIpList.ip[1] = inet_addr(tsMasterIp); - strcpy(tscMgmtIpList.ipStr[2], tsSecondIp); tscMgmtIpList.ip[2] = inet_addr(tsSecondIp); tscMgmtIpList.index = 0; tscMgmtIpList.port = tsMgmtShellPort; @@ -907,7 +904,7 @@ void taos_stop_query(TAOS_RES *res) { return; } - taosStopRpcConn(pSql->thandle); + //taosStopRpcConn(pSql->thandle); tscTrace("%p query is cancelled", res); } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index b9c0ae2018..f411698bb7 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -99,12 +99,10 @@ void taos_init_imp() { tscMgmtIpList.index = 0; tscMgmtIpList.port = tsMgmtShellPort; tscMgmtIpList.numOfIps = 1; - strcpy(tscMgmtIpList.ipStr[0], tsMasterIp); tscMgmtIpList.ip[0] = inet_addr(tsMasterIp); if (tsSecondIp[0]) { tscMgmtIpList.numOfIps = 2; - strcpy(tscMgmtIpList.ipStr[1], tsSecondIp); tscMgmtIpList.ip[1] = inet_addr(tsSecondIp); } @@ -131,7 +129,7 @@ void taos_init_imp() { rpcInit.localPort = 0; rpcInit.label = "TSC-vnode"; rpcInit.numOfThreads = tscNumOfThreads; - rpcInit.fp = tscProcessMsgFromServer; + rpcInit.afp = tscProcessMsgFromServer; rpcInit.sessions = tsMaxVnodeConnections; rpcInit.connType = TAOS_CONN_SOCKET_TYPE_C(); pVnodeConn = rpcOpen(&rpcInit); @@ -145,7 +143,7 @@ void taos_init_imp() { rpcInit.localPort = 0; rpcInit.label = "TSC-mgmt"; rpcInit.numOfThreads = 1; - rpcInit.fp = tscProcessMsgFromServer; + rpcInit.afp = tscProcessMsgFromServer; rpcInit.sessions = tsMaxMgmtConnections; rpcInit.connType = TAOS_CONN_SOCKET_TYPE_C(); pTscMgmtConn = rpcOpen(&rpcInit); diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index c1e572cdcc..ef7d6e2981 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -9,9 +9,8 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) - ADD_LIBRARY(dnode ${SRC}) - #ADD_EXECUTABLE(taosd ${SRC}) - #TARGET_LINK_LIBRARIES(taosd mnode sdb vnode taos_static monitor http) + ADD_EXECUTABLE(taosd ${SRC}) + TARGET_LINK_LIBRARIES(taosd mnode sdb taos_static monitor http) #IF (TD_CLUSTER) # TARGET_LINK_LIBRARIES(taosd dcluster) diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 50a0f81503..164bc80a35 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -50,7 +50,7 @@ void* dnodeProcessMsgFromShell(int8_t msgType, void *pCont, int32_t contLen, voi } if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { - rpcSendSimpleRsp(handle, TSDB_CODE_NOT_READY); + rpcSendResponse(handle, TSDB_CODE_NOT_READY, 0, 0); dTrace("conn:%p, query msg is ignored since dnode not running", handle); return NULL; } @@ -83,7 +83,7 @@ int32_t dnodeInitShell() { rpcInit.localPort = tsVnodeShellPort; rpcInit.label = "DND-shell"; rpcInit.numOfThreads = numOfThreads; - rpcInit.fp = dnodeProcessMsgFromShell; + rpcInit.cfp = dnodeProcessMsgFromShell; rpcInit.sessions = TSDB_SESSIONS_PER_DNODE; rpcInit.connType = TAOS_CONN_SOCKET_TYPE_S(); rpcInit.idleTime = tsShellActivityTimer * 2000; @@ -118,7 +118,7 @@ void dnodeProcessQueryRequestCb(int code, void *pQInfo, void *pConn) { queryRsp->code = htonl(code); queryRsp->qhandle = (uint64_t) (pQInfo); - rpcSendResponse(pConn, queryRsp, contLen); + rpcSendResponse(pConn, TSDB_CODE_SUCCESS, queryRsp, contLen); } static void dnodeProcessQueryRequest(int8_t *pCont, int32_t contLen, void *pConn) { @@ -134,7 +134,7 @@ void dnodeProcessRetrieveRequestCb(int32_t code, void *pQInfo, void *pConn) { assert(pConn != NULL); if (code != TSDB_CODE_SUCCESS) { - rpcSendSimpleRsp(pConn, code); + rpcSendResponse(pConn, code, 0, 0); return; } @@ -142,13 +142,13 @@ void dnodeProcessRetrieveRequestCb(int32_t code, void *pQInfo, void *pConn) { int32_t contLen = dnodeGetRetrieveDataSize(pQInfo); SRetrieveMeterRsp *retrieveRsp = (SRetrieveMeterRsp *) rpcMallocCont(contLen); if (retrieveRsp == NULL) { - rpcSendSimpleRsp(pConn, TSDB_CODE_SERV_OUT_OF_MEMORY); + rpcSendResponse(pConn, TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 0); return; } code = dnodeGetRetrieveData(pQInfo, retrieveRsp); if (code != TSDB_CODE_SUCCESS) { - rpcSendSimpleRsp(pConn, TSDB_CODE_INVALID_QHANDLE); + rpcSendResponse(pConn, TSDB_CODE_INVALID_QHANDLE, 0, 0); } retrieveRsp->numOfRows = htonl(retrieveRsp->numOfRows); @@ -156,7 +156,7 @@ void dnodeProcessRetrieveRequestCb(int32_t code, void *pQInfo, void *pConn) { retrieveRsp->offset = htobe64(retrieveRsp->offset); retrieveRsp->useconds = htobe64(retrieveRsp->useconds); - rpcSendResponse(pConn, retrieveRsp, contLen); + rpcSendResponse(pConn, TSDB_CODE_SUCCESS, retrieveRsp, contLen); } static void dnodeProcessRetrieveRequest(int8_t *pCont, int32_t contLen, void *pConn) { @@ -170,14 +170,14 @@ void dnodeProcessShellSubmitRequestCb(SShellSubmitRspMsg *result, void *pConn) { assert(result != NULL); if (result->code != 0) { - rpcSendSimpleRsp(pConn, result->code); + rpcSendResponse(pConn, result->code, 0, 0); return; } int32_t contLen = sizeof(SShellSubmitRspMsg) + result->numOfFailedBlocks * sizeof(SShellSubmitRspBlock); SShellSubmitRspMsg *submitRsp = (SShellSubmitRspMsg *) rpcMallocCont(contLen); if (submitRsp == NULL) { - rpcSendSimpleRsp(pConn, TSDB_CODE_SERV_OUT_OF_MEMORY); + rpcSendResponse(pConn, TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 0); return; } @@ -202,7 +202,7 @@ void dnodeProcessShellSubmitRequestCb(SShellSubmitRspMsg *result, void *pConn) { submitRsp->failedRows = htonl(submitRsp->failedRows); submitRsp->numOfFailedBlocks = htonl(submitRsp->numOfFailedBlocks); - rpcSendResponse(pConn, submitRsp, contLen); + rpcSendResponse(pConn, TSDB_CODE_SUCCESS, submitRsp, contLen); } static void dnodeProcessShellSubmitRequest(int8_t *pCont, int32_t contLen, void *pConn) { diff --git a/src/dnode/src/dnodeVnodeMgmt.c b/src/dnode/src/dnodeVnodeMgmt.c index ee92991203..c39f7848e1 100644 --- a/src/dnode/src/dnodeVnodeMgmt.c +++ b/src/dnode/src/dnodeVnodeMgmt.c @@ -19,14 +19,34 @@ #include "taoserror.h" #include "dnodeVnodeMgmt.h" -EVnodeStatus dnodeGetVnodeStatus(int32_t vnode) { - return TSDB_VN_STATUS_MASTER; +int32_t dnodeOpenVnodes() { + return 0; +} + +int32_t dnodeCleanupVnodes() { + return 0; } bool dnodeCheckVnodeExist(int32_t vnode) { return true; } +int32_t dnodeCreateVnode(int32_t vnode, SVPeersMsg *cfg) { + return 0; +} + +int32_t dnodeDropVnode(int32_t vnode) { + return 0; +} + +void* dnodeGetVnode(int vid) { + return NULL; +} + +EVnodeStatus dnodeGetVnodeStatus(int32_t vnode) { + return TSDB_VN_STATUS_MASTER; +} + bool dnodeCheckTableExist(int32_t vnode, int32_t sid, int64_t uid) { return true; } diff --git a/src/inc/mnode.h b/src/inc/mnode.h index 4f92e28d31..d0449489c6 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -152,9 +152,7 @@ typedef struct SSuperTableObj { int8_t reserved[7]; int8_t updateEnd[1]; - pthread_rwlock_t rwLock; - struct SSuperTableObj *prev, *next; int16_t nextColId; int8_t *schema; @@ -217,11 +215,11 @@ typedef struct _vg_obj { int32_t lbIp; int32_t lbTime; int8_t lbStatus; - int8_t reserved[16]; - int8_t updateEnd[1]; + int8_t reserved[16]; + int8_t updateEnd[1]; struct _vg_obj *prev, *next; void * idPool; - STabObj ** meterList; + void ** meterList; } SVgObj; typedef struct _db_obj { diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index 0f490c58b1..20a740dee9 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/kit/taosdemo/CMakeLists.txt b/src/kit/taosdemo/CMakeLists.txt index d47e6a06df..627092a85b 100644 --- a/src/kit/taosdemo/CMakeLists.txt +++ b/src/kit/taosdemo/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/kit/taosdump/CMakeLists.txt b/src/kit/taosdump/CMakeLists.txt index 5b54540782..0ff54200ce 100644 --- a/src/kit/taosdump/CMakeLists.txt +++ b/src/kit/taosdump/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/mnode/CMakeLists.txt b/src/mnode/CMakeLists.txt index a62b87fab6..a8abf54dfd 100644 --- a/src/mnode/CMakeLists.txt +++ b/src/mnode/CMakeLists.txt @@ -11,7 +11,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(mnode ${SRC}) - #TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread) + TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread) #IF (TD_CLUSTER) # TARGET_LINK_LIBRARIES(mnode mcluster) diff --git a/src/mnode/inc/mgmtDb.h b/src/mnode/inc/mgmtDb.h index 79c3509ece..e4843d01ef 100644 --- a/src/mnode/inc/mgmtDb.h +++ b/src/mnode/inc/mgmtDb.h @@ -28,8 +28,6 @@ int mgmtUseDb(SConnObj *pConn, char *name); int mgmtAddVgroupIntoDb(SDbObj *pDb, SVgObj *pVgroup); int mgmtAddVgroupIntoDbTail(SDbObj *pDb, SVgObj *pVgroup); int mgmtRemoveVgroupFromDb(SDbObj *pDb, SVgObj *pVgroup); -int mgmtAddMetricIntoDb(SDbObj *pDb, STabObj *pMetric); -int mgmtRemoveMetricFromDb(SDbObj *pDb, STabObj *pMetric); int mgmtMoveVgroupToTail(SDbObj *pDb, SVgObj *pVgroup); int mgmtMoveVgroupToHead(SDbObj *pDb, SVgObj *pVgroup); int mgmtGetDbMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); diff --git a/src/mnode/inc/mgmtDnodeInt.h b/src/mnode/inc/mgmtDnodeInt.h index e9d6aa1a26..c21081950b 100644 --- a/src/mnode/inc/mgmtDnodeInt.h +++ b/src/mnode/inc/mgmtDnodeInt.h @@ -38,8 +38,8 @@ int mgmtSendOneFreeVnodeMsg(SVnodeGid *pVnodeGid); char *taosBuildRspMsgToDnode(SDnodeObj *pObj, char type); char *taosBuildReqMsgToDnode(SDnodeObj *pObj, char type); -extern int32_t (*mgmtSendSimpleRspToDnode)(int32_t msgType, int32_t code); -extern int32_t (*mgmtSendMsgToDnode)(SDnodeObj *pObj, char *msg, int msgLen); +extern int32_t (*mgmtSendSimpleRspToDnode)(void *pConn, int32_t msgType, int32_t code); +extern int32_t (*mgmtSendMsgToDnode)(int8_t *pCont, int32_t contLen, int8_t msgType); extern int32_t (*mgmtInitDnodeInt)(); extern void (*mgmtCleanUpDnodeInt)(); extern void (*mgmtProcessDnodeStatus)(void *handle, void *tmrId); diff --git a/src/mnode/inc/mgmtNormalTable.h b/src/mnode/inc/mgmtNormalTable.h index a8cf30bdbd..f6238a1b5b 100644 --- a/src/mnode/inc/mgmtNormalTable.h +++ b/src/mnode/inc/mgmtNormalTable.h @@ -34,7 +34,7 @@ int32_t mgmtDropNormalTableColumnByName(SNormalTableObj *pTable, char * SNormalTableObj* mgmtGetNormalTable(char *tableId); SSchema* mgmtGetNormalTableSchema(SNormalTableObj *pTable); -int8_t * mgmtBuildCreateNormalTableMsg(SNormalTableObj *pTable, int8_t *pMsg, int32_t vnode); +int8_t * mgmtBuildCreateNormalTableMsg(SNormalTableObj *pTable, int32_t vnode); #ifdef __cplusplus } diff --git a/src/mnode/inc/mgmtTable.h b/src/mnode/inc/mgmtTable.h index 7b445baae3..5313565735 100644 --- a/src/mnode/inc/mgmtTable.h +++ b/src/mnode/inc/mgmtTable.h @@ -33,6 +33,7 @@ typedef struct { int mgmtInitMeters(); STableObj mgmtGetTable(char *tableId); +STableObj mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid); STabObj *mgmtGetTableInfo(char *src, char *tags[]); int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pInfo); diff --git a/src/mnode/inc/mgmtUtil.h b/src/mnode/inc/mgmtUtil.h index 78889607a6..9bce2e95a2 100644 --- a/src/mnode/inc/mgmtUtil.h +++ b/src/mnode/inc/mgmtUtil.h @@ -28,8 +28,7 @@ extern "C" { bool mgmtTableCreateFromSuperTable(STabObj *pTableObj); bool mgmtIsSuperTable(STabObj *pTableObj); bool mgmtIsNormalTable(STabObj *pTableObj); -char* mgmtTableGetTag(STabObj* pTable, int32_t col, SSchema* pTagColSchema); -int32_t mgmtGetTagsLength(STabObj* pSuperTable, int32_t col); +int32_t mgmtGetTagsLength(SSuperTableObj* pSuperTable, int32_t col); bool mgmtCheckIsMonitorDB(char *db, char *monitordb); int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate); diff --git a/src/mnode/src/mgmtAcct.c b/src/mnode/src/mgmtAcct.c index be695a036d..3ae7284cb7 100644 --- a/src/mnode/src/mgmtAcct.c +++ b/src/mnode/src/mgmtAcct.c @@ -20,6 +20,7 @@ #include "mgmtTable.h" #include "mgmtUser.h" #include "tschemautil.h" +#include "taoserror.h" extern void *userSdb; extern void *dbSdb; @@ -156,7 +157,7 @@ int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) { int numOfDbs = sdbGetNumOfRows(dbSdb); if (numOfDbs >= tsMaxDbs) { mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs); - return TSDB_CODE_TOO_MANY_DATABSES; + return TSDB_CODE_TOO_MANY_DATABASES; } return 0; } diff --git a/src/mnode/src/mgmtChildTable.c b/src/mnode/src/mgmtChildTable.c index da1b9c9a6e..b6ed7eee9f 100644 --- a/src/mnode/src/mgmtChildTable.c +++ b/src/mnode/src/mgmtChildTable.c @@ -208,86 +208,86 @@ void mgmtCleanUpChildTables() { int8_t *mgmtBuildCreateChildTableMsg(SChildTableObj *pTable, int8_t *pMsg, int32_t vnode, int32_t tagDataLen, int8_t *pTagData) { - SCreateChildTableMsg *pCreateTable = (SCreateChildTableMsg *) pMsg; - memcpy(pCreateTable->tableId, pTable->tableId, TSDB_TABLE_ID_LEN); - memcpy(pCreateTable->superTableId, pTable->superTable->tableId, TSDB_TABLE_ID_LEN); - pCreateTable->vnode = htonl(vnode); - pCreateTable->sid = htonl(pTable->sid); - pCreateTable->uid = pTable->uid; - pCreateTable->createdTime = htobe64(pTable->createdTime); - pCreateTable->sversion = htonl(pTable->superTable->sversion); - pCreateTable->numOfColumns = htons(pTable->superTable->numOfColumns); - pCreateTable->numOfTags = htons(pTable->superTable->numOfTags); - - SSchema *pSchema = pTable->superTable->schema; - int32_t totalCols = pCreateTable->numOfColumns + pCreateTable->numOfTags; - - for (int32_t col = 0; col < totalCols; ++col) { - SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; - colData->type = pSchema[col].type; - colData->bytes = htons(pSchema[col].bytes); - colData->colId = htons(pSchema[col].colId); - } - - int32_t totalColsSize = sizeof(SMColumn *) * totalCols; - pMsg = pCreateTable->data + totalColsSize + tagDataLen; - - memcpy(pCreateTable->data + totalColsSize, pTagData, tagDataLen); - pCreateTable->tagDataLen = htonl(tagDataLen); + SCreateTableMsg *pCreateTable = (SCreateTableMsg *) pMsg; +// memcpy(pCreateTable->tableId, pTable->tableId, TSDB_TABLE_ID_LEN); +// memcpy(pCreateTable->superTableId, pTable->superTable->tableId, TSDB_TABLE_ID_LEN); +// pCreateTable->vnode = htonl(vnode); +// pCreateTable->sid = htonl(pTable->sid); +// pCreateTable->uid = pTable->uid; +// pCreateTable->createdTime = htobe64(pTable->createdTime); +// pCreateTable->sversion = htonl(pTable->superTable->sversion); +// pCreateTable->numOfColumns = htons(pTable->superTable->numOfColumns); +// pCreateTable->numOfTags = htons(pTable->superTable->numOfTags); +// +// SSchema *pSchema = pTable->superTable->schema; +// int32_t totalCols = pCreateTable->numOfColumns + pCreateTable->numOfTags; +// +// for (int32_t col = 0; col < totalCols; ++col) { +// SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; +// colData->type = pSchema[col].type; +// colData->bytes = htons(pSchema[col].bytes); +// colData->colId = htons(pSchema[col].colId); +// } +// +// int32_t totalColsSize = sizeof(SMColumn *) * totalCols; +// pMsg = pCreateTable->data + totalColsSize + tagDataLen; +// +// memcpy(pCreateTable->data + totalColsSize, pTagData, tagDataLen); +// pCreateTable->tagDataLen = htonl(tagDataLen); return pMsg; } int32_t mgmtCreateChildTable(SDbObj *pDb, SCreateTableMsg *pCreate, SVgObj *pVgroup, int32_t sid) { - int numOfTables = sdbGetNumOfRows(tsChildTableSdb); - if (numOfTables >= tsMaxTables) { - mError("table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, tsMaxTables); - return TSDB_CODE_TOO_MANY_TABLES; - } - - char *pTagData = (char *) pCreate->schema; // it is a tag key - SSuperTableObj *pSuperTable = mgmtGetSuperTable(pTagData); - if (pSuperTable == NULL) { - mError("table:%s, corresponding super table does not exist", pCreate->meterId); - return TSDB_CODE_INVALID_TABLE; - } - - SChildTableObj *pTable = (SChildTableObj *) calloc(sizeof(SChildTableObj), 1); - if (pTable == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; - } - strcpy(pTable->tableId, pCreate->meterId); - strcpy(pTable->superTableId, pSuperTable->tableId); - pTable->createdTime = taosGetTimestampMs(); - pTable->superTable = pSuperTable; - pTable->vgId = pVgroup->vgId; - pTable->sid = sid; - pTable->uid = (((uint64_t) pTable->vgId) << 40) + ((((uint64_t) pTable->sid) & ((1ul << 24) - 1ul)) << 16) + - ((uint64_t) sdbGetVersion() & ((1ul << 16) - 1ul)); - - SVariableMsg tags = {0}; - tags.size = mgmtGetTagsLength(pSuperTable, INT_MAX) + (uint32_t) TSDB_TABLE_ID_LEN; - tags.data = (char *) calloc(1, tags.size); - if (tags.data == NULL) { - free(pTable); - mError("table:%s, corresponding super table schema is null", pCreate->meterId); - return TSDB_CODE_INVALID_TABLE; - } - memcpy(tags.data, pTagData, tags.size); - - if (sdbInsertRow(tsStreamTableSdb, pTable, 0) < 0) { - mError("table:%s, update sdb error", pCreate->meterId); - return TSDB_CODE_SDB_ERROR; - } - - mgmtAddTimeSeries(pTable->superTable->numOfColumns - 1); - - mgmtSendCreateChildTableMsg(pTable, pVgroup, tags.size, tags.data); - - mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" - PRIu64 - " db:%s", - pTable->tableId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name); +// int numOfTables = sdbGetNumOfRows(tsChildTableSdb); +// if (numOfTables >= tsMaxTables) { +// mError("table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, tsMaxTables); +// return TSDB_CODE_TOO_MANY_TABLES; +// } +// +// char *pTagData = (char *) pCreate->schema; // it is a tag key +// SSuperTableObj *pSuperTable = mgmtGetSuperTable(pTagData); +// if (pSuperTable == NULL) { +// mError("table:%s, corresponding super table does not exist", pCreate->meterId); +// return TSDB_CODE_INVALID_TABLE; +// } +// +// SChildTableObj *pTable = (SChildTableObj *) calloc(sizeof(SChildTableObj), 1); +// if (pTable == NULL) { +// return TSDB_CODE_SERV_OUT_OF_MEMORY; +// } +// strcpy(pTable->tableId, pCreate->meterId); +// strcpy(pTable->superTableId, pSuperTable->tableId); +// pTable->createdTime = taosGetTimestampMs(); +// pTable->superTable = pSuperTable; +// pTable->vgId = pVgroup->vgId; +// pTable->sid = sid; +// pTable->uid = (((uint64_t) pTable->vgId) << 40) + ((((uint64_t) pTable->sid) & ((1ul << 24) - 1ul)) << 16) + +// ((uint64_t) sdbGetVersion() & ((1ul << 16) - 1ul)); +// +// SVariableMsg tags = {0}; +// tags.size = mgmtGetTagsLength(pSuperTable, INT_MAX) + (uint32_t) TSDB_TABLE_ID_LEN; +// tags.data = (char *) calloc(1, tags.size); +// if (tags.data == NULL) { +// free(pTable); +// mError("table:%s, corresponding super table schema is null", pCreate->meterId); +// return TSDB_CODE_INVALID_TABLE; +// } +// memcpy(tags.data, pTagData, tags.size); +// +// if (sdbInsertRow(tsStreamTableSdb, pTable, 0) < 0) { +// mError("table:%s, update sdb error", pCreate->meterId); +// return TSDB_CODE_SDB_ERROR; +// } +// +// mgmtAddTimeSeries(pTable->superTable->numOfColumns - 1); +// +// mgmtSendCreateChildTableMsg(pTable, pVgroup, tags.size, tags.data); +// +// mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" +// PRIu64 +// " db:%s", +// pTable->tableId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name); return 0; } @@ -323,14 +323,14 @@ SChildTableObj* mgmtGetChildTable(char *tableId) { } int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName, char *nContent) { - int col = mgmtFindTagCol(pTable->superTable, tagName); - if (col < 0 || col > pTable->superTable->numOfTags) { - return TSDB_CODE_APP_ERROR; - } - - //TODO send msg to dnode - mTrace("Succeed to modify tag column %d of table %s", col, pTable->tableId); - return TSDB_CODE_SUCCESS; +// int col = mgmtFindTagCol(pTable->superTable, tagName); +// if (col < 0 || col > pTable->superTable->numOfTags) { +// return TSDB_CODE_APP_ERROR; +// } +// +// //TODO send msg to dnode +// mTrace("Succeed to modify tag column %d of table %s", col, pTable->tableId); +// return TSDB_CODE_SUCCESS; // int rowSize = 0; // SSchema *schema = (SSchema *)(pSuperTable->schema + (pSuperTable->numOfColumns + col) * sizeof(SSchema)); diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 0e324d7eda..41a1f9ebaf 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -27,6 +27,7 @@ #include "tschemautil.h" #include "tstatus.h" #include "mnode.h" +#include "taoserror.h" void *dbSdb = NULL; extern void *vgSdb; @@ -324,7 +325,7 @@ int mgmtDropDbByName(SAcctObj *pAcct, char *name, short ignoreNotExists) { } if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) { - return TSDB_CODE_MONITOR_DB_FORBEIDEN; + return TSDB_CODE_MONITOR_DB_FORBIDDEN; } return mgmtDropDb(pDb); @@ -479,33 +480,6 @@ int mgmtMoveVgroupToHead(SDbObj *pDb, SVgObj *pVgroup) { return 0; } -int mgmtAddMetricIntoDb(SDbObj *pDb, STabObj *pMetric) { - pMetric->next = pDb->pMetric; - pMetric->prev = NULL; - - if (pDb->pMetric) pDb->pMetric->prev = pMetric; - - pDb->pMetric = pMetric; - pDb->numOfMetrics++; - - return 0; -} - -int mgmtRemoveMetricFromDb(SDbObj *pDb, STabObj *pMetric) { - if (pMetric->prev) pMetric->prev->next = pMetric->next; - - if (pMetric->next) pMetric->next->prev = pMetric->prev; - - if (pMetric->prev == NULL) pDb->pMetric = pMetric->next; - - pDb->numOfMetrics--; - - if (pMetric->pSkipList != NULL) { - pMetric->pSkipList = tSkipListDestroy(pMetric->pSkipList); - } - return 0; -} - int mgmtShowTables(SAcctObj *pAcct, char *db) { int code; diff --git a/src/mnode/src/mgmtDnodeInt.c b/src/mnode/src/mgmtDnodeInt.c index 4d86baab87..9ce0a7f4d4 100644 --- a/src/mnode/src/mgmtDnodeInt.c +++ b/src/mnode/src/mgmtDnodeInt.c @@ -28,162 +28,179 @@ #include "tstatus.h" #include "tsystem.h" #include "tsched.h" - +#include "taoserror.h" #include "dnodeSystem.h" - - #include "mgmtChildTable.h" #include "mgmtNormalTable.h" #include "mgmtStreamTable.h" -void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj); +void mgmtProcessMsgFromDnode(int8_t *pCont, int32_t contLen, int32_t msgType, void *pConn); int mgmtSendVPeersMsg(SVgObj *pVgroup); char *mgmtBuildVpeersIe(char *pMsg, SVgObj *pVgroup, int vnode); char *mgmtBuildCreateMeterIe(STabObj *pTable, char *pMsg, int vnode); +extern void *tsDnodeMgmtQhandle; +void * mgmtStatusTimer = NULL; +void mgmtSendMsgToDnodeImpFp(SSchedMsg *sched) { + int8_t msgType = *(int8_t *) (sched->msg - sizeof(int32_t) - sizeof(int8_t)); + int32_t contLen = *(int32_t *) (sched->msg - sizeof(int8_t)); + int8_t *pCont = sched->msg; + void *pConn = NULL; -int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { - char * pMsg, *pStart; - int msgLen = 0; - STabObj * pTable = NULL; - SMeterCfgMsg *pCfg = (SMeterCfgMsg *)cont; - SVgObj * pVgroup; - - if (!sdbMaster) { - mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_TABLE_CFG_RSP, TSDB_CODE_REDIRECT); - return 0; - } - - int vnode = htonl(pCfg->vnode); - int sid = htonl(pCfg->sid); + dnodeProcessMsgFromMgmt(pCont, contLen, msgType, pConn); + rpcFreeCont(sched->msg); +} - pStart = taosBuildRspMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_TABLE_CFG_RSP, 64000); - if (pStart == NULL) { - mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_TABLE_CFG_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } +int32_t mgmtSendMsgToDnodeImp(int8_t *pCont, int32_t contLen, int8_t msgType) { + mTrace("msg:%s is sent to dnode", taosMsg[msgType]); + *(int8_t *) (pCont - sizeof(int32_t) - sizeof(int8_t)) = msgType; + *(int32_t *) (pCont - sizeof(int8_t)) = contLen; - pMsg = pStart; + SSchedMsg schedMsg = {0}; + schedMsg.fp = mgmtSendMsgToDnodeImpFp; + schedMsg.msg = pCont; - if (vnode < pObj->numOfVnodes) { - int vgId = pObj->vload[vnode].vgId; + taosScheduleTask(tsDnodeMgmtQhandle, &schedMsg); - pVgroup = mgmtGetVgroup(vgId); - if (pVgroup) pTable = pVgroup->meterList[sid]; - } + return TSDB_CODE_SUCCESS; +} - if (pTable) { - *pMsg = 0; // code - pMsg++; - pMsg = mgmtBuildCreateMeterIe(pTable, pMsg, vnode); - } else { - mTrace("dnode:%s, vnode:%d sid:%d, meter not there", taosIpStr(pObj->privateIp), vnode, sid); - *pMsg = TSDB_CODE_INVALID_TABLE_ID; - pMsg++; - - *(int32_t *)pMsg = htonl(vnode); - pMsg += sizeof(int32_t); - *(int32_t *)pMsg = htonl(sid); - pMsg += sizeof(int32_t); - } +int32_t (*mgmtSendMsgToDnode)(int8_t *pCont, int32_t contLen, int8_t msgType) = mgmtSendMsgToDnodeImp; - msgLen = pMsg - pStart; - mgmtSendMsgToDnode(pObj, pStart, msgLen); +int32_t mgmtSendSimpleRspToDnodeImp(void *pConn, int32_t msgType, int32_t code) { + int8_t *pCont = rpcMallocCont(sizeof(int32_t)); + *(int32_t *) pCont = code; - return 0; + mgmtSendMsgToDnodeImp(pCont, sizeof(int32_t), msgType); + return TSDB_CODE_SUCCESS; } -int mgmtProcessVpeerCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { - char * pMsg, *pStart; - int msgLen = 0; - SVpeerCfgMsg *pCfg = (SVpeerCfgMsg *)cont; - SVgObj * pVgroup = NULL; +int32_t (*mgmtSendSimpleRspToDnode)(void *pConn, int32_t msgType, int32_t code) = mgmtSendSimpleRspToDnodeImp; +int32_t mgmtProcessMeterCfgMsg(int8_t *pCont, int32_t contLen, void *pConn) { if (!sdbMaster) { - mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP, TSDB_CODE_REDIRECT); - return 0; + mgmtSendSimpleRspToDnode(pConn, TSDB_MSG_TYPE_TABLE_CFG_RSP, TSDB_CODE_REDIRECT); + return TSDB_CODE_REDIRECT; } - int vnode = htonl(pCfg->vnode); + SMeterCfgMsg *cfg = (SMeterCfgMsg *) pConn; + int32_t vnode = htonl(cfg->vnode); + int32_t sid = htonl(cfg->sid); - pStart = taosBuildRspMsgToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP); - if (pStart == NULL) { - mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; + STableObj table = mgmtGetTableByPos(0, vnode, sid); + if (table.obj == NULL) { + mgmtSendSimpleRspToDnode(pConn, TSDB_MSG_TYPE_TABLE_CFG_RSP, TSDB_CODE_INVALID_TABLE); + return TSDB_CODE_INVALID_TABLE_ID; } - pMsg = pStart; - - if (vnode < pObj->numOfVnodes) pVgroup = mgmtGetVgroup(pObj->vload[vnode].vgId); - if (pVgroup) { - *pMsg = 0; - pMsg++; - pMsg = mgmtBuildVpeersIe(pMsg, pVgroup, vnode); - mTrace("dnode:%s, vnode:%d, vgroup:%d, send create vnode msg, code:%d", taosIpStr(pObj->privateIp), vnode, pVgroup->vgId, *pMsg); + int8_t *pCreateTableMsg = NULL; + if (table.type == TSDB_TABLE_TYPE_NORMAL_TABLE) { + pCreateTableMsg = mgmtBuildCreateNormalTableMsg((SNormalTableObj *)table.obj, vnode); + } else if (table.type == TSDB_TABLE_TYPE_CHILD_TABLE) { + pCreateTableMsg = mgmtBuildCreateNormalTableMsg((SNormalTableObj *)table.obj, vnode); + } else if (table.type == TSDB_TABLE_TYPE_STREAM_TABLE) { + pCreateTableMsg = mgmtBuildCreateNormalTableMsg((SNormalTableObj *)table.obj, vnode); + } else {} + + if (pCreateTableMsg != NULL) { + mgmtSendMsgToDnode(pCreateTableMsg, 0, TSDB_MSG_TYPE_TABLE_CFG_RSP); + return TSDB_CODE_SUCCESS; } else { - mTrace("dnode:%s, vnode:%d, no vgroup info, vgroup:%d", taosIpStr(pObj->privateIp), vnode, pObj->vload[vnode].vgId); - *pMsg = TSDB_CODE_NOT_ACTIVE_VNODE; - pMsg++; - *(int32_t *)pMsg = htonl(vnode); - pMsg += sizeof(int32_t); + mgmtSendSimpleRspToDnode(pConn, TSDB_MSG_TYPE_TABLE_CFG_RSP, TSDB_CODE_INVALID_TABLE); + return TSDB_CODE_INVALID_TABLE; } +} - msgLen = pMsg - pStart; - mgmtSendMsgToDnode(pObj, pStart, msgLen); +int mgmtProcessVpeerCfgMsg(int8_t *pCont, int32_t contLen, void *pConn) { +// char * pMsg, *pStart; +// int msgLen = 0; +// SVpeerCfgMsg *pCfg = (SVpeerCfgMsg *)cont; +// SVgObj * pVgroup = NULL; +// +// if (!sdbMaster) { +// mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP, TSDB_CODE_REDIRECT); +// return 0; +// } +// +// int vnode = htonl(pCfg->vnode); +// +// pStart = taosBuildRspMsgToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP); +// if (pStart == NULL) { +// mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VNODE_CFG_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// pMsg = pStart; +// +// if (vnode < pObj->numOfVnodes) pVgroup = mgmtGetVgroup(pObj->vload[vnode].vgId); +// +// if (pVgroup) { +// *pMsg = 0; +// pMsg++; +// pMsg = mgmtBuildVpeersIe(pMsg, pVgroup, vnode); +// mTrace("dnode:%s, vnode:%d, vgroup:%d, send create vnode msg, code:%d", taosIpStr(pObj->privateIp), vnode, pVgroup->vgId, *pMsg); +// } else { +// mTrace("dnode:%s, vnode:%d, no vgroup info, vgroup:%d", taosIpStr(pObj->privateIp), vnode, pObj->vload[vnode].vgId); +// *pMsg = TSDB_CODE_NOT_ACTIVE_VNODE; +// pMsg++; +// *(int32_t *)pMsg = htonl(vnode); +// pMsg += sizeof(int32_t); +// } +// +// msgLen = pMsg - pStart; +// mgmtSendMsgToDnode(pObj, pStart, msgLen); return 0; } -int mgmtProcessCreateRsp(char *msg, int msgLen, SDnodeObj *pObj) { return 0; } - -int mgmtProcessFreeVnodeRsp(char *msg, int msgLen, SDnodeObj *pObj) { return 0; } - -int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) { - STaosRsp *pRsp = (STaosRsp *)msg; - - if (!sdbMaster) { - mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_DNODE_VPEERS_RSP, TSDB_CODE_REDIRECT); - return 0; - } - - SDbObj *pDb = mgmtGetDb(pRsp->more); - if (!pDb) { - mError("dnode:%s, db:%s not find, code:%d", taosIpStr(pObj->privateIp), pRsp->more, pRsp->code); - return 0; - } - - if (pDb->vgStatus != TSDB_VG_STATUS_IN_PROGRESS) { - mTrace("dnode:%s, db:%s vpeer rsp already disposed, vgroup status:%s code:%d", - taosIpStr(pObj->privateIp), pRsp->more, taosGetVgroupStatusStr(pDb->vgStatus), pRsp->code); - return 0; - } - - if (pRsp->code == TSDB_CODE_SUCCESS) { - pDb->vgStatus = TSDB_VG_STATUS_READY; - mTrace("dnode:%s, db:%s vgroup is created in dnode", taosIpStr(pObj->privateIp), pRsp->more); - return 0; - } - - pDb->vgStatus = pRsp->code; - mError("dnode:%s, db:%s vgroup init failed, code:%d %s", - taosIpStr(pObj->privateIp), pRsp->more, pRsp->code, taosGetVgroupStatusStr(pDb->vgStatus)); +int mgmtProcessCreateRsp(int8_t *pCont, int32_t contLen, void *pConn) { return 0; } + +int mgmtProcessFreeVnodeRsp(int8_t *pCont, int32_t contLen, void *pConn) { return 0; } + +int mgmtProcessVPeersRsp(int8_t *pCont, int32_t contLen, void *pConn) { +// STaosRsp *pRsp = (STaosRsp *)msg; +// +// if (!sdbMaster) { +// mgmtSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_DNODE_VPEERS_RSP, TSDB_CODE_REDIRECT); +// return 0; +// } +// +// SDbObj *pDb = mgmtGetDb(pRsp->more); +// if (!pDb) { +// mError("dnode:%s, db:%s not find, code:%d", taosIpStr(pObj->privateIp), pRsp->more, pRsp->code); +// return 0; +// } +// +// if (pDb->vgStatus != TSDB_VG_STATUS_IN_PROGRESS) { +// mTrace("dnode:%s, db:%s vpeer rsp already disposed, vgroup status:%s code:%d", +// taosIpStr(pObj->privateIp), pRsp->more, taosGetVgroupStatusStr(pDb->vgStatus), pRsp->code); +// return 0; +// } +// +// if (pRsp->code == TSDB_CODE_SUCCESS) { +// pDb->vgStatus = TSDB_VG_STATUS_READY; +// mTrace("dnode:%s, db:%s vgroup is created in dnode", taosIpStr(pObj->privateIp), pRsp->more); +// return 0; +// } +// +// pDb->vgStatus = pRsp->code; +// mError("dnode:%s, db:%s vgroup init failed, code:%d %s", +// taosIpStr(pObj->privateIp), pRsp->more, pRsp->code, taosGetVgroupStatusStr(pDb->vgStatus)); return 0; } - -void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj) { +void mgmtProcessMsgFromDnode(int8_t *pCont, int32_t contLen, int32_t msgType, void *pConn) { if (msgType == TSDB_MSG_TYPE_TABLE_CFG) { - mgmtProcessMeterCfgMsg(content, msgLen - sizeof(SIntMsg), pObj); + mgmtProcessMeterCfgMsg(pCont, contLen, pConn); } else if (msgType == TSDB_MSG_TYPE_VNODE_CFG) { - mgmtProcessVpeerCfgMsg(content, msgLen - sizeof(SIntMsg), pObj); - } else if (msgType == TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE_RSP) { - mgmtProcessCreateRsp(content, msgLen - sizeof(SIntMsg), pObj); - } else if (msgType == TSDB_MSG_TYPE_REMOVE_RSP) { + mgmtProcessVpeerCfgMsg(pCont, contLen, pConn); + } else if (msgType == TSDB_MSG_TYPE_DNODE_CREATE_TABLE_RSP) { + mgmtProcessCreateRsp(pCont, contLen, pConn); + } else if (msgType == TSDB_MSG_TYPE_DNODE_REMOVE_TABLE_RSP) { // do nothing } else if (msgType == TSDB_MSG_TYPE_DNODE_VPEERS_RSP) { - mgmtProcessVPeersRsp(content, msgLen - sizeof(SIntMsg), pObj); + mgmtProcessVPeersRsp(pCont, contLen, pConn); } else if (msgType == TSDB_MSG_TYPE_DNODE_FREE_VNODE_RSP) { - mgmtProcessFreeVnodeRsp(content, msgLen - sizeof(SIntMsg), pObj); + mgmtProcessFreeVnodeRsp(pCont, contLen, pConn); } else if (msgType == TSDB_MSG_TYPE_DNODE_CFG_RSP) { // do nothing; } else if (msgType == TSDB_MSG_TYPE_ALTER_STREAM_RSP) { @@ -193,186 +210,145 @@ void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj * } } -char *mgmtBuildCreateMeterIe(STabObj *pTable, char *pMsg, int vnode) { - SCreateMsg *pCreateMeter; - - pCreateMeter = (SCreateMsg *)pMsg; - pCreateMeter->vnode = htons(vnode); - pCreateMeter->sid = htonl(pTable->gid.sid); - pCreateMeter->uid = pTable->uid; - memcpy(pCreateMeter->meterId, pTable->meterId, TSDB_TABLE_ID_LEN); - - // pCreateMeter->lastCreate = htobe64(pVgroup->lastCreate); - pCreateMeter->timeStamp = htobe64(pTable->createdTime); - /* - pCreateMeter->spi = pSec->spi; - pCreateMeter->encrypt = pSec->encrypt; - memcpy(pCreateMeter->cipheringKey, pSec->cipheringKey, TSDB_KEY_LEN); - memcpy(pCreateMeter->secret, pSec->secret, TSDB_KEY_LEN); - */ - pCreateMeter->sversion = htonl(pTable->sversion); - pCreateMeter->numOfColumns = htons(pTable->numOfColumns); - SSchema *pSchema = mgmtGetTableSchema(pTable); - - for (int i = 0; i < pTable->numOfColumns; ++i) { - pCreateMeter->schema[i].type = pSchema[i].type; - /* strcpy(pCreateMeter->schema[i].name, pColumnModel[i].name); */ - pCreateMeter->schema[i].bytes = htons(pSchema[i].bytes); - pCreateMeter->schema[i].colId = htons(pSchema[i].colId); - } - - pMsg = ((char *)(pCreateMeter->schema)) + pTable->numOfColumns * sizeof(SMColumn); - pCreateMeter->sqlLen = 0; - - if (pTable->pSql) { - int len = strlen(pTable->pSql) + 1; - pCreateMeter->sqlLen = htons(len); - strcpy(pMsg, pTable->pSql); - pMsg += len; - } - - return pMsg; -} - int32_t mgmtSendCreateChildTableMsg(SChildTableObj *pTable, SVgObj *pVgroup, int32_t tagDataLen, int8_t *pTagData) { - uint64_t timeStamp = taosGetTimestampMs(); - - for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { - SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); - if (pObj == NULL) { - continue; - } - - int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); - if (pStart == NULL) { - continue; - } - - int8_t *pMsg = mgmtBuildCreateChildTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode, tagDataLen, pTagData); - int32_t msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pObj, pStart, msgLen); - } - - pVgroup->lastCreate = timeStamp; +// uint64_t timeStamp = taosGetTimestampMs(); +// +// for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { +// SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); +// if (pObj == NULL) { +// continue; +// } +// +// int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); +// if (pStart == NULL) { +// continue; +// } +// +// int8_t *pMsg = mgmtBuildCreateChildTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode, tagDataLen, pTagData); +// int32_t msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pObj, pStart, msgLen); +// } +// +// pVgroup->lastCreate = timeStamp; return 0; } int32_t mgmtSendCreateStreamTableMsg(SStreamTableObj *pTable, SVgObj *pVgroup) { - uint64_t timeStamp = taosGetTimestampMs(); - - for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { - SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); - if (pObj == NULL) { - continue; - } - - int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); - if (pStart == NULL) { - continue; - } - - int8_t *pMsg = mgmtBuildCreateStreamTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode); - int32_t msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pObj, pStart, msgLen); - } - - pVgroup->lastCreate = timeStamp; +// uint64_t timeStamp = taosGetTimestampMs(); +// +// for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { +// SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); +// if (pObj == NULL) { +// continue; +// } +// +// int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); +// if (pStart == NULL) { +// continue; +// } +// +// int8_t *pMsg = mgmtBuildCreateStreamTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode); +// int32_t msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pObj, pStart, msgLen); +// } +// +// pVgroup->lastCreate = timeStamp; return 0; } int32_t mgmtSendCreateNormalTableMsg(SNormalTableObj *pTable, SVgObj *pVgroup) { - uint64_t timeStamp = taosGetTimestampMs(); - - for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { - SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); - if (pObj == NULL) { - continue; - } - - int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); - if (pStart == NULL) { - continue; - } - - int8_t *pMsg = mgmtBuildCreateNormalTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode); - int32_t msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pObj, pStart, msgLen); - } - - pVgroup->lastCreate = timeStamp; - return 0; +// uint64_t timeStamp = taosGetTimestampMs(); +// +// for (int32_t index = 0; index < pVgroup->numOfVnodes; ++index) { +// SDnodeObj *pObj = mgmtGetDnode(pVgroup->vnodeGid[index].ip); +// if (pObj == NULL) { +// continue; +// } +// +// int8_t *pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_DNODE_CREATE_CHILD_TABLE, 64000); +// if (pStart == NULL) { +// continue; +// } +// +// int8_t *pMsg = mgmtBuildCreateNormalTableMsg(pTable, pStart, pVgroup->vnodeGid[index].vnode); +// int32_t msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pObj, pStart, msgLen); +// } +// +// pVgroup->lastCreate = timeStamp; +// return 0; } int mgmtSendRemoveMeterMsgToDnode(STabObj *pTable, SVgObj *pVgroup) { - SDRemoveTableMsg *pRemove; - char * pMsg, *pStart; - int i, msgLen = 0; - SDnodeObj * pObj; - char ipstr[20]; - uint64_t timeStamp; - - timeStamp = taosGetTimestampMs(); - - for (i = 0; i < pVgroup->numOfVnodes; ++i) { - //if (pVgroup->vnodeGid[i].ip == 0) continue; - - pObj = mgmtGetDnode(pVgroup->vnodeGid[i].ip); - if (pObj == NULL) continue; - - pStart = taosBuildReqMsgToDnode(pObj, TSDB_MSG_TYPE_DNODE_REMOVE_CHILD_TABLE); - if (pStart == NULL) continue; - pMsg = pStart; - - pRemove = (SDRemoveTableMsg *)pMsg; - pRemove->vnode = htons(pVgroup->vnodeGid[i].vnode); - pRemove->sid = htonl(pTable->gid.sid); - memcpy(pRemove->meterId, pTable->meterId, TSDB_TABLE_ID_LEN); - - pMsg += sizeof(SDRemoveTableMsg); - msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pObj, pStart, msgLen); - - tinet_ntoa(ipstr, pVgroup->vnodeGid[i].ip); - mTrace("dnode:%s vid:%d, send remove meter msg, sid:%d status:%d", ipstr, pVgroup->vnodeGid[i].vnode, - pTable->gid.sid, pObj->status); - } - - pVgroup->lastRemove = timeStamp; +// SDRemoveTableMsg *pRemove; +// char * pMsg, *pStart; +// int i, msgLen = 0; +// SDnodeObj * pObj; +// char ipstr[20]; +// uint64_t timeStamp; +// +// timeStamp = taosGetTimestampMs(); +// +// for (i = 0; i < pVgroup->numOfVnodes; ++i) { +// //if (pVgroup->vnodeGid[i].ip == 0) continue; +// +// pObj = mgmtGetDnode(pVgroup->vnodeGid[i].ip); +// if (pObj == NULL) continue; +// +// pStart = taosBuildReqMsgToDnode(pObj, TSDB_MSG_TYPE_DNODE_REMOVE_CHILD_TABLE); +// if (pStart == NULL) continue; +// pMsg = pStart; +// +// pRemove = (SDRemoveTableMsg *)pMsg; +// pRemove->vnode = htons(pVgroup->vnodeGid[i].vnode); +// pRemove->sid = htonl(pTable->gid.sid); +// memcpy(pRemove->meterId, pTable->meterId, TSDB_TABLE_ID_LEN); +// +// pMsg += sizeof(SDRemoveTableMsg); +// msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pObj, pStart, msgLen); +// +// tinet_ntoa(ipstr, pVgroup->vnodeGid[i].ip); +// mTrace("dnode:%s vid:%d, send remove meter msg, sid:%d status:%d", ipstr, pVgroup->vnodeGid[i].vnode, +// pTable->gid.sid, pObj->status); +// } +// +// pVgroup->lastRemove = timeStamp; return 0; } int mgmtSendAlterStreamMsgToDnode(STabObj *pTable, SVgObj *pVgroup) { - SAlterStreamMsg *pAlter; - char * pMsg, *pStart; - int i, msgLen = 0; - SDnodeObj * pObj; - - for (i = 0; i < pVgroup->numOfVnodes; ++i) { - if (pVgroup->vnodeGid[i].ip == 0) continue; - - pObj = mgmtGetDnode(pVgroup->vnodeGid[i].ip); - if (pObj == NULL) continue; - - pStart = taosBuildReqMsgToDnode(pObj, TSDB_MSG_TYPE_ALTER_STREAM); - if (pStart == NULL) continue; - pMsg = pStart; - - pAlter = (SAlterStreamMsg *)pMsg; - pAlter->vnode = htons(pVgroup->vnodeGid[i].vnode); - pAlter->sid = htonl(pTable->gid.sid); - pAlter->uid = pTable->uid; - pAlter->status = pTable->status; - - pMsg += sizeof(SAlterStreamMsg); - msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pObj, pStart, msgLen); - } +// SAlterStreamMsg *pAlter; +// char * pMsg, *pStart; +// int i, msgLen = 0; +// SDnodeObj * pObj; +// +// for (i = 0; i < pVgroup->numOfVnodes; ++i) { +// if (pVgroup->vnodeGid[i].ip == 0) continue; +// +// pObj = mgmtGetDnode(pVgroup->vnodeGid[i].ip); +// if (pObj == NULL) continue; +// +// pStart = taosBuildReqMsgToDnode(pObj, TSDB_MSG_TYPE_ALTER_STREAM); +// if (pStart == NULL) continue; +// pMsg = pStart; +// +// pAlter = (SAlterStreamMsg *)pMsg; +// pAlter->vnode = htons(pVgroup->vnodeGid[i].vnode); +// pAlter->sid = htonl(pTable->gid.sid); +// pAlter->uid = pTable->uid; +// pAlter->status = pTable->status; +// +// pMsg += sizeof(SAlterStreamMsg); +// msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pObj, pStart, msgLen); +// } return 0; } @@ -413,61 +389,61 @@ char *mgmtBuildVpeersIe(char *pMsg, SVgObj *pVgroup, int vnode) { } int mgmtSendVPeersMsg(SVgObj *pVgroup) { - SDnodeObj *pDnode; - char * pMsg, *pStart; - int msgLen = 0; - - for (int i = 0; i < pVgroup->numOfVnodes; ++i) { - pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].ip); - if (pDnode == NULL) { - mError("dnode:%s not there", taosIpStr(pVgroup->vnodeGid[i].ip)); - continue; - } - - pDnode->vload[pVgroup->vnodeGid[i].vnode].vgId = pVgroup->vgId; - mgmtUpdateDnode(pDnode); - - if (pDnode->thandle && pVgroup->numOfVnodes >= 1) { - pStart = taosBuildReqMsgToDnode(pDnode, TSDB_MSG_TYPE_DNODE_VPEERS); - if (pStart == NULL) continue; - pMsg = mgmtBuildVpeersIe(pStart, pVgroup, pVgroup->vnodeGid[i].vnode); - msgLen = pMsg - pStart; - - mgmtSendMsgToDnode(pDnode, pStart, msgLen); - } - } +// SDnodeObj *pDnode; +// char * pMsg, *pStart; +// int msgLen = 0; +// +// for (int i = 0; i < pVgroup->numOfVnodes; ++i) { +// pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].ip); +// if (pDnode == NULL) { +// mError("dnode:%s not there", taosIpStr(pVgroup->vnodeGid[i].ip)); +// continue; +// } +// +// pDnode->vload[pVgroup->vnodeGid[i].vnode].vgId = pVgroup->vgId; +// mgmtUpdateDnode(pDnode); +// +// if (pDnode->thandle && pVgroup->numOfVnodes >= 1) { +// pStart = taosBuildReqMsgToDnode(pDnode, TSDB_MSG_TYPE_DNODE_VPEERS); +// if (pStart == NULL) continue; +// pMsg = mgmtBuildVpeersIe(pStart, pVgroup, pVgroup->vnodeGid[i].vnode); +// msgLen = pMsg - pStart; +// +// mgmtSendMsgToDnode(pDnode, pStart, msgLen); +// } +// } return 0; } int mgmtSendOneFreeVnodeMsg(SVnodeGid *pVnodeGid) { - SFreeVnodeMsg *pFreeVnode; - char * pMsg, *pStart; - int msgLen = 0; - SDnodeObj * pDnode; - - pDnode = mgmtGetDnode(pVnodeGid->ip); - if (pDnode == NULL) { - mError("dnode:%s not there", taosIpStr(pVnodeGid->ip)); - return -1; - } - - if (pDnode->thandle == NULL) { - mTrace("dnode:%s offline, failed to send Vpeer msg", taosIpStr(pVnodeGid->ip)); - return -1; - } - - pStart = taosBuildReqMsgToDnode(pDnode, TSDB_MSG_TYPE_DNODE_FREE_VNODE); - if (pStart == NULL) return -1; - pMsg = pStart; - - pFreeVnode = (SFreeVnodeMsg *)pMsg; - pFreeVnode->vnode = htons(pVnodeGid->vnode); - - pMsg += sizeof(SFreeVnodeMsg); - - msgLen = pMsg - pStart; - mgmtSendMsgToDnode(pDnode, pStart, msgLen); +// SFreeVnodeMsg *pFreeVnode; +// char * pMsg, *pStart; +// int msgLen = 0; +// SDnodeObj * pDnode; +// +// pDnode = mgmtGetDnode(pVnodeGid->ip); +// if (pDnode == NULL) { +// mError("dnode:%s not there", taosIpStr(pVnodeGid->ip)); +// return -1; +// } +// +// if (pDnode->thandle == NULL) { +// mTrace("dnode:%s offline, failed to send Vpeer msg", taosIpStr(pVnodeGid->ip)); +// return -1; +// } +// +// pStart = taosBuildReqMsgToDnode(pDnode, TSDB_MSG_TYPE_DNODE_FREE_VNODE); +// if (pStart == NULL) return -1; +// pMsg = pStart; +// +// pFreeVnode = (SFreeVnodeMsg *)pMsg; +// pFreeVnode->vnode = htons(pVnodeGid->vnode); +// +// pMsg += sizeof(SFreeVnodeMsg); +// +// msgLen = pMsg - pStart; +// mgmtSendMsgToDnode(pDnode, pStart, msgLen); return 0; } @@ -554,52 +530,6 @@ int mgmtSendCfgDnodeMsg(char *cont) { return 0; } - -/* - * functions for communicate between dnode and mnode - */ - -extern void *tsDnodeMgmtQhandle; -void * mgmtStatusTimer = NULL; -void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj); - - -void mgmtSendMsgToDnodeImpFp(SSchedMsg *sched) { - int8_t msgType = *(int8_t *) (sched->msg - sizeof(int32_t) - sizeof(int8_t)); - int32_t contLen = *(int32_t *) (sched->msg - sizeof(int8_t)); - int8_t *pCont = sched->msg; - void *pConn = NULL; - - dnodeProcessMsgFromMgmt(pCont, contLen, msgType, pConn); - rpcFreeCont(sched->msg); -} - -int32_t mgmtSendMsgToDnodeImp(int8_t *pCont, int32_t contLen, int8_t msgType) { - mTrace("msg:%s is sent to dnode", taosMsg[msgType]); - *(int8_t *) (pCont - sizeof(int32_t) - sizeof(int8_t)) = msgType; - *(int32_t *) (pCont - sizeof(int8_t)) = contLen; - - SSchedMsg schedMsg = {0}; - schedMsg.fp = mgmtSendMsgToDnodeImpFp; - schedMsg.msg = pCont; - - taosScheduleTask(tsDnodeMgmtQhandle, &schedMsg); - - return TSDB_CODE_SUCCESS; -} - -int32_t (*mgmtSendMsgToDnode)(SDnodeObj *pObj, char *msg, int msgLen) = mgmtSendMsgToDnodeImp; - -int32_t mgmtSendSimpleRspToDnodeImp(int32_t msgType, int32_t code) { - int8_t *pCont = rpcMallocCont(sizeof(int32_t)); - *(int32_t *) pCont = code; - - mgmtSendMsgToDnodeImp(pCont, sizeof(int32_t), msgType); - return TSDB_CODE_SUCCESS; -} - -int32_t (*mgmtSendSimpleRspToDnode)(int32_t msgType, int32_t code) = mgmtSendSimpleRspToDnodeImp; - int32_t mgmtInitDnodeIntImp() { return 0; } int32_t (*mgmtInitDnodeInt)() = mgmtInitDnodeIntImp; diff --git a/src/mnode/src/mgmtNormalTable.c b/src/mnode/src/mgmtNormalTable.c index 0551e3bc99..5e37c380cd 100644 --- a/src/mnode/src/mgmtNormalTable.c +++ b/src/mnode/src/mgmtNormalTable.c @@ -39,7 +39,7 @@ #include "mgmtNormalTable.h" -void *tsSuperTableSdb; +void *tsNormalTableSdb; void *(*mgmtNormalTableActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize); void *mgmtNormalTableActionInsert(void *row, char *str, int size, int *ssize); @@ -218,8 +218,9 @@ void mgmtCleanUpNormalTables() { sdbCloseTable(tsNormalTableSdb); } -int8_t *mgmtBuildCreateNormalTableMsg(SNormalTableObj *pTable, int8_t *pMsg, int32_t vnode) { - SCreateNormalTableMsg *pCreateTable = (SCreateNormalTableMsg *) pMsg; +int8_t *mgmtBuildCreateNormalTableMsg(SNormalTableObj *pTable, int32_t vnode) { + int8_t *pMsg = NULL; + SDCreateTableMsg *pCreateTable = (SDCreateTableMsg *) pMsg; memcpy(pCreateTable->tableId, pTable->tableId, TSDB_TABLE_ID_LEN); pCreateTable->vnode = htobe32(vnode); pCreateTable->sid = htobe32(pTable->sid); @@ -231,15 +232,15 @@ int8_t *mgmtBuildCreateNormalTableMsg(SNormalTableObj *pTable, int8_t *pMsg, int SSchema *pSchema = pTable->schema; int32_t totalCols = pCreateTable->numOfColumns; - for (int32_t col = 0; col < totalCols; ++col) { - SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; - colData->type = pSchema[col].type; - colData->bytes = htons(pSchema[col].bytes); - colData->colId = htons(pSchema[col].colId); - } +// for (int32_t col = 0; col < totalCols; ++col) { +// SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; +// colData->type = pSchema[col].type; +// colData->bytes = htons(pSchema[col].bytes); +// colData->colId = htons(pSchema[col].colId); +// } - int32_t totalColsSize = sizeof(SMColumn *) * totalCols; - pMsg = pCreateTable->data + totalColsSize; +// int32_t totalColsSize = sizeof(SMColumn *) * totalCols; +// pMsg = pCreateTable->data + totalColsSize; return pMsg; } diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 9619804bf1..d9161e1f04 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -34,6 +34,8 @@ #include "taosmsg.h" #include "tlog.h" #include "tstatus.h" +#include "tsched.h" +#include "trpc.h" #define MAX_LEN_OF_METER_META (sizeof(SMultiMeterMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS + sizeof(SSchema) * TSDB_MAX_TAGS + TSDB_MAX_TAGS_LEN) @@ -87,17 +89,13 @@ int mgmtInitShell() { rpcInit.localPort = tsMgmtShellPort; rpcInit.label = "MND-shell"; rpcInit.numOfThreads = numOfThreads; - rpcInit.fp = mgmtProcessMsgFromShell; - rpcInit.bits = 20; - rpcInit.numOfChanns = 1; - rpcInit.sessionsPerChann = tsMaxShellConns; - rpcInit.idMgmt = TAOS_ID_FREE; + rpcInit.cfp = mgmtProcessMsgFromShell; + rpcInit.sessions = tsMaxShellConns; rpcInit.connType = TAOS_CONN_SOCKET_TYPE_S(); rpcInit.idleTime = tsShellActivityTimer * 2000; - rpcInit.qhandle = mgmtQhandle; rpcInit.afp = mgmtRetriveUserAuthInfo; - pShellConn = taosOpenRpc(&rpcInit); + pShellConn = rpcOpen(&rpcInit); if (pShellConn == NULL) { mError("failed to init tcp connection to shell"); return -1; @@ -107,8 +105,10 @@ int mgmtInitShell() { } void mgmtCleanUpShell() { - if (pShellConn) taosCloseRpc(pShellConn); - pShellConn = NULL; + if (pShellConn) { + rpcClose(pShellConn); + pShellConn = NULL; + } tfree(connList); } @@ -138,21 +138,23 @@ static uint32_t mgmtSetMeterTagValue(char *pTags, STabObj *pMetric, STabObj *pMe } static char *mgmtAllocMsg(SConnObj *pConn, int32_t size, char **pMsg, STaosRsp **pRsp) { - char *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, size); - if (pStart == NULL) return 0; - *pMsg = pStart; - *pRsp = (STaosRsp *)(*pMsg); - - return pStart; +// char *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, size); +// if (pStart == NULL) return 0; +// *pMsg = pStart; +// *pRsp = (STaosRsp *)(*pMsg); +// +// return pStart; + return 0; } static char *mgmtForMultiAllocMsg(SConnObj *pConn, int32_t size, char **pMsg, STaosRsp **pRsp) { - char *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, size); - if (pStart == NULL) return 0; - *pMsg = pStart; - *pRsp = (STaosRsp *)(*pMsg); - - return pStart; +// char *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, size); +// if (pStart == NULL) return 0; +// *pMsg = pStart; +// *pRsp = (STaosRsp *)(*pMsg); +// +// return pStart; + return 0; } /** @@ -164,176 +166,179 @@ static char *mgmtForMultiAllocMsg(SConnObj *pConn, int32_t size, char **pMsg, ST bool mgmtCheckMeterMetaMsgType(char *pMsg) { SMeterInfoMsg *pInfo = (SMeterInfoMsg *)pMsg; - int16_t autoCreate = htons(pInfo->createFlag); - STabObj *pMeterObj = mgmtGetTable(pInfo->meterId); + int16_t autoCreate = htons(pInfo->createFlag); + STableObj table = mgmtGetTable(pInfo->meterId); // If table does not exists and autoCreate flag is set, we add the handler into another task queue, namely tranQueue - bool addIntoTranQueue = (pMeterObj == NULL && autoCreate == 1); - if (addIntoTranQueue) { - mTrace("meter:%s auto created task added", pInfo->meterId); - } +// bool addIntoTranQueue = (pMeterObj == NULL && autoCreate == 1); +// if (addIntoTranQueue) { +// mTrace("meter:%s auto created task added", pInfo->meterId); +// } + + bool addIntoTranQueue = true; return addIntoTranQueue; } int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SMeterInfoMsg *pInfo = (SMeterInfoMsg *)pMsg; - STabObj * pMeterObj = NULL; - SVgObj * pVgroup = NULL; - SMeterMeta * pMeta = NULL; - SSchema * pSchema = NULL; - STaosRsp * pRsp = NULL; - char * pStart = NULL; - - pInfo->createFlag = htons(pInfo->createFlag); - - int size = sizeof(STaosHeader) + sizeof(STaosRsp) + sizeof(SMeterMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS + - sizeof(SSchema) * TSDB_MAX_TAGS + TSDB_MAX_TAGS_LEN + TSDB_EXTRA_PAYLOAD_SIZE; - - SDbObj *pDb = NULL; - if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); - - // todo db check should be extracted - if (pDb == NULL || (pDb != NULL && pDb->dropStatus != TSDB_DB_STATUS_READY)) { - - if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - pRsp->code = TSDB_CODE_INVALID_DB; - pMsg++; - - goto _exit_code; - } - - pMeterObj = mgmtGetTable(pInfo->meterId); - - // on demand create table from super table if meter does not exists - if (pMeterObj == NULL && pInfo->createFlag == 1) { - // write operation needs to redirect to master mnode - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_TABLE_META_RSP) != 0) { - return 0; - } - - SCreateTableMsg *pCreateMsg = calloc(1, sizeof(SCreateTableMsg) + sizeof(STagData)); - if (pCreateMsg == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - memcpy(pCreateMsg->schema, pInfo->tags, sizeof(STagData)); - strcpy(pCreateMsg->meterId, pInfo->meterId); - - SDbObj* pMeterDb = mgmtGetDbByMeterId(pCreateMsg->meterId); - mTrace("meter:%s, pConnDb:%p, pConnDbName:%s, pMeterDb:%p, pMeterDbName:%s", - pCreateMsg->meterId, pDb, pDb->name, pMeterDb, pMeterDb->name); - assert(pDb == pMeterDb); - - int32_t code = mgmtCreateTable(pDb, pCreateMsg); - - char stableName[TSDB_TABLE_ID_LEN] = {0}; - strncpy(stableName, pInfo->tags, TSDB_TABLE_ID_LEN); - mTrace("meter:%s is automatically created by %s from %s, code:%d", pCreateMsg->meterId, pConn->pUser->user, - stableName, code); - - tfree(pCreateMsg); - - if (code != TSDB_CODE_SUCCESS) { - if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - pRsp->code = code; - pMsg++; - - goto _exit_code; - } - - pMeterObj = mgmtGetTable(pInfo->meterId); - } - - if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - if (pMeterObj == NULL) { - if (pDb) - pRsp->code = TSDB_CODE_INVALID_TABLE; - else - pRsp->code = TSDB_CODE_DB_NOT_SELECTED; - pMsg++; - } else { - mTrace("%s, uid:%" PRIu64 " meter meta is retrieved", pInfo->meterId, pMeterObj->uid); - pRsp->code = 0; - pMsg += sizeof(STaosRsp); - *pMsg = TSDB_IE_TYPE_META; - pMsg++; - - pMeta = (SMeterMeta *)pMsg; - pMeta->uid = htobe64(pMeterObj->uid); - pMeta->sid = htonl(pMeterObj->gid.sid); - pMeta->vgid = htonl(pMeterObj->gid.vgId); - pMeta->sversion = htons(pMeterObj->sversion); - - pMeta->precision = pDb->cfg.precision; - - pMeta->numOfTags = pMeterObj->numOfTags; - pMeta->numOfColumns = htons(pMeterObj->numOfColumns); - pMeta->tableType = pMeterObj->tableType; - - pMsg += sizeof(SMeterMeta); - pSchema = (SSchema *)pMsg; // schema locates at the end of SMeterMeta struct - - if (mgmtTableCreateFromSuperTable(pMeterObj)) { - assert(pMeterObj->numOfTags == 0); - - STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData); - uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; - - pMeta->numOfTags = pMetric->numOfTags; // update the numOfTags info - mgmtSetSchemaFromMeters(pSchema, pMetric, numOfTotalCols); - pMsg += numOfTotalCols * sizeof(SSchema); - - // for meters created from metric, we need the metric tag schema to parse the tag data - int32_t tagsLen = mgmtSetMeterTagValue(pMsg, pMetric, pMeterObj); - pMsg += tagsLen; - } else { - /* - * for metrics, or meters that are not created from metric, set the schema directly - * for meters created from metric, we use the schema of metric instead - */ - uint32_t numOfTotalCols = (uint32_t)pMeterObj->numOfTags + pMeterObj->numOfColumns; - mgmtSetSchemaFromMeters(pSchema, pMeterObj, numOfTotalCols); - pMsg += numOfTotalCols * sizeof(SSchema); - } - - if (mgmtIsNormalTable(pMeterObj)) { - pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); - if (pVgroup == NULL) { - pRsp->code = TSDB_CODE_INVALID_TABLE; - goto _exit_code; - } - for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { - if (pConn->usePublicIp) { - pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; - pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); - } else { - pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; - pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); - } - } - } - } - -_exit_code: - msgLen = pMsg - pStart; - - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - return msgLen; +// SMeterInfoMsg *pInfo = (SMeterInfoMsg *)pMsg; +// STabObj * pMeterObj = NULL; +// SVgObj * pVgroup = NULL; +// SMeterMeta * pMeta = NULL; +// SSchema * pSchema = NULL; +// STaosRsp * pRsp = NULL; +// char * pStart = NULL; +// +// pInfo->createFlag = htons(pInfo->createFlag); +// +// int size = sizeof(STaosHeader) + sizeof(STaosRsp) + sizeof(SMeterMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS + +// sizeof(SSchema) * TSDB_MAX_TAGS + TSDB_MAX_TAGS_LEN + TSDB_EXTRA_PAYLOAD_SIZE; +// +// SDbObj *pDb = NULL; +// if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); +// +// // todo db check should be extracted +// if (pDb == NULL || (pDb != NULL && pDb->dropStatus != TSDB_DB_STATUS_READY)) { +// +// if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// pRsp->code = TSDB_CODE_INVALID_DB; +// pMsg++; +// +// goto _exit_code; +// } +// +// pMeterObj = mgmtGetTable(pInfo->meterId); +// +// // on demand create table from super table if meter does not exists +// if (pMeterObj == NULL && pInfo->createFlag == 1) { +// // write operation needs to redirect to master mnode +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_TABLE_META_RSP) != 0) { +// return 0; +// } +// +// SCreateTableMsg *pCreateMsg = calloc(1, sizeof(SCreateTableMsg) + sizeof(STagData)); +// if (pCreateMsg == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// memcpy(pCreateMsg->schema, pInfo->tags, sizeof(STagData)); +// strcpy(pCreateMsg->meterId, pInfo->meterId); +// +// SDbObj* pMeterDb = mgmtGetDbByMeterId(pCreateMsg->meterId); +// mTrace("meter:%s, pConnDb:%p, pConnDbName:%s, pMeterDb:%p, pMeterDbName:%s", +// pCreateMsg->meterId, pDb, pDb->name, pMeterDb, pMeterDb->name); +// assert(pDb == pMeterDb); +// +// int32_t code = mgmtCreateTable(pDb, pCreateMsg); +// +// char stableName[TSDB_TABLE_ID_LEN] = {0}; +// strncpy(stableName, pInfo->tags, TSDB_TABLE_ID_LEN); +// mTrace("meter:%s is automatically created by %s from %s, code:%d", pCreateMsg->meterId, pConn->pUser->user, +// stableName, code); +// +// tfree(pCreateMsg); +// +// if (code != TSDB_CODE_SUCCESS) { +// if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// pRsp->code = code; +// pMsg++; +// +// goto _exit_code; +// } +// +// pMeterObj = mgmtGetTable(pInfo->meterId); +// } +// +// if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// if (pMeterObj == NULL) { +// if (pDb) +// pRsp->code = TSDB_CODE_INVALID_TABLE; +// else +// pRsp->code = TSDB_CODE_DB_NOT_SELECTED; +// pMsg++; +// } else { +// mTrace("%s, uid:%" PRIu64 " meter meta is retrieved", pInfo->meterId, pMeterObj->uid); +// pRsp->code = 0; +// pMsg += sizeof(STaosRsp); +// *pMsg = TSDB_IE_TYPE_META; +// pMsg++; +// +// pMeta = (SMeterMeta *)pMsg; +// pMeta->uid = htobe64(pMeterObj->uid); +// pMeta->sid = htonl(pMeterObj->gid.sid); +// pMeta->vgid = htonl(pMeterObj->gid.vgId); +// pMeta->sversion = htons(pMeterObj->sversion); +// +// pMeta->precision = pDb->cfg.precision; +// +// pMeta->numOfTags = pMeterObj->numOfTags; +// pMeta->numOfColumns = htons(pMeterObj->numOfColumns); +// pMeta->tableType = pMeterObj->tableType; +// +// pMsg += sizeof(SMeterMeta); +// pSchema = (SSchema *)pMsg; // schema locates at the end of SMeterMeta struct +// +// if (mgmtTableCreateFromSuperTable(pMeterObj)) { +// assert(pMeterObj->numOfTags == 0); +// +// STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData); +// uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; +// +// pMeta->numOfTags = pMetric->numOfTags; // update the numOfTags info +// mgmtSetSchemaFromMeters(pSchema, pMetric, numOfTotalCols); +// pMsg += numOfTotalCols * sizeof(SSchema); +// +// // for meters created from metric, we need the metric tag schema to parse the tag data +// int32_t tagsLen = mgmtSetMeterTagValue(pMsg, pMetric, pMeterObj); +// pMsg += tagsLen; +// } else { +// /* +// * for metrics, or meters that are not created from metric, set the schema directly +// * for meters created from metric, we use the schema of metric instead +// */ +// uint32_t numOfTotalCols = (uint32_t)pMeterObj->numOfTags + pMeterObj->numOfColumns; +// mgmtSetSchemaFromMeters(pSchema, pMeterObj, numOfTotalCols); +// pMsg += numOfTotalCols * sizeof(SSchema); +// } +// +// if (mgmtIsNormalTable(pMeterObj)) { +// pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); +// if (pVgroup == NULL) { +// pRsp->code = TSDB_CODE_INVALID_TABLE; +// goto _exit_code; +// } +// for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { +// if (pConn->usePublicIp) { +// pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; +// pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); +// } else { +// pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; +// pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); +// } +// } +// } +// } +// +//_exit_code: +// msgLen = pMsg - pStart; +// +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// return msgLen; + return 0; } /** @@ -348,541 +353,544 @@ _exit_code: * pStart pCurMeter pTail **/ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SDbObj * pDbObj = NULL; - STabObj * pMeterObj = NULL; - SVgObj * pVgroup = NULL; - SMultiMeterMeta * pMeta = NULL; - SSchema * pSchema = NULL; - STaosRsp * pRsp = NULL; - char * pStart = NULL; - - SMultiMeterInfoMsg * pInfo = (SMultiMeterInfoMsg *)pMsg; - char * str = pMsg + sizeof(SMultiMeterInfoMsg); - pInfo->numOfMeters = htonl(pInfo->numOfMeters); - - int size = 4*1024*1024; // first malloc 4 MB, subsequent reallocation as twice - - char *pNewMsg; - if ((pStart = mgmtForMultiAllocMsg(pConn, size, &pNewMsg, &pRsp)) == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - int32_t totalNum = 0; - char tblName[TSDB_TABLE_ID_LEN]; - char* nextStr; - - char* pCurMeter = pStart + sizeof(STaosRsp) + sizeof(SMultiMeterInfoMsg) + 1; // 1: ie type byte - char* pTail = pStart + size; - - while (str - pMsg < msgLen) { - nextStr = strchr(str, ','); - if (nextStr == NULL) { - break; - } - - memcpy(tblName, str, nextStr - str); - tblName[nextStr - str] = '\0'; - str = nextStr + 1; - - // judge whether the remaining memory is adequate - if ((pTail - pCurMeter) < MAX_LEN_OF_METER_META) { - char* pMsgHdr = pStart - sizeof(STaosHeader); - size *= 2; - pMsgHdr = (char*)realloc(pMsgHdr, size); - if (NULL == pMsgHdr) { - char* pTmp = pStart - sizeof(STaosHeader); - tfree(pTmp); - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - break; - } - - pCurMeter = (char*)pMsgHdr + sizeof(STaosHeader) + (pCurMeter - pStart); - pStart = (char*)pMsgHdr + sizeof(STaosHeader); - pNewMsg = pStart; - pRsp = (STaosRsp *)pStart; - pTail = pMsgHdr + size; - } - - // get meter schema, and fill into resp payload - pMeterObj = mgmtGetTable(tblName); - pDbObj = mgmtGetDbByMeterId(tblName); - - if (pMeterObj == NULL || (pDbObj == NULL)) { - continue; - } else { - mTrace("%s, uid:%" PRIu64 " sversion:%d meter meta is retrieved", tblName, pMeterObj->uid, pMeterObj->sversion); - pMeta = (SMultiMeterMeta *)pCurMeter; - - memcpy(pMeta->meterId, tblName, strlen(tblName)); - pMeta->meta.uid = htobe64(pMeterObj->uid); - pMeta->meta.sid = htonl(pMeterObj->gid.sid); - pMeta->meta.vgid = htonl(pMeterObj->gid.vgId); - pMeta->meta.sversion = htons(pMeterObj->sversion); - pMeta->meta.precision = pDbObj->cfg.precision; - pMeta->meta.numOfTags = pMeterObj->numOfTags; - pMeta->meta.numOfColumns = htons(pMeterObj->numOfColumns); - pMeta->meta.tableType = pMeterObj->tableType; - - pCurMeter += sizeof(SMultiMeterMeta); - pSchema = (SSchema *)pCurMeter; // schema locates at the end of SMeterMeta struct - - if (mgmtTableCreateFromSuperTable(pMeterObj)) { - assert(pMeterObj->numOfTags == 0); - - STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData); - uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; - - pMeta->meta.numOfTags = pMetric->numOfTags; // update the numOfTags info - mgmtSetSchemaFromMeters(pSchema, pMetric, numOfTotalCols); - pCurMeter += numOfTotalCols * sizeof(SSchema); - - // for meters created from metric, we need the metric tag schema to parse the tag data - int32_t tagsLen = mgmtSetMeterTagValue(pCurMeter, pMetric, pMeterObj); - pCurMeter += tagsLen; - } else { - /* - * for metrics, or meters that are not created from metric, set the schema directly - * for meters created from metric, we use the schema of metric instead - */ - uint32_t numOfTotalCols = (uint32_t)pMeterObj->numOfTags + pMeterObj->numOfColumns; - mgmtSetSchemaFromMeters(pSchema, pMeterObj, numOfTotalCols); - pCurMeter += numOfTotalCols * sizeof(SSchema); - } - - if (mgmtIsNormalTable(pMeterObj)) { - pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); - if (pVgroup == NULL) { - pRsp->code = TSDB_CODE_INVALID_TABLE; - pNewMsg++; - mError("%s, uid:%" PRIu64 " sversion:%d vgId:%d pVgroup is NULL", tblName, pMeterObj->uid, pMeterObj->sversion, - pMeterObj->gid.vgId); - goto _error_exit_code; - } - - for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { - if (pConn->usePublicIp) { - pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; - pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); - } else { - pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; - pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); - } - } - } - } - - totalNum++; - if (totalNum > pInfo->numOfMeters) { - pNewMsg++; - break; - } - } - - // fill rsp code, ieType - msgLen = pCurMeter - pNewMsg; - - pRsp->code = 0; - pNewMsg += sizeof(STaosRsp); - *pNewMsg = TSDB_IE_TYPE_META; - pNewMsg++; - - SMultiMeterInfoMsg *pRspInfo = (SMultiMeterInfoMsg *)pNewMsg; - - pRspInfo->numOfMeters = htonl(totalNum); - goto _exit_code; - -_error_exit_code: - msgLen = pNewMsg - pStart; - -_exit_code: - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - return msgLen; +// SDbObj * pDbObj = NULL; +// STabObj * pMeterObj = NULL; +// SVgObj * pVgroup = NULL; +// SMultiMeterMeta * pMeta = NULL; +// SSchema * pSchema = NULL; +// STaosRsp * pRsp = NULL; +// char * pStart = NULL; +// +// SMultiMeterInfoMsg * pInfo = (SMultiMeterInfoMsg *)pMsg; +// char * str = pMsg + sizeof(SMultiMeterInfoMsg); +// pInfo->numOfMeters = htonl(pInfo->numOfMeters); +// +// int size = 4*1024*1024; // first malloc 4 MB, subsequent reallocation as twice +// +// char *pNewMsg; +// if ((pStart = mgmtForMultiAllocMsg(pConn, size, &pNewMsg, &pRsp)) == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// int32_t totalNum = 0; +// char tblName[TSDB_TABLE_ID_LEN]; +// char* nextStr; +// +// char* pCurMeter = pStart + sizeof(STaosRsp) + sizeof(SMultiMeterInfoMsg) + 1; // 1: ie type byte +// char* pTail = pStart + size; +// +// while (str - pMsg < msgLen) { +// nextStr = strchr(str, ','); +// if (nextStr == NULL) { +// break; +// } +// +// memcpy(tblName, str, nextStr - str); +// tblName[nextStr - str] = '\0'; +// str = nextStr + 1; +// +// // judge whether the remaining memory is adequate +// if ((pTail - pCurMeter) < MAX_LEN_OF_METER_META) { +// char* pMsgHdr = pStart - sizeof(STaosHeader); +// size *= 2; +// pMsgHdr = (char*)realloc(pMsgHdr, size); +// if (NULL == pMsgHdr) { +// char* pTmp = pStart - sizeof(STaosHeader); +// tfree(pTmp); +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_MULTI_TABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// break; +// } +// +// pCurMeter = (char*)pMsgHdr + sizeof(STaosHeader) + (pCurMeter - pStart); +// pStart = (char*)pMsgHdr + sizeof(STaosHeader); +// pNewMsg = pStart; +// pRsp = (STaosRsp *)pStart; +// pTail = pMsgHdr + size; +// } +// +// // get meter schema, and fill into resp payload +// pMeterObj = mgmtGetTable(tblName); +// pDbObj = mgmtGetDbByMeterId(tblName); +// +// if (pMeterObj == NULL || (pDbObj == NULL)) { +// continue; +// } else { +// mTrace("%s, uid:%" PRIu64 " sversion:%d meter meta is retrieved", tblName, pMeterObj->uid, pMeterObj->sversion); +// pMeta = (SMultiMeterMeta *)pCurMeter; +// +// memcpy(pMeta->meterId, tblName, strlen(tblName)); +// pMeta->meta.uid = htobe64(pMeterObj->uid); +// pMeta->meta.sid = htonl(pMeterObj->gid.sid); +// pMeta->meta.vgid = htonl(pMeterObj->gid.vgId); +// pMeta->meta.sversion = htons(pMeterObj->sversion); +// pMeta->meta.precision = pDbObj->cfg.precision; +// pMeta->meta.numOfTags = pMeterObj->numOfTags; +// pMeta->meta.numOfColumns = htons(pMeterObj->numOfColumns); +// pMeta->meta.tableType = pMeterObj->tableType; +// +// pCurMeter += sizeof(SMultiMeterMeta); +// pSchema = (SSchema *)pCurMeter; // schema locates at the end of SMeterMeta struct +// +// if (mgmtTableCreateFromSuperTable(pMeterObj)) { +// assert(pMeterObj->numOfTags == 0); +// +// STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData); +// uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; +// +// pMeta->meta.numOfTags = pMetric->numOfTags; // update the numOfTags info +// mgmtSetSchemaFromMeters(pSchema, pMetric, numOfTotalCols); +// pCurMeter += numOfTotalCols * sizeof(SSchema); +// +// // for meters created from metric, we need the metric tag schema to parse the tag data +// int32_t tagsLen = mgmtSetMeterTagValue(pCurMeter, pMetric, pMeterObj); +// pCurMeter += tagsLen; +// } else { +// /* +// * for metrics, or meters that are not created from metric, set the schema directly +// * for meters created from metric, we use the schema of metric instead +// */ +// uint32_t numOfTotalCols = (uint32_t)pMeterObj->numOfTags + pMeterObj->numOfColumns; +// mgmtSetSchemaFromMeters(pSchema, pMeterObj, numOfTotalCols); +// pCurMeter += numOfTotalCols * sizeof(SSchema); +// } +// +// if (mgmtIsNormalTable(pMeterObj)) { +// pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); +// if (pVgroup == NULL) { +// pRsp->code = TSDB_CODE_INVALID_TABLE; +// pNewMsg++; +// mError("%s, uid:%" PRIu64 " sversion:%d vgId:%d pVgroup is NULL", tblName, pMeterObj->uid, pMeterObj->sversion, +// pMeterObj->gid.vgId); +// goto _error_exit_code; +// } +// +// for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { +// if (pConn->usePublicIp) { +// pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; +// pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); +// } else { +// pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; +// pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); +// } +// } +// } +// } +// +// totalNum++; +// if (totalNum > pInfo->numOfMeters) { +// pNewMsg++; +// break; +// } +// } +// +// // fill rsp code, ieType +// msgLen = pCurMeter - pNewMsg; +// +// pRsp->code = 0; +// pNewMsg += sizeof(STaosRsp); +// *pNewMsg = TSDB_IE_TYPE_META; +// pNewMsg++; +// +// SMultiMeterInfoMsg *pRspInfo = (SMultiMeterInfoMsg *)pNewMsg; +// +// pRspInfo->numOfMeters = htonl(totalNum); +// goto _exit_code; +// +//_error_exit_code: +// msgLen = pNewMsg - pStart; +// +//_exit_code: +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// return msgLen; + return 0; } int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SSuperTableMetaMsg *pSuperTableMetaMsg = (SSuperTableMetaMsg *)pMsg; - STabObj * pMetric; - STaosRsp * pRsp; - char * pStart; - - pSuperTableMetaMsg->numOfMeters = htonl(pSuperTableMetaMsg->numOfMeters); - - pSuperTableMetaMsg->join = htonl(pSuperTableMetaMsg->join); - pSuperTableMetaMsg->joinCondLen = htonl(pSuperTableMetaMsg->joinCondLen); - - for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) { - pSuperTableMetaMsg->metaElem[i] = htonl(pSuperTableMetaMsg->metaElem[i]); - } - - SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)(((char *)pSuperTableMetaMsg) + pSuperTableMetaMsg->metaElem[0]); - pMetric = mgmtGetTable(pElem->meterId); - - SDbObj *pDb = NULL; - if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); - - if (pMetric == NULL || (pDb != NULL && pDb->dropStatus != TSDB_DB_STATUS_READY)) { - pStart = taosBuildRspMsg(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP); - if (pStart == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - pMsg = pStart; - pRsp = (STaosRsp *)pMsg; - if (pDb) - pRsp->code = TSDB_CODE_INVALID_TABLE; - else - pRsp->code = TSDB_CODE_DB_NOT_SELECTED; - pMsg++; - - msgLen = pMsg - pStart; - } else { - msgLen = mgmtRetrieveMetricMeta(pConn, &pStart, pSuperTableMetaMsg); - if (msgLen <= 0) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - } - - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - return msgLen; +// SSuperTableMetaMsg *pSuperTableMetaMsg = (SSuperTableMetaMsg *)pMsg; +// STabObj * pMetric; +// STaosRsp * pRsp; +// char * pStart; +// +// pSuperTableMetaMsg->numOfMeters = htonl(pSuperTableMetaMsg->numOfMeters); +// +// pSuperTableMetaMsg->join = htonl(pSuperTableMetaMsg->join); +// pSuperTableMetaMsg->joinCondLen = htonl(pSuperTableMetaMsg->joinCondLen); +// +// for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) { +// pSuperTableMetaMsg->metaElem[i] = htonl(pSuperTableMetaMsg->metaElem[i]); +// } +// +// SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)(((char *)pSuperTableMetaMsg) + pSuperTableMetaMsg->metaElem[0]); +// pMetric = mgmtGetTable(pElem->meterId); +// +// SDbObj *pDb = NULL; +// if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); +// +// if (pMetric == NULL || (pDb != NULL && pDb->dropStatus != TSDB_DB_STATUS_READY)) { +// pStart = taosBuildRspMsg(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP); +// if (pStart == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// pMsg = pStart; +// pRsp = (STaosRsp *)pMsg; +// if (pDb) +// pRsp->code = TSDB_CODE_INVALID_TABLE; +// else +// pRsp->code = TSDB_CODE_DB_NOT_SELECTED; +// pMsg++; +// +// msgLen = pMsg - pStart; +// } else { +// msgLen = mgmtRetrieveMetricMeta(pConn, &pStart, pSuperTableMetaMsg); +// if (msgLen <= 0) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_STABLE_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// } +// +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// return msgLen; + return 0; } int mgmtProcessCreateDbMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SCreateDbMsg *pCreate = (SCreateDbMsg *)pMsg; - int code = 0; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_DB_RSP) != 0) { - return 0; - } - - pCreate->maxSessions = htonl(pCreate->maxSessions); - pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize); - // pCreate->cacheNumOfBlocks = htonl(pCreate->cacheNumOfBlocks); - pCreate->daysPerFile = htonl(pCreate->daysPerFile); - pCreate->daysToKeep = htonl(pCreate->daysToKeep); - pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); - pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); - pCreate->commitTime = htonl(pCreate->commitTime); - pCreate->blocksPerMeter = htons(pCreate->blocksPerMeter); - pCreate->rowsInFileBlock = htonl(pCreate->rowsInFileBlock); - - if (mgmtCheckExpired()) { - code = TSDB_CODE_GRANT_EXPIRED; - } else if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtCreateDb(pConn->pAcct, pCreate); - if (code == TSDB_CODE_SUCCESS) { - mLPrint("DB:%s is created by %s", pCreate->db, pConn->pUser->user); - } - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DB_RSP, code); +// SCreateDbMsg *pCreate = (SCreateDbMsg *)pMsg; +// int code = 0; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_DB_RSP) != 0) { +// return 0; +// } +// +// pCreate->maxSessions = htonl(pCreate->maxSessions); +// pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize); +// // pCreate->cacheNumOfBlocks = htonl(pCreate->cacheNumOfBlocks); +// pCreate->daysPerFile = htonl(pCreate->daysPerFile); +// pCreate->daysToKeep = htonl(pCreate->daysToKeep); +// pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); +// pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); +// pCreate->commitTime = htonl(pCreate->commitTime); +// pCreate->blocksPerMeter = htons(pCreate->blocksPerMeter); +// pCreate->rowsInFileBlock = htonl(pCreate->rowsInFileBlock); +// +// if (mgmtCheckExpired()) { +// code = TSDB_CODE_GRANT_EXPIRED; +// } else if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtCreateDb(pConn->pAcct, pCreate); +// if (code == TSDB_CODE_SUCCESS) { +// mLPrint("DB:%s is created by %s", pCreate->db, pConn->pUser->user); +// } +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DB_RSP, code); return 0; } int mgmtProcessCreateMnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); +// return rpcSendResponse(pConn->thandle, TSDB_MSG_TYPE_CREATE_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int mgmtProcessAlterDbMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SAlterDbMsg *pAlter = (SAlterDbMsg *)pMsg; - int code = 0; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_DB_RSP) != 0) { - return 0; - } - - pAlter->daysPerFile = htonl(pAlter->daysPerFile); - pAlter->daysToKeep = htonl(pAlter->daysToKeep); - pAlter->maxSessions = htonl(pAlter->maxSessions) + 1; - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtAlterDb(pConn->pAcct, pAlter); - if (code == TSDB_CODE_SUCCESS) { - mLPrint("DB:%s is altered by %s", pAlter->db, pConn->pUser->user); - } - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_DB_RSP, code); +// SAlterDbMsg *pAlter = (SAlterDbMsg *)pMsg; +// int code = 0; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_DB_RSP) != 0) { +// return 0; +// } +// +// pAlter->daysPerFile = htonl(pAlter->daysPerFile); +// pAlter->daysToKeep = htonl(pAlter->daysToKeep); +// pAlter->maxSessions = htonl(pAlter->maxSessions) + 1; +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtAlterDb(pConn->pAcct, pAlter); +// if (code == TSDB_CODE_SUCCESS) { +// mLPrint("DB:%s is altered by %s", pAlter->db, pConn->pUser->user); +// } +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_DB_RSP, code); return 0; } int mgmtProcessKillQueryMsg(char *pMsg, int msgLen, SConnObj *pConn) { - int code = 0; - SKillQuery *pKill = (SKillQuery *)pMsg; - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtKillQuery(pKill->queryId, pConn); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_QUERY_RSP, code); +// int code = 0; +// SKillQuery *pKill = (SKillQuery *)pMsg; +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtKillQuery(pKill->queryId, pConn); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_QUERY_RSP, code); return 0; } int mgmtProcessKillStreamMsg(char *pMsg, int msgLen, SConnObj *pConn) { - int code = 0; - SKillStream *pKill = (SKillStream *)pMsg; - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtKillStream(pKill->queryId, pConn); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_STREAM_RSP, code); +// int code = 0; +// SKillStream *pKill = (SKillStream *)pMsg; +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtKillStream(pKill->queryId, pConn); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_STREAM_RSP, code); return 0; } int mgmtProcessKillConnectionMsg(char *pMsg, int msgLen, SConnObj *pConn) { - int code = 0; - SKillConnection *pKill = (SKillConnection *)pMsg; - - if (!pConn->superAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtKillConnection(pKill->queryId, pConn); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_CONNECTION_RSP, code); +// int code = 0; +// SKillConnection *pKill = (SKillConnection *)pMsg; +// +// if (!pConn->superAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtKillConnection(pKill->queryId, pConn); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_KILL_CONNECTION_RSP, code); return 0; } int mgmtProcessCreateUserMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SCreateUserMsg *pCreate = (SCreateUserMsg *)pMsg; - int code = 0; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_USER_RSP) != 0) { - return 0; - } - - if (pConn->superAuth) { - code = mgmtCreateUser(pConn->pAcct, pCreate->user, pCreate->pass); - if (code == TSDB_CODE_SUCCESS) { - mLPrint("user:%s is created by %s", pCreate->user, pConn->pUser->user); - } - } else { - code = TSDB_CODE_NO_RIGHTS; - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_USER_RSP, code); +// SCreateUserMsg *pCreate = (SCreateUserMsg *)pMsg; +// int code = 0; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_USER_RSP) != 0) { +// return 0; +// } +// +// if (pConn->superAuth) { +// code = mgmtCreateUser(pConn->pAcct, pCreate->user, pCreate->pass); +// if (code == TSDB_CODE_SUCCESS) { +// mLPrint("user:%s is created by %s", pCreate->user, pConn->pUser->user); +// } +// } else { +// code = TSDB_CODE_NO_RIGHTS; +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_USER_RSP, code); return 0; } int mgmtProcessAlterUserMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SAlterUserMsg *pAlter = (SAlterUserMsg *)pMsg; - int code = 0; - SUserObj * pUser; - SUserObj * pOperUser; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_USER_RSP) != 0) { - return 0; - } - - pUser = mgmtGetUser(pAlter->user); - pOperUser = mgmtGetUser(pConn->pUser->user); - - if (pUser == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, TSDB_CODE_INVALID_USER); - return 0; - } - - if (pOperUser == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, TSDB_CODE_INVALID_USER); - return 0; - } - - if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { - code = TSDB_CODE_NO_RIGHTS; - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); - return 0; - } - - if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { - bool hasRight = false; - if (strcmp(pOperUser->user, "root") == 0) { - hasRight = true; - } else if (strcmp(pUser->user, pOperUser->user) == 0) { - hasRight = true; - } else if (pOperUser->superAuth) { - if (strcmp(pUser->user, "root") == 0) { - hasRight = false; - } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { - hasRight = false; - } else { - hasRight = true; - } - } - - if (hasRight) { - memset(pUser->pass, 0, sizeof(pUser->pass)); - taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass); - code = mgmtUpdateUser(pUser); - mLPrint("user:%s password is altered by %s, code:%d", pAlter->user, pConn->pUser->user, code); - } else { - code = TSDB_CODE_NO_RIGHTS; - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); - return 0; - } - - if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { - bool hasRight = false; - - if (strcmp(pUser->user, "root") == 0) { - hasRight = false; - } else if (strcmp(pUser->user, pUser->acct) == 0) { - hasRight = false; - } else if (strcmp(pOperUser->user, "root") == 0) { - hasRight = true; - } else if (strcmp(pUser->user, pOperUser->user) == 0) { - hasRight = false; - } else if (pOperUser->superAuth) { - if (strcmp(pUser->user, "root") == 0) { - hasRight = false; - } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { - hasRight = false; - } else { - hasRight = true; - } - } - - if (pAlter->privilege == 1) { // super - hasRight = false; - } - - if (hasRight) { - //if (pAlter->privilege == 1) { // super - // pUser->superAuth = 1; - // pUser->writeAuth = 1; - //} - if (pAlter->privilege == 2) { // read - pUser->superAuth = 0; - pUser->writeAuth = 0; - } - if (pAlter->privilege == 3) { // write - pUser->superAuth = 0; - pUser->writeAuth = 1; - } - - code = mgmtUpdateUser(pUser); - mLPrint("user:%s privilege is altered by %s, code:%d", pAlter->user, pConn->pUser->user, code); - } else { - code = TSDB_CODE_NO_RIGHTS; - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); - return 0; - } - - code = TSDB_CODE_NO_RIGHTS; - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); +// SAlterUserMsg *pAlter = (SAlterUserMsg *)pMsg; +// int code = 0; +// SUserObj * pUser; +// SUserObj * pOperUser; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_USER_RSP) != 0) { +// return 0; +// } +// +// pUser = mgmtGetUser(pAlter->user); +// pOperUser = mgmtGetUser(pConn->pUser->user); +// +// if (pUser == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, TSDB_CODE_INVALID_USER); +// return 0; +// } +// +// if (pOperUser == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, TSDB_CODE_INVALID_USER); +// return 0; +// } +// +// if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { +// code = TSDB_CODE_NO_RIGHTS; +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); +// return 0; +// } +// +// if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { +// bool hasRight = false; +// if (strcmp(pOperUser->user, "root") == 0) { +// hasRight = true; +// } else if (strcmp(pUser->user, pOperUser->user) == 0) { +// hasRight = true; +// } else if (pOperUser->superAuth) { +// if (strcmp(pUser->user, "root") == 0) { +// hasRight = false; +// } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { +// hasRight = false; +// } else { +// hasRight = true; +// } +// } +// +// if (hasRight) { +// memset(pUser->pass, 0, sizeof(pUser->pass)); +// taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass); +// code = mgmtUpdateUser(pUser); +// mLPrint("user:%s password is altered by %s, code:%d", pAlter->user, pConn->pUser->user, code); +// } else { +// code = TSDB_CODE_NO_RIGHTS; +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); +// return 0; +// } +// +// if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { +// bool hasRight = false; +// +// if (strcmp(pUser->user, "root") == 0) { +// hasRight = false; +// } else if (strcmp(pUser->user, pUser->acct) == 0) { +// hasRight = false; +// } else if (strcmp(pOperUser->user, "root") == 0) { +// hasRight = true; +// } else if (strcmp(pUser->user, pOperUser->user) == 0) { +// hasRight = false; +// } else if (pOperUser->superAuth) { +// if (strcmp(pUser->user, "root") == 0) { +// hasRight = false; +// } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { +// hasRight = false; +// } else { +// hasRight = true; +// } +// } +// +// if (pAlter->privilege == 1) { // super +// hasRight = false; +// } +// +// if (hasRight) { +// //if (pAlter->privilege == 1) { // super +// // pUser->superAuth = 1; +// // pUser->writeAuth = 1; +// //} +// if (pAlter->privilege == 2) { // read +// pUser->superAuth = 0; +// pUser->writeAuth = 0; +// } +// if (pAlter->privilege == 3) { // write +// pUser->superAuth = 0; +// pUser->writeAuth = 1; +// } +// +// code = mgmtUpdateUser(pUser); +// mLPrint("user:%s privilege is altered by %s, code:%d", pAlter->user, pConn->pUser->user, code); +// } else { +// code = TSDB_CODE_NO_RIGHTS; +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); +// return 0; +// } +// +// code = TSDB_CODE_NO_RIGHTS; +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_USER_RSP, code); return 0; } int mgmtProcessDropUserMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SDropUserMsg *pDrop = (SDropUserMsg *)pMsg; - int code = 0; - SUserObj * pUser; - SUserObj * pOperUser; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_USER_RSP) != 0) { - return 0; - } - - pUser = mgmtGetUser(pDrop->user); - pOperUser = mgmtGetUser(pConn->pUser->user); - - if (pUser == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, TSDB_CODE_INVALID_USER); - return 0; - } - - if (pOperUser == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, TSDB_CODE_INVALID_USER); - return 0; - } - - if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { - code = TSDB_CODE_NO_RIGHTS; - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, code); - return 0; - } - - bool hasRight = false; - if (strcmp(pUser->user, "root") == 0) { - hasRight = false; - } else if (strcmp(pOperUser->user, "root") == 0) { - hasRight = true; - } else if (strcmp(pUser->user, pOperUser->user) == 0) { - hasRight = false; - } else if (pOperUser->superAuth) { - if (strcmp(pUser->user, "root") == 0) { - hasRight = false; - } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { - hasRight = false; - } else { - hasRight = true; - } - } - - if (hasRight) { - code = mgmtDropUser(pConn->pAcct, pDrop->user); - if (code == 0) { - mLPrint("user:%s is dropped by %s", pDrop->user, pConn->pUser->user); - } - } else { - code = TSDB_CODE_NO_RIGHTS; - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, code); +// SDropUserMsg *pDrop = (SDropUserMsg *)pMsg; +// int code = 0; +// SUserObj * pUser; +// SUserObj * pOperUser; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_USER_RSP) != 0) { +// return 0; +// } +// +// pUser = mgmtGetUser(pDrop->user); +// pOperUser = mgmtGetUser(pConn->pUser->user); +// +// if (pUser == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, TSDB_CODE_INVALID_USER); +// return 0; +// } +// +// if (pOperUser == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, TSDB_CODE_INVALID_USER); +// return 0; +// } +// +// if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { +// code = TSDB_CODE_NO_RIGHTS; +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, code); +// return 0; +// } +// +// bool hasRight = false; +// if (strcmp(pUser->user, "root") == 0) { +// hasRight = false; +// } else if (strcmp(pOperUser->user, "root") == 0) { +// hasRight = true; +// } else if (strcmp(pUser->user, pOperUser->user) == 0) { +// hasRight = false; +// } else if (pOperUser->superAuth) { +// if (strcmp(pUser->user, "root") == 0) { +// hasRight = false; +// } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { +// hasRight = false; +// } else { +// hasRight = true; +// } +// } +// +// if (hasRight) { +// code = mgmtDropUser(pConn->pAcct, pDrop->user); +// if (code == 0) { +// mLPrint("user:%s is dropped by %s", pDrop->user, pConn->pUser->user); +// } +// } else { +// code = TSDB_CODE_NO_RIGHTS; +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_USER_RSP, code); return 0; } int mgmtProcessDropDbMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SDropDbMsg *pDrop = (SDropDbMsg *)pMsg; - int code; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_DB_RSP) != 0) { - return 0; - } - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtDropDbByName(pConn->pAcct, pDrop->db, pDrop->ignoreNotExists); - if (code == 0) { - mLPrint("DB:%s is dropped by %s", pDrop->db, pConn->pUser->user); - } - } - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DB_RSP, code); +// SDropDbMsg *pDrop = (SDropDbMsg *)pMsg; +// int code; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_DB_RSP) != 0) { +// return 0; +// } +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtDropDbByName(pConn->pAcct, pDrop->db, pDrop->ignoreNotExists); +// if (code == 0) { +// mLPrint("DB:%s is dropped by %s", pDrop->db, pConn->pUser->user); +// } +// } +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DB_RSP, code); return 0; } int mgmtProcessUseDbMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SUseDbMsg *pUse = (SUseDbMsg *)pMsg; - int code; - - code = mgmtUseDb(pConn, pUse->db); - if (code == 0) mTrace("DB is change to:%s by %s", pUse->db, pConn->pUser->user); - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_USE_DB_RSP, code); +// SUseDbMsg *pUse = (SUseDbMsg *)pMsg; +// int code; +// +// code = mgmtUseDb(pConn, pUse->db); +// if (code == 0) mTrace("DB is change to:%s by %s", pUse->db, pConn->pUser->user); +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_USE_DB_RSP, code); return 0; } @@ -926,364 +934,366 @@ static void mgmtInitShowMsgFp() { } int mgmtProcessShowMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SShowMsg * pShowMsg = (SShowMsg *)pMsg; - STaosRsp * pRsp; - char * pStart; - int code = 0; - SShowRspMsg *pShowRsp; - SShowObj * pShow = NULL; - - if (pShowMsg->type == TSDB_MGMT_TABLE_DNODE || TSDB_MGMT_TABLE_GRANTS || TSDB_MGMT_TABLE_SCORES) { - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_SHOW_RSP) != 0) { - return 0; - } - } - - int size = sizeof(STaosHeader) + sizeof(STaosRsp) + sizeof(SShowRspMsg) + sizeof(SSchema) * TSDB_MAX_COLUMNS + - TSDB_EXTRA_PAYLOAD_SIZE; - pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_SHOW_RSP, size); - if (pStart == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_SHOW_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - pMsg = pStart; - pRsp = (STaosRsp *)pMsg; - pMsg = (char *)pRsp->more; - - if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) { - code = -1; - } else { - pShow = (SShowObj *)calloc(1, sizeof(SShowObj) + htons(pShowMsg->payloadLen)); - pShow->signature = pShow; - pShow->type = pShowMsg->type; - mTrace("pShow:%p is allocated", pShow); - - // set the table name query condition - pShow->payloadLen = htons(pShowMsg->payloadLen); - memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen); - - pShowRsp = (SShowRspMsg *)pMsg; - pShowRsp->qhandle = (uint64_t)pShow; // qhandle; - pConn->qhandle = pShowRsp->qhandle; - - code = (*mgmtGetMetaFp[(uint8_t)pShowMsg->type])(&pShowRsp->meterMeta, pShow, pConn); - if (code == 0) { - pMsg += sizeof(SShowRspMsg) + sizeof(SSchema) * pShow->numOfColumns; - } else { - mError("pShow:%p, type:%d %s, failed to get Meta, code:%d", pShow, pShowMsg->type, taosMsg[(uint8_t)pShowMsg->type], code); - free(pShow); - } - } - - pRsp->code = code; - msgLen = pMsg - pStart; - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - return msgLen; +// SShowMsg * pShowMsg = (SShowMsg *)pMsg; +// STaosRsp * pRsp; +// char * pStart; +// int code = 0; +// SShowRspMsg *pShowRsp; +// SShowObj * pShow = NULL; +// +// if (pShowMsg->type == TSDB_MGMT_TABLE_DNODE || TSDB_MGMT_TABLE_GRANTS || TSDB_MGMT_TABLE_SCORES) { +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_SHOW_RSP) != 0) { +// return 0; +// } +// } +// +// int size = sizeof(STaosHeader) + sizeof(STaosRsp) + sizeof(SShowRspMsg) + sizeof(SSchema) * TSDB_MAX_COLUMNS + +// TSDB_EXTRA_PAYLOAD_SIZE; +// pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_SHOW_RSP, size); +// if (pStart == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_SHOW_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// pMsg = pStart; +// pRsp = (STaosRsp *)pMsg; +// pMsg = (char *)pRsp->more; +// +// if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) { +// code = -1; +// } else { +// pShow = (SShowObj *)calloc(1, sizeof(SShowObj) + htons(pShowMsg->payloadLen)); +// pShow->signature = pShow; +// pShow->type = pShowMsg->type; +// mTrace("pShow:%p is allocated", pShow); +// +// // set the table name query condition +// pShow->payloadLen = htons(pShowMsg->payloadLen); +// memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen); +// +// pShowRsp = (SShowRspMsg *)pMsg; +// pShowRsp->qhandle = (uint64_t)pShow; // qhandle; +// pConn->qhandle = pShowRsp->qhandle; +// +// code = (*mgmtGetMetaFp[(uint8_t)pShowMsg->type])(&pShowRsp->meterMeta, pShow, pConn); +// if (code == 0) { +// pMsg += sizeof(SShowRspMsg) + sizeof(SSchema) * pShow->numOfColumns; +// } else { +// mError("pShow:%p, type:%d %s, failed to get Meta, code:%d", pShow, pShowMsg->type, taosMsg[(uint8_t)pShowMsg->type], code); +// free(pShow); +// } +// } +// +// pRsp->code = code; +// msgLen = pMsg - pStart; +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// return msgLen; + return 0; } int mgmtProcessRetrieveMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SRetrieveMeterMsg *pRetrieve; - SRetrieveMeterRsp *pRsp; - int rowsToRead = 0, size = 0, rowsRead = 0; - char * pStart; - int code = 0; - SShowObj * pShow; - - pRetrieve = (SRetrieveMeterMsg *)pMsg; - - /* - * in case of server restart, apps may hold qhandle created by server before - * restart, which is actually invalid, therefore, signature check is required. - */ - if (pRetrieve->qhandle != pConn->qhandle) { - mError("retrieve:%p, qhandle:%p is not matched with saved:%p", pRetrieve, pRetrieve->qhandle, pConn->qhandle); - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_MEMORY_CORRUPTED); - return -1; - } - - pShow = (SShowObj *)pRetrieve->qhandle; - if (pShow->signature != (void *)pShow) { - mError("pShow:%p, signature:%p, query memory is corrupted", pShow, pShow->signature); - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_MEMORY_CORRUPTED); - return -1; - } else { - if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsToRead = pShow->numOfRows - pShow->numOfReads; - } - - /* return no more than 100 meters in one round trip */ - if (rowsToRead > 100) rowsToRead = 100; - - /* - * the actual number of table may be larger than the value of pShow->numOfRows, if a query is - * issued during a continuous create table operation. Therefore, rowToRead may be less than 0. - */ - if (rowsToRead < 0) rowsToRead = 0; - size = pShow->rowSize * rowsToRead; - } - - pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, size + 100); - if (pStart == NULL) { - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); - return 0; - } - - pMsg = pStart; - - STaosRsp *pTaosRsp = (STaosRsp *)pStart; - pTaosRsp->code = code; - pMsg = pTaosRsp->more; - - if (code == 0) { - pRsp = (SRetrieveMeterRsp *)pMsg; - pMsg = pRsp->data; - - // if free flag is set, client wants to clean the resources - if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) - rowsRead = (*mgmtRetrieveFp[(uint8_t)pShow->type])(pShow, pRsp->data, rowsToRead, pConn); - - if (rowsRead < 0) { - rowsRead = 0; - pTaosRsp->code = TSDB_CODE_ACTION_IN_PROGRESS; - } - - pRsp->numOfRows = htonl(rowsRead); - pRsp->precision = htonl(TSDB_TIME_PRECISION_MILLI); // millisecond time precision - pMsg += size; - } - - msgLen = pMsg - pStart; - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - if (rowsToRead == 0) { - uintptr_t oldSign = (uintptr_t)atomic_val_compare_exchange_ptr(&pShow->signature, pShow, 0); - if (oldSign != (uintptr_t)pShow) { - return msgLen; - } - // pShow->signature = 0; - mTrace("pShow:%p is released", pShow); - tfree(pShow); - } - - return msgLen; +// SRetrieveMeterMsg *pRetrieve; +// SRetrieveMeterRsp *pRsp; +// int rowsToRead = 0, size = 0, rowsRead = 0; +// char * pStart; +// int code = 0; +// SShowObj * pShow; +// +// pRetrieve = (SRetrieveMeterMsg *)pMsg; +// +// /* +// * in case of server restart, apps may hold qhandle created by server before +// * restart, which is actually invalid, therefore, signature check is required. +// */ +// if (pRetrieve->qhandle != pConn->qhandle) { +// mError("retrieve:%p, qhandle:%p is not matched with saved:%p", pRetrieve, pRetrieve->qhandle, pConn->qhandle); +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_MEMORY_CORRUPTED); +// return -1; +// } +// +// pShow = (SShowObj *)pRetrieve->qhandle; +// if (pShow->signature != (void *)pShow) { +// mError("pShow:%p, signature:%p, query memory is corrupted", pShow, pShow->signature); +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_MEMORY_CORRUPTED); +// return -1; +// } else { +// if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { +// rowsToRead = pShow->numOfRows - pShow->numOfReads; +// } +// +// /* return no more than 100 meters in one round trip */ +// if (rowsToRead > 100) rowsToRead = 100; +// +// /* +// * the actual number of table may be larger than the value of pShow->numOfRows, if a query is +// * issued during a continuous create table operation. Therefore, rowToRead may be less than 0. +// */ +// if (rowsToRead < 0) rowsToRead = 0; +// size = pShow->rowSize * rowsToRead; +// } +// +// pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, size + 100); +// if (pStart == NULL) { +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_RETRIEVE_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); +// return 0; +// } +// +// pMsg = pStart; +// +// STaosRsp *pTaosRsp = (STaosRsp *)pStart; +// pTaosRsp->code = code; +// pMsg = pTaosRsp->more; +// +// if (code == 0) { +// pRsp = (SRetrieveMeterRsp *)pMsg; +// pMsg = pRsp->data; +// +// // if free flag is set, client wants to clean the resources +// if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) +// rowsRead = (*mgmtRetrieveFp[(uint8_t)pShow->type])(pShow, pRsp->data, rowsToRead, pConn); +// +// if (rowsRead < 0) { +// rowsRead = 0; +// pTaosRsp->code = TSDB_CODE_ACTION_IN_PROGRESS; +// } +// +// pRsp->numOfRows = htonl(rowsRead); +// pRsp->precision = htonl(TSDB_TIME_PRECISION_MILLI); // millisecond time precision +// pMsg += size; +// } +// +// msgLen = pMsg - pStart; +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// if (rowsToRead == 0) { +// uintptr_t oldSign = (uintptr_t)atomic_val_compare_exchange_ptr(&pShow->signature, pShow, 0); +// if (oldSign != (uintptr_t)pShow) { +// return msgLen; +// } +// // pShow->signature = 0; +// mTrace("pShow:%p is released", pShow); +// tfree(pShow); +// } +// +// return msgLen; + return 0; } int mgmtProcessCreateTableMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SCreateTableMsg *pCreate = (SCreateTableMsg *)pMsg; - int code; - SSchema * pSchema; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_TABLE_RSP) != 0) { - return 0; - } - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - pCreate->numOfColumns = htons(pCreate->numOfColumns); - pCreate->numOfTags = htons(pCreate->numOfTags); - - pCreate->sqlLen = htons(pCreate->sqlLen); - pSchema = pCreate->schema; - for (int i = 0; i < pCreate->numOfColumns + pCreate->numOfTags; ++i) { - pSchema->bytes = htons(pSchema->bytes); - pSchema->colId = i; - pSchema++; - } - - SDbObj *pDb = NULL; - if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); - - if (pDb) { - code = mgmtCreateTable(pDb, pCreate); - } else { - code = TSDB_CODE_DB_NOT_SELECTED; - } - } - - if (code == 1) { - //mTrace("table:%s, wait vgroup create finish", pCreate->meterId, code); - } else if (code != TSDB_CODE_SUCCESS) { - if (code == TSDB_CODE_TABLE_ALREADY_EXIST) { // table already created when the second attempt to create table - - STabObj* pTable = mgmtGetTable(pCreate->meterId); - assert(pTable != NULL); - - mWarn("table:%s, table already created, failed to create table, ts:%" PRId64 ", code:%d", pCreate->meterId, - pTable->createdTime, code); - } else { // other errors - mError("table:%s, failed to create table, code:%d", pCreate->meterId, code); - } - } else { - mTrace("table:%s, table is created by %s", pCreate->meterId, pConn->pUser->user); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_TABLE_RSP, code); +// SCreateTableMsg *pCreate = (SCreateTableMsg *)pMsg; +// int code; +// SSchema * pSchema; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_TABLE_RSP) != 0) { +// return 0; +// } +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// pCreate->numOfColumns = htons(pCreate->numOfColumns); +// pCreate->numOfTags = htons(pCreate->numOfTags); +// +// pCreate->sqlLen = htons(pCreate->sqlLen); +// pSchema = pCreate->schema; +// for (int i = 0; i < pCreate->numOfColumns + pCreate->numOfTags; ++i) { +// pSchema->bytes = htons(pSchema->bytes); +// pSchema->colId = i; +// pSchema++; +// } +// +// SDbObj *pDb = NULL; +// if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); +// +// if (pDb) { +// code = mgmtCreateTable(pDb, pCreate); +// } else { +// code = TSDB_CODE_DB_NOT_SELECTED; +// } +// } +// +// if (code == 1) { +// //mTrace("table:%s, wait vgroup create finish", pCreate->meterId, code); +// } else if (code != TSDB_CODE_SUCCESS) { +// if (code == TSDB_CODE_TABLE_ALREADY_EXIST) { // table already created when the second attempt to create table +// +// STabObj* pTable = mgmtGetTable(pCreate->meterId); +// assert(pTable != NULL); +// +// mWarn("table:%s, table already created, failed to create table, ts:%" PRId64 ", code:%d", pCreate->meterId, +// pTable->createdTime, code); +// } else { // other errors +// mError("table:%s, failed to create table, code:%d", pCreate->meterId, code); +// } +// } else { +// mTrace("table:%s, table is created by %s", pCreate->meterId, pConn->pUser->user); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_TABLE_RSP, code); return 0; } int mgmtProcessDropTableMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SDropTableMsg *pDrop = (SDropTableMsg *)pMsg; - int code; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_TABLE_RSP) != 0) { - return 0; - } - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - SDbObj *pDb = NULL; - if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); - - code = mgmtDropTable(pDb, pDrop->meterId, pDrop->igNotExists); - if (code == 0) { - mTrace("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user); - // mLPrint("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_TABLE_RSP, code); - } +// SDropTableMsg *pDrop = (SDropTableMsg *)pMsg; +// int code; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_DROP_TABLE_RSP) != 0) { +// return 0; +// } +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// SDbObj *pDb = NULL; +// if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); +// +// code = mgmtDropTable(pDb, pDrop->meterId, pDrop->igNotExists); +// if (code == 0) { +// mTrace("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user); +// // mLPrint("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_TABLE_RSP, code); +// } return 0; } int mgmtProcessAlterTableMsg(char *pMsg, int msgLen, SConnObj *pConn) { - SAlterTableMsg *pAlter = (SAlterTableMsg *)pMsg; - int code; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_TABLE_RSP) != 0) { - return 0; - } - - if (!pConn->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; - } else { - pAlter->type = htons(pAlter->type); - pAlter->numOfCols = htons(pAlter->numOfCols); - - if (pAlter->numOfCols > 2) { - mError("meter:%s error numOfCols:%d in alter table", pAlter->meterId, pAlter->numOfCols); - code = TSDB_CODE_APP_ERROR; - } else { - SDbObj *pDb = NULL; - if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); - - if (pDb) { - for (int32_t i = 0; i < pAlter->numOfCols; ++i) { - pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes); - } - - code = mgmtAlterTable(pDb, pAlter); - if (code == 0) { - mLPrint("meter:%s is altered by %s", pAlter->meterId, pConn->pUser->user); - } - } else { - code = TSDB_CODE_DB_NOT_SELECTED; - } - } - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_TABLE_RSP, code); +// SAlterTableMsg *pAlter = (SAlterTableMsg *)pMsg; +// int code; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_ALTER_TABLE_RSP) != 0) { +// return 0; +// } +// +// if (!pConn->writeAuth) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// pAlter->type = htons(pAlter->type); +// pAlter->numOfCols = htons(pAlter->numOfCols); +// +// if (pAlter->numOfCols > 2) { +// mError("meter:%s error numOfCols:%d in alter table", pAlter->meterId, pAlter->numOfCols); +// code = TSDB_CODE_APP_ERROR; +// } else { +// SDbObj *pDb = NULL; +// if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); +// +// if (pDb) { +// for (int32_t i = 0; i < pAlter->numOfCols; ++i) { +// pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes); +// } +// +// code = mgmtAlterTable(pDb, pAlter); +// if (code == 0) { +// mLPrint("meter:%s is altered by %s", pAlter->meterId, pConn->pUser->user); +// } +// } else { +// code = TSDB_CODE_DB_NOT_SELECTED; +// } +// } +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_TABLE_RSP, code); return 0; } int mgmtProcessCfgDnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { - int code = 0; - SCfgMsg *pCfg = (SCfgMsg *)pMsg; - - if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CFG_MNODE_RSP) != 0) { - return 0; - } - - if (strcmp(pConn->pAcct->user, "root") != 0) { - code = TSDB_CODE_NO_RIGHTS; - } else { - code = mgmtSendCfgDnodeMsg(pMsg); - } - - taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_CFG_RSP, code); - - if (code == 0) mTrace("dnode:%s is configured by %s", pCfg->ip, pConn->pUser->user); - - return 0; -} - -int mgmtProcessHeartBeatMsg(char *cont, int contLen, SConnObj *pConn) { - char * pStart, *pMsg; - int msgLen; - STaosRsp *pRsp; - - mgmtSaveQueryStreamList(cont, contLen, pConn); - - pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_HEARTBEAT_RSP, 128); - if (pStart == NULL) return 0; - pMsg = pStart; - pRsp = (STaosRsp *)pMsg; - pRsp->code = 0; - pMsg = (char *)pRsp->more; - - SHeartBeatRsp *pHBRsp = (SHeartBeatRsp *)pRsp->more; - pHBRsp->queryId = pConn->queryId; - pConn->queryId = 0; - pHBRsp->streamId = pConn->streamId; - pHBRsp->streamId = pConn->streamId; - pConn->streamId = 0; - pHBRsp->killConnection = pConn->killConnection; - - if (pConn->usePublicIp) { - if (pSdbPublicIpList != NULL) { - int size = pSdbPublicIpList->numOfIps * 4; - pHBRsp->ipList.numOfIps = pSdbPublicIpList->numOfIps; - memcpy(pHBRsp->ipList.ip, pSdbPublicIpList->ip, size); - pMsg += sizeof(SHeartBeatRsp) + size; - } else { - pHBRsp->ipList.numOfIps = 0; - pMsg += sizeof(SHeartBeatRsp); - } - - } else { - if (pSdbIpList != NULL) { - int size = pSdbIpList->numOfIps * 4; - pHBRsp->ipList.numOfIps = pSdbIpList->numOfIps; - memcpy(pHBRsp->ipList.ip, pSdbIpList->ip, size); - pMsg += sizeof(SHeartBeatRsp) + size; - } else { - pHBRsp->ipList.numOfIps = 0; - pMsg += sizeof(SHeartBeatRsp); - } - } - msgLen = pMsg - pStart; - - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// int code = 0; +// SCfgMsg *pCfg = (SCfgMsg *)pMsg; +// +// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CFG_MNODE_RSP) != 0) { +// return 0; +// } +// +// if (strcmp(pConn->pAcct->user, "root") != 0) { +// code = TSDB_CODE_NO_RIGHTS; +// } else { +// code = mgmtSendCfgDnodeMsg(pMsg); +// } +// +// taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DNODE_CFG_RSP, code); +// +// if (code == 0) mTrace("dnode:%s is configured by %s", pCfg->ip, pConn->pUser->user); +// +// return 0; +//} +// +//int mgmtProcessHeartBeatMsg(char *cont, int contLen, SConnObj *pConn) { +// char * pStart, *pMsg; +// int msgLen; +// STaosRsp *pRsp; +// +// mgmtSaveQueryStreamList(cont, contLen, pConn); +// +// pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_HEARTBEAT_RSP, 128); +// if (pStart == NULL) return 0; +// pMsg = pStart; +// pRsp = (STaosRsp *)pMsg; +// pRsp->code = 0; +// pMsg = (char *)pRsp->more; +// +// SHeartBeatRsp *pHBRsp = (SHeartBeatRsp *)pRsp->more; +// pHBRsp->queryId = pConn->queryId; +// pConn->queryId = 0; +// pHBRsp->streamId = pConn->streamId; +// pHBRsp->streamId = pConn->streamId; +// pConn->streamId = 0; +// pHBRsp->killConnection = pConn->killConnection; +// +// if (pConn->usePublicIp) { +// if (pSdbPublicIpList != NULL) { +// int size = pSdbPublicIpList->numOfIps * 4; +// pHBRsp->ipList.numOfIps = pSdbPublicIpList->numOfIps; +// memcpy(pHBRsp->ipList.ip, pSdbPublicIpList->ip, size); +// pMsg += sizeof(SHeartBeatRsp) + size; +// } else { +// pHBRsp->ipList.numOfIps = 0; +// pMsg += sizeof(SHeartBeatRsp); +// } +// +// } else { +// if (pSdbIpList != NULL) { +// int size = pSdbIpList->numOfIps * 4; +// pHBRsp->ipList.numOfIps = pSdbIpList->numOfIps; +// memcpy(pHBRsp->ipList.ip, pSdbIpList->ip, size); +// pMsg += sizeof(SHeartBeatRsp) + size; +// } else { +// pHBRsp->ipList.numOfIps = 0; +// pMsg += sizeof(SHeartBeatRsp); +// } +// } +// msgLen = pMsg - pStart; +// +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); return 0; } void mgmtEstablishConn(SConnObj *pConn) { - atomic_fetch_add_32(&mgmtShellConns, 1); - atomic_fetch_add_32(&sdbExtConns, 1); - pConn->stime = taosGetTimestampMs(); - - if (strcmp(pConn->pUser->user, "root") == 0) { - pConn->superAuth = 1; - pConn->writeAuth = 1; - } else { - pConn->superAuth = pConn->pUser->superAuth; - pConn->writeAuth = pConn->pUser->writeAuth; - if (pConn->superAuth) { - pConn->writeAuth = 1; - } - } - - int32_t tempint32; - uint32_t tempuint32; - taosGetRpcConnInfo(pConn->thandle, &tempuint32, &pConn->ip, &pConn->port, &tempint32, &tempint32); - mgmtAddConnIntoAcct(pConn); +// atomic_fetch_add_32(&mgmtShellConns, 1); +// atomic_fetch_add_32(&sdbExtConns, 1); +// pConn->stime = taosGetTimestampMs(); +// +// if (strcmp(pConn->pUser->user, "root") == 0) { +// pConn->superAuth = 1; +// pConn->writeAuth = 1; +// } else { +// pConn->superAuth = pConn->pUser->superAuth; +// pConn->writeAuth = pConn->pUser->writeAuth; +// if (pConn->superAuth) { +// pConn->writeAuth = 1; +// } +// } +// +// int32_t tempint32; +// uint32_t tempuint32; +// taosGetRpcConnInfo(pConn->thandle, &tempuint32, &pConn->ip, &pConn->port, &tempint32, &tempint32); +// mgmtAddConnIntoAcct(pConn); } int mgmtRetriveUserAuthInfo(char *user, char *spi, char *encrypt, uint8_t *secret, uint8_t *ckey) { @@ -1305,196 +1315,198 @@ int mgmtRetriveUserAuthInfo(char *user, char *spi, char *encrypt, uint8_t *secre } int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { - STaosRsp * pRsp; - SConnectRsp *pConnectRsp; - SConnectMsg *pConnectMsg; - char * pStart; - int code = TSDB_CODE_INVALID_USER; - SAcctObj * pAcct = NULL; - SUserObj * pUser = NULL; - SDbObj * pDb = NULL; - char dbName[256] = {0}; - - pConnectMsg = (SConnectMsg *)pMsg; - - pUser = mgmtGetUser(pConn->user); - if (pUser == NULL) { - code = TSDB_CODE_INVALID_USER; - goto _rsp; - } - - if (mgmtCheckExpired()) { - code = TSDB_CODE_GRANT_EXPIRED; - goto _rsp; - } - - pAcct = mgmtGetAcct(pUser->acct); - - code = taosCheckVersion(pConnectMsg->clientVersion, version, 3); - if (code != 0) { - mError("invalid client version:%s", pConnectMsg->clientVersion); - goto _rsp; - } - - if (pConnectMsg->db[0]) { - sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); - pDb = mgmtGetDb(dbName); - if (pDb == NULL) { - code = TSDB_CODE_INVALID_DB; - goto _rsp; - } - } - - if (pConn->pAcct) { - mgmtRemoveConnFromAcct(pConn); - atomic_fetch_sub_32(&mgmtShellConns, 1); - atomic_fetch_sub_32(&sdbExtConns, 1); - } - - code = 0; - pConn->pAcct = pAcct; - pConn->pDb = pDb; - pConn->pUser = pUser; - mgmtEstablishConn(pConn); - -_rsp: - pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_CONNECT_RSP, 128); - if (pStart == NULL) return 0; - - pMsg = pStart; - pRsp = (STaosRsp *)pMsg; - pRsp->code = code; - pMsg += sizeof(STaosRsp); - - if (code == 0) { - pConnectRsp = (SConnectRsp *)pRsp->more; - sprintf(pConnectRsp->acctId, "%x", pConn->pAcct->acctId); - strcpy(pConnectRsp->version, version); - pConnectRsp->writeAuth = pConn->writeAuth; - pConnectRsp->superAuth = pConn->superAuth; - pMsg += sizeof(SConnectRsp); - - int size; - if (pSdbPublicIpList != NULL && pSdbIpList != NULL) { - size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); - if (pConn->usePublicIp) { - memcpy(pMsg, pSdbPublicIpList, size); - } else { - memcpy(pMsg, pSdbIpList, size); - } - } else { - SIpList tmpIpList; - tmpIpList.numOfIps = 0; - size = tmpIpList.numOfIps * 4 + sizeof(SIpList); - memcpy(pMsg, &tmpIpList, size); - } - - pMsg += size; - - // set the time resolution: millisecond or microsecond - *((uint32_t *)pMsg) = tsTimePrecision; - pMsg += sizeof(uint32_t); - - } else { - pConn->pAcct = NULL; - pConn->pUser = NULL; - } - - msgLen = pMsg - pStart; - taosSendMsgToPeer(pConn->thandle, pStart, msgLen); - - char ipstr[24]; - tinet_ntoa(ipstr, pConn->ip); - mLPrint("user:%s login from %s, code:%d", pConn->user, ipstr, code); - - return code; +// STaosRsp * pRsp; +// SConnectRsp *pConnectRsp; +// SConnectMsg *pConnectMsg; +// char * pStart; +// int code = TSDB_CODE_INVALID_USER; +// SAcctObj * pAcct = NULL; +// SUserObj * pUser = NULL; +// SDbObj * pDb = NULL; +// char dbName[256] = {0}; +// +// pConnectMsg = (SConnectMsg *)pMsg; +// +// pUser = mgmtGetUser(pConn->user); +// if (pUser == NULL) { +// code = TSDB_CODE_INVALID_USER; +// goto _rsp; +// } +// +// if (mgmtCheckExpired()) { +// code = TSDB_CODE_GRANT_EXPIRED; +// goto _rsp; +// } +// +// pAcct = mgmtGetAcct(pUser->acct); +// +// code = taosCheckVersion(pConnectMsg->clientVersion, version, 3); +// if (code != 0) { +// mError("invalid client version:%s", pConnectMsg->clientVersion); +// goto _rsp; +// } +// +// if (pConnectMsg->db[0]) { +// sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); +// pDb = mgmtGetDb(dbName); +// if (pDb == NULL) { +// code = TSDB_CODE_INVALID_DB; +// goto _rsp; +// } +// } +// +// if (pConn->pAcct) { +// mgmtRemoveConnFromAcct(pConn); +// atomic_fetch_sub_32(&mgmtShellConns, 1); +// atomic_fetch_sub_32(&sdbExtConns, 1); +// } +// +// code = 0; +// pConn->pAcct = pAcct; +// pConn->pDb = pDb; +// pConn->pUser = pUser; +// mgmtEstablishConn(pConn); +// +//_rsp: +// pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_CONNECT_RSP, 128); +// if (pStart == NULL) return 0; +// +// pMsg = pStart; +// pRsp = (STaosRsp *)pMsg; +// pRsp->code = code; +// pMsg += sizeof(STaosRsp); +// +// if (code == 0) { +// pConnectRsp = (SConnectRsp *)pRsp->more; +// sprintf(pConnectRsp->acctId, "%x", pConn->pAcct->acctId); +// strcpy(pConnectRsp->version, version); +// pConnectRsp->writeAuth = pConn->writeAuth; +// pConnectRsp->superAuth = pConn->superAuth; +// pMsg += sizeof(SConnectRsp); +// +// int size; +// if (pSdbPublicIpList != NULL && pSdbIpList != NULL) { +// size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); +// if (pConn->usePublicIp) { +// memcpy(pMsg, pSdbPublicIpList, size); +// } else { +// memcpy(pMsg, pSdbIpList, size); +// } +// } else { +// SIpList tmpIpList; +// tmpIpList.numOfIps = 0; +// size = tmpIpList.numOfIps * 4 + sizeof(SIpList); +// memcpy(pMsg, &tmpIpList, size); +// } +// +// pMsg += size; +// +// // set the time resolution: millisecond or microsecond +// *((uint32_t *)pMsg) = tsTimePrecision; +// pMsg += sizeof(uint32_t); +// +// } else { +// pConn->pAcct = NULL; +// pConn->pUser = NULL; +// } +// +// msgLen = pMsg - pStart; +// taosSendMsgToPeer(pConn->thandle, pStart, msgLen); +// +// char ipstr[24]; +// tinet_ntoa(ipstr, pConn->ip); +// mLPrint("user:%s login from %s, code:%d", pConn->user, ipstr, code); +// +// return code; + return 0; } void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { - SIntMsg * pMsg = (SIntMsg *)msg; - SConnObj *pConn = (SConnObj *)ahandle; - - if (msg == NULL) { - if (pConn) { - mgmtRemoveConnFromAcct(pConn); - atomic_fetch_sub_32(&mgmtShellConns, 1); - atomic_fetch_sub_32(&sdbExtConns, 1); - mTrace("connection from %s is closed", pConn->pUser->user); - memset(pConn, 0, sizeof(SConnObj)); - } - - return NULL; - } - -#ifdef CLUSTER - if (sdbInited == NULL || sdbStatus != SDB_STATUS_SERVING) { - taosSendSimpleRsp(thandle, pMsg->msgType + 1, TSDB_CODE_NOT_READY); - mTrace("shell msg is ignored since SDB is not ready"); - } -#endif - - if (pConn == NULL) { - pConn = connList + pMsg->destId; - pConn->thandle = thandle; - strcpy(pConn->user, pMsg->meterId); - pConn->usePublicIp = (pMsg->destIp == tsPublicIpInt ? 1 : 0); - mTrace("pConn:%p is rebuild, destIp:%s publicIp:%s usePublicIp:%u", - pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); - } - - if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) { - (*mgmtProcessShellMsg[pMsg->msgType])((char *)pMsg->content, pMsg->msgLen - sizeof(SIntMsg), pConn); - } else { - SMgmtHead *pHead = (SMgmtHead *)pMsg->content; - if (pConn->pAcct == NULL) { - pConn->pUser = mgmtGetUser(pConn->user); - if (pConn->pUser) { - pConn->pAcct = mgmtGetAcct(pConn->pUser->acct); - mgmtEstablishConn(pConn); - mTrace("login from:%x:%hu", pConn->ip, htons(pConn->port)); - } - } - - if (pConn->pAcct) { - if (pConn->pDb == NULL || strncmp(pConn->pDb->name, pHead->db, tListLen(pConn->pDb->name)) != 0) { - pConn->pDb = mgmtGetDb(pHead->db); - } - - char *cont = (char *)pMsg->content + sizeof(SMgmtHead); - int contLen = pMsg->msgLen - sizeof(SIntMsg) - sizeof(SMgmtHead); - - // read-only request can be executed concurrently - if ((pMsg->msgType == TSDB_MSG_TYPE_TABLE_META && (!mgmtCheckMeterMetaMsgType(cont))) || - pMsg->msgType == TSDB_MSG_TYPE_STABLE_META || pMsg->msgType == TSDB_MSG_TYPE_DNODE_RETRIEVE || - pMsg->msgType == TSDB_MSG_TYPE_SHOW || pMsg->msgType == TSDB_MSG_TYPE_MULTI_TABLE_META) { - (*mgmtProcessShellMsg[pMsg->msgType])(cont, contLen, pConn); - } else { - if (mgmtProcessShellMsg[pMsg->msgType]) { - SSchedMsg schedMsg; - schedMsg.msg = malloc(pMsg->msgLen); // Message to deal with - memcpy(schedMsg.msg, pMsg, pMsg->msgLen); - - schedMsg.fp = mgmtProcessTranRequest; - schedMsg.tfp = NULL; - schedMsg.thandle = pConn; - - taosScheduleTask(mgmtTranQhandle, &schedMsg); - } else { - mError("%s from shell is not processed", taosMsg[pMsg->msgType]); - } - } - } else { - taosSendSimpleRsp(thandle, pMsg->msgType + 1, TSDB_CODE_DISCONNECTED); - } - } - - if (pConn->pAcct == NULL) { - taosCloseRpcConn(pConn->thandle); - memset(pConn, 0, sizeof(SConnObj)); // close the connection; - pConn = NULL; - } - - return pConn; +// SIntMsg * pMsg = (SIntMsg *)msg; +// SConnObj *pConn = (SConnObj *)ahandle; +// +// if (msg == NULL) { +// if (pConn) { +// mgmtRemoveConnFromAcct(pConn); +// atomic_fetch_sub_32(&mgmtShellConns, 1); +// atomic_fetch_sub_32(&sdbExtConns, 1); +// mTrace("connection from %s is closed", pConn->pUser->user); +// memset(pConn, 0, sizeof(SConnObj)); +// } +// +// return NULL; +// } +// +//#ifdef CLUSTER +// if (sdbInited == NULL || sdbStatus != SDB_STATUS_SERVING) { +// taosSendSimpleRsp(thandle, pMsg->msgType + 1, TSDB_CODE_NOT_READY); +// mTrace("shell msg is ignored since SDB is not ready"); +// } +//#endif +// +// if (pConn == NULL) { +// pConn = connList + pMsg->destId; +// pConn->thandle = thandle; +// strcpy(pConn->user, pMsg->meterId); +// pConn->usePublicIp = (pMsg->destIp == tsPublicIpInt ? 1 : 0); +// mTrace("pConn:%p is rebuild, destIp:%s publicIp:%s usePublicIp:%u", +// pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); +// } +// +// if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) { +// (*mgmtProcessShellMsg[pMsg->msgType])((char *)pMsg->content, pMsg->msgLen - sizeof(SIntMsg), pConn); +// } else { +// SMgmtHead *pHead = (SMgmtHead *)pMsg->content; +// if (pConn->pAcct == NULL) { +// pConn->pUser = mgmtGetUser(pConn->user); +// if (pConn->pUser) { +// pConn->pAcct = mgmtGetAcct(pConn->pUser->acct); +// mgmtEstablishConn(pConn); +// mTrace("login from:%x:%hu", pConn->ip, htons(pConn->port)); +// } +// } +// +// if (pConn->pAcct) { +// if (pConn->pDb == NULL || strncmp(pConn->pDb->name, pHead->db, tListLen(pConn->pDb->name)) != 0) { +// pConn->pDb = mgmtGetDb(pHead->db); +// } +// +// char *cont = (char *)pMsg->content + sizeof(SMgmtHead); +// int contLen = pMsg->msgLen - sizeof(SIntMsg) - sizeof(SMgmtHead); +// +// // read-only request can be executed concurrently +// if ((pMsg->msgType == TSDB_MSG_TYPE_TABLE_META && (!mgmtCheckMeterMetaMsgType(cont))) || +// pMsg->msgType == TSDB_MSG_TYPE_STABLE_META || pMsg->msgType == TSDB_MSG_TYPE_DNODE_RETRIEVE || +// pMsg->msgType == TSDB_MSG_TYPE_SHOW || pMsg->msgType == TSDB_MSG_TYPE_MULTI_TABLE_META) { +// (*mgmtProcessShellMsg[pMsg->msgType])(cont, contLen, pConn); +// } else { +// if (mgmtProcessShellMsg[pMsg->msgType]) { +// SSchedMsg schedMsg; +// schedMsg.msg = malloc(pMsg->msgLen); // Message to deal with +// memcpy(schedMsg.msg, pMsg, pMsg->msgLen); +// +// schedMsg.fp = mgmtProcessTranRequest; +// schedMsg.tfp = NULL; +// schedMsg.thandle = pConn; +// +// taosScheduleTask(mgmtTranQhandle, &schedMsg); +// } else { +// mError("%s from shell is not processed", taosMsg[pMsg->msgType]); +// } +// } +// } else { +// taosSendSimpleRsp(thandle, pMsg->msgType + 1, TSDB_CODE_DISCONNECTED); +// } +// } +// +// if (pConn->pAcct == NULL) { +// taosCloseRpcConn(pConn->thandle); +// memset(pConn, 0, sizeof(SConnObj)); // close the connection; +// pConn = NULL; +// } +// +// return pConn; + return NULL; } void mgmtInitProcessShellMsg() { @@ -1519,7 +1531,7 @@ void mgmtInitProcessShellMsg() { mgmtProcessShellMsg[TSDB_MSG_TYPE_DNODE_RETRIEVE] = mgmtProcessRetrieveMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_SHOW] = mgmtProcessShowMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CONNECT] = mgmtProcessConnectMsg; - mgmtProcessShellMsg[TSDB_MSG_TYPE_HEARTBEAT] = mgmtProcessHeartBeatMsg; +// mgmtProcessShellMsg[TSDB_MSG_TYPE_HEARTBEAT] = mgmtProcessHeartBeatMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_DNODE] = mgmtProcessCreateDnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_DNODE] = mgmtProcessDropDnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_MNODE] = mgmtProcessCreateMnodeMsg; @@ -1537,36 +1549,43 @@ int32_t mgmtCheckRedirectMsgImp(SConnObj *pConn, int32_t msgType) { int32_t (*mgmtCheckRedirectMsg)(SConnObj *pConn, int32_t msgType) = mgmtCheckRedirectMsgImp; int32_t mgmtProcessAlterAcctMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + //return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessAlterAcctMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessAlterAcctMsgImp; int32_t mgmtProcessCreateDnodeMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + //return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessCreateDnodeMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessCreateDnodeMsgImp; int32_t mgmtProcessCfgMnodeMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CFG_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + //return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CFG_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessCfgMnodeMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessCfgMnodeMsgImp; int32_t mgmtProcessDropMnodeMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + //return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessDropMnodeMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessDropMnodeMsgImp; int32_t mgmtProcessDropDnodeMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + //return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessDropDnodeMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessDropDnodeMsgImp; int32_t mgmtProcessDropAcctMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); +// return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessDropAcctMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessDropAcctMsgImp; int32_t mgmtProcessCreateAcctMsgImp(char *pMsg, int32_t msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); +// return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return 0; } int32_t (*mgmtProcessCreateAcctMsg)(char *pMsg, int32_t msgLen, SConnObj *pConn) = mgmtProcessCreateAcctMsgImp; \ No newline at end of file diff --git a/src/mnode/src/mgmtStreamTable.c b/src/mnode/src/mgmtStreamTable.c index ef9aaa0086..6fc2fb5e7b 100644 --- a/src/mnode/src/mgmtStreamTable.c +++ b/src/mnode/src/mgmtStreamTable.c @@ -39,7 +39,7 @@ #include "mgmtStreamTable.h" -void *tsSuperTableSdb; +void *tsStreamTableSdb; void *(*mgmtStreamTableActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize); void *mgmtStreamTableActionInsert(void *row, char *str, int size, int *ssize); @@ -78,7 +78,7 @@ void *mgmtStreamTableActionReset(void *row, char *str, int size, int *ssize) { } void *mgmtStreamTableActionDestroy(void *row, char *str, int size, int *ssize) { - SSuperTableObj *pTable = (STabObj *)row; + SStreamTableObj *pTable = (SStreamTableObj *)row; mgmtDestroyStreamTable(pTable); return NULL; } @@ -230,7 +230,7 @@ void mgmtCleanUpStreamTables() { } int8_t *mgmtBuildCreateStreamTableMsg(SStreamTableObj *pTable, int8_t *pMsg, int32_t vnode) { - SCreateStreamTableMsg *pCreateTable = (SCreateStreamTableMsg *) pMsg; + SDCreateTableMsg *pCreateTable = (SDCreateTableMsg *) pMsg; memcpy(pCreateTable->tableId, pTable->tableId, TSDB_TABLE_ID_LEN); pCreateTable->vnode = htonl(vnode); pCreateTable->sid = htonl(pTable->sid); @@ -238,23 +238,23 @@ int8_t *mgmtBuildCreateStreamTableMsg(SStreamTableObj *pTable, int8_t *pMsg, int pCreateTable->createdTime = htobe64(pTable->createdTime); pCreateTable->sversion = htonl(pTable->sversion); pCreateTable->numOfColumns = htons(pTable->numOfColumns); - pCreateTable->sqlLen = htons(pTable->sqlLen); + //pCreateTable->sqlLen = htons(pTable->sqlLen); SSchema *pSchema = pTable->schema; int32_t totalCols = pCreateTable->numOfColumns; - for (int32_t col = 0; col < totalCols; ++col) { - SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; - colData->type = pSchema[col].type; - colData->bytes = htons(pSchema[col].bytes); - colData->colId = htons(pSchema[col].colId); - } +// for (int32_t col = 0; col < totalCols; ++col) { +// SMColumn *colData = &((SMColumn *) (pCreateTable->data))[col]; +// colData->type = pSchema[col].type; +// colData->bytes = htons(pSchema[col].bytes); +// colData->colId = htons(pSchema[col].colId); +// } - int32_t totalColsSize = sizeof(SMColumn *) * totalCols; - pMsg = pCreateTable->data + totalColsSize + pTable->sqlLen; +// int32_t totalColsSize = sizeof(SMColumn *) * totalCols; +// pMsg = pCreateTable->data + totalColsSize + pTable->sqlLen; - char *sql = pTable->schema + pTable->schemaSize; - memcpy(pCreateTable->data + totalColsSize, pTable->sqlLen, sql); +// char *sql = pTable->schema + pTable->schemaSize; +// memcpy(pCreateTable->data + totalColsSize, pTable->sqlLen, sql); return pMsg; } @@ -345,6 +345,6 @@ int32_t mgmtDropStreamTable(SDbObj *pDb, SStreamTableObj *pTable) { return 0; } -SStreamTableObj* mgmtGetStreamTable(char *tableId); { +SStreamTableObj* mgmtGetStreamTable(char *tableId) { return (SStreamTableObj *)sdbGetRow(tsStreamTableSdb, tableId); } \ No newline at end of file diff --git a/src/mnode/src/mgmtSuperTable.c b/src/mnode/src/mgmtSuperTable.c index 3542979fc2..f5ceeb026c 100644 --- a/src/mnode/src/mgmtSuperTable.c +++ b/src/mnode/src/mgmtSuperTable.c @@ -93,7 +93,7 @@ void *mgmtSuperTableActionReset(void *row, char *str, int size, int *ssize) { SSuperTableObj *pTable = (SSuperTableObj *) row; int tsize = pTable->updateEnd - (int8_t *) pTable; memcpy(pTable, str, tsize); - pTable->schema = (char *) realloc(pTable->schema, pTable->schemaSize); + pTable->schema = realloc(pTable->schema, pTable->schemaSize); memcpy(pTable->schema, str + tsize, pTable->schemaSize); return NULL; } @@ -105,20 +105,10 @@ void *mgmtSuperTableActionDestroy(void *row, char *str, int size, int *ssize) { } void *mgmtSuperTableActionInsert(void *row, char *str, int size, int *ssize) { - SSuperTableObj *pTable = (SSuperTableObj *) row; - SDbObj *pDb = mgmtGetDbByMeterId(pTable->tableId); - if (pDb) { - mgmtAddMetricIntoDb(pDb, pTable); - } return NULL; } void *mgmtSuperTableActionDelete(void *row, char *str, int size, int *ssize) { - SSuperTableObj *pTable = (SSuperTableObj *) row; - SDbObj *pDb = mgmtGetDbByMeterId(pTable->tableId); - if (pDb) { - mgmtRemoveMetricFromDb(pDb, pTable); - } return NULL; } @@ -159,7 +149,7 @@ void *mgmtSuperTableActionDecode(void *row, char *str, int size, int *ssize) { } memcpy(pTable, str, tsize); - pTable->schema = (char *)malloc(pTable->schemaSize); + pTable->schema = malloc(pTable->schemaSize); if (pTable->schema == NULL) { mgmtDestroySuperTable(pTable); return NULL; @@ -179,95 +169,38 @@ void *mgmtSuperTableAction(char action, void *row, char *str, int size, int *ssi int32_t mgmtInitSuperTables() { void * pNode = NULL; void * pLastNode = NULL; - SVgObj * pVgroup = NULL; - STabObj * pTable = NULL; - STabObj * pMetric = NULL; - SDbObj * pDb = NULL; - SAcctObj *pAcct = NULL; + SSuperTableObj * pTable = NULL; // TODO: Make sure this function only run once mgmtSuperTableActionInit(); tsSuperTableSdb = sdbOpenTable(tsMaxTables, sizeof(STabObj) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_MAX_SQL_LEN, "meters", SDB_KEYTYPE_STRING, mgmtDirectory, mgmtSuperTableAction); - if (meterSdb == NULL) { + if (tsSuperTableSdb == NULL) { mError("failed to init meter data"); return -1; } pNode = NULL; while (1) { - pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable); - if (pTable == NULL) break; - if (mgmtIsSuperTable(pTable)) pTable->numOfMeters = 0; - } - - pNode = NULL; - while (1) { - pLastNode = pNode; - pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable); - if (pTable == NULL) break; + pNode = sdbFetchRow(tsSuperTableSdb, pNode, (void **)&pTable); + if (pTable == NULL) { + break; + } - pDb = mgmtGetDbByMeterId(pTable->meterId); + SDbObj *pDb = mgmtGetDbByMeterId(pTable->tableId); if (pDb == NULL) { - mError("meter:%s, failed to get db, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); + mError("super table:%s, failed to get db, discard it", pTable->tableId); + sdbDeleteRow(tsSuperTableSdb, pTable); pNode = pLastNode; continue; } - - if (mgmtIsNormalTable(pTable)) { - pVgroup = mgmtGetVgroup(pTable->gid.vgId); - - if (pVgroup == NULL) { - mError("meter:%s, failed to get vgroup:%d sid:%d, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - if (strcmp(pVgroup->dbName, pDb->name) != 0) { - mError("meter:%s, db:%s not match with vgroup:%d db:%s sid:%d, discard it", - pTable->meterId, pDb->name, pTable->gid.vgId, pVgroup->dbName, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - if ( pVgroup->meterList == NULL) { - mError("meter:%s, vgroup:%d meterlist is null", pTable->meterId, pTable->gid.vgId); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - pVgroup->meterList[pTable->gid.sid] = pTable; - taosIdPoolMarkStatus(pVgroup->idPool, pTable->gid.sid, 1); - - if (pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE) { - pTable->pSql = (char *)pTable->schema + sizeof(SSchema) * pTable->numOfColumns; - } - - if (mgmtTableCreateFromSuperTable(pTable)) { - pTable->pTagData = (char *)pTable->schema; // + sizeof(SSchema)*pTable->numOfColumns; - pMetric = mgmtGetTable(pTable->pTagData); - if (pMetric) mgmtAddMeterIntoMetric(pMetric, pTable); - } - - pAcct = mgmtGetAcct(pDb->cfg.acct); - if (pAcct) mgmtAddMeterStatisticToAcct(pTable, pAcct); - } else { - if (pDb) mgmtAddMetricIntoDb(pDb, pTable); - } + pTable->numOfMeters = 0; } mgmtSetVgroupIdPool(); - mTrace("meter is initialized"); + mTrace("super table is initialized"); return 0; } @@ -321,11 +254,8 @@ int32_t mgmtCreateSuperTable(SDbObj *pDb, SCreateTableMsg *pCreate) { } int32_t mgmtDropSuperTable(SDbObj *pDb, SSuperTableObj *pSuperTable) { - SChildTableObj *pMetric; - while ((pMetric = pSuperTable->pHead) != NULL) { - mgmtDropChildTable(pDb, pMetric); - } - sdbDeleteRow(tsSuperTableSdb, pMetric); + //TODO drop all child tables + return sdbDeleteRow(tsSuperTableSdb, pSuperTable); } SSuperTableObj* mgmtGetSuperTable(char *tableId) { @@ -477,7 +407,7 @@ int32_t mgmtModifySuperTableTagNameByName(SSuperTableObj *pMetric, char *oldTagN } -static int32_t mgmtFindSuperTableColumnIndex(SNormalTableObj *pMetric, char *colName) { +static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pMetric, char *colName) { SSchema *schema = (SSchema *) pMetric->schema; for (int32_t i = 0; i < pMetric->numOfColumns; i++) { if (strcasecmp(schema[i].name, colName) == 0) { @@ -650,7 +580,7 @@ int mgmtRetrieveSuperTables(SShowObj *pShow, char *data, int rows, SConnObj *pCo while (numOfRows < rows) { pTable = (SSuperTableObj *)pShow->pNode; if (pTable == NULL) break; - pShow->pNode = (void *)pTable->next; + //pShow->pNode = (void *)pTable->next; if (strncmp(pTable->tableId, prefix, prefixLen)) { continue; @@ -706,8 +636,6 @@ int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable) { pMetric->pHead = pTable; pMetric->numOfMeters++; - addMeterIntoMetricIndex(pMetric, pTable); - pthread_rwlock_unlock(&(pMetric->rwLock)); return 0; @@ -724,8 +652,6 @@ int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable) { pMetric->numOfMeters--; - removeMeterFromMetricIndex(pMetric, pTable); - pthread_rwlock_unlock(&(pMetric->rwLock)); return 0; diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 6aa90f34f1..4b0499911e 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -44,21 +44,6 @@ extern int64_t sdbVersion; - -void *meterSdb = NULL; -void *(*mgmtMeterActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize); - -int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags); -static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pTable); -static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pTable); -int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name); -int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const char *nname); -int32_t mgmtMeterModifyTagValueByName(STabObj *pTable, char *tagName, char *nContent); -int32_t mgmtMeterAddColumn(STabObj *pTable, SSchema schema[], int ncols); -int32_t mgmtMeterDropColumnByName(STabObj *pTable, const char *name); -static int dropMeterImp(SDbObj *pDb, STabObj * pTable, SAcctObj *pAcct); -static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcct); - static int32_t mgmtGetReqTagsLength(STabObj *pMetric, int16_t *cols, int32_t numOfCols) { assert(mgmtIsSuperTable(pMetric) && numOfCols >= 0 && numOfCols <= TSDB_MAX_TAGS + 1); @@ -87,98 +72,27 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_ } int mgmtInitMeters() { - void * pNode = NULL; - void * pLastNode = NULL; - SVgObj * pVgroup = NULL; - STabObj * pTable = NULL; - STabObj * pMetric = NULL; - SDbObj * pDb = NULL; - SAcctObj *pAcct = NULL; - - // TODO: Make sure this function only run once - mgmtMeterActionInit(); - - meterSdb = sdbOpenTable(tsMaxTables, sizeof(STabObj) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_MAX_SQL_LEN, - "meters", SDB_KEYTYPE_STRING, mgmtDirectory, mgmtMeterAction); - if (meterSdb == NULL) { - mError("failed to init meter data"); - return -1; + int32_t code = mgmtInitSuperTables(); + if (code != TSDB_CODE_SUCCESS) { + return code; } - pNode = NULL; - while (1) { - pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable); - if (pTable == NULL) break; - if (mgmtIsSuperTable(pTable)) pTable->numOfMeters = 0; + code = mgmtInitNormalTables(); + if (code != TSDB_CODE_SUCCESS) { + return code; } - pNode = NULL; - while (1) { - pLastNode = pNode; - pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable); - if (pTable == NULL) break; - - pDb = mgmtGetDbByMeterId(pTable->meterId); - if (pDb == NULL) { - mError("meter:%s, failed to get db, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - if (mgmtIsNormalTable(pTable)) { - pVgroup = mgmtGetVgroup(pTable->gid.vgId); - - if (pVgroup == NULL) { - mError("meter:%s, failed to get vgroup:%d sid:%d, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - if (strcmp(pVgroup->dbName, pDb->name) != 0) { - mError("meter:%s, db:%s not match with vgroup:%d db:%s sid:%d, discard it", - pTable->meterId, pDb->name, pTable->gid.vgId, pVgroup->dbName, pTable->gid.sid); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - if ( pVgroup->meterList == NULL) { - mError("meter:%s, vgroup:%d meterlist is null", pTable->meterId, pTable->gid.vgId); - pTable->gid.vgId = 0; - sdbDeleteRow(meterSdb, pTable); - pNode = pLastNode; - continue; - } - - pVgroup->meterList[pTable->gid.sid] = pTable; - taosIdPoolMarkStatus(pVgroup->idPool, pTable->gid.sid, 1); - - if (pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE) { - pTable->pSql = (char *)pTable->schema + sizeof(SSchema) * pTable->numOfColumns; - } - - if (mgmtTableCreateFromSuperTable(pTable)) { - pTable->pTagData = (char *)pTable->schema; // + sizeof(SSchema)*pTable->numOfColumns; - pMetric = mgmtGetTable(pTable->pTagData); - if (pMetric) mgmtAddMeterIntoMetric(pMetric, pTable); - } - - pAcct = mgmtGetAcct(pDb->cfg.acct); - if (pAcct) mgmtAddMeterStatisticToAcct(pTable, pAcct); - } else { - if (pDb) mgmtAddMetricIntoDb(pDb, pTable); - } + code = mgmtInitStreamTables(); + if (code != TSDB_CODE_SUCCESS) { + return code; } - mgmtSetVgroupIdPool(); + code = mgmtInitChildTables(); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - mTrace("meter is initialized"); - return 0; + return TSDB_CODE_SUCCESS; } STableObj mgmtGetTable(char *tableId) { @@ -211,6 +125,11 @@ STableObj mgmtGetTable(char *tableId) { return table; } +STableObj mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid) { + STableObj table = {0}; + return table; +} + int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) { STableObj table = mgmtGetTable(pCreate->meterId); if (table.obj != NULL) { @@ -293,7 +212,7 @@ int mgmtDropTable(SDbObj *pDb, char *tableId, int ignore) { } int mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter) { - STableObj table = mgmtGetTable(tableId); + STableObj table = mgmtGetTable(pAlter->meterId); if (table.obj == NULL) { return TSDB_CODE_INVALID_TABLE; } @@ -503,9 +422,9 @@ int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pCon cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - if (pTable->pTagData) { - extractTableName(superTableId, pWrite); - } +// if (pTable->pTagData) { +// extractTableName(superTableId, pWrite); +// } cols++; numOfRows++; diff --git a/src/mnode/src/mgmtUtil.c b/src/mnode/src/mgmtUtil.c index 57b9495860..c2da5c398e 100644 --- a/src/mnode/src/mgmtUtil.c +++ b/src/mnode/src/mgmtUtil.c @@ -31,34 +31,32 @@ bool mgmtIsSuperTable(STabObj* pTableObj) { bool mgmtIsNormalTable(STabObj* pTableObj) { return !mgmtIsSuperTable(pTableObj); } +// +///** +// * TODO: the tag offset value should be kept in memory to avoid dynamically calculating the value +// * +// * @param pTable +// * @param col +// * @param pTagColSchema +// * @return +// */ +//char* mgmtTableGetTag(STabObj* pTable, int32_t col, SSchema* pTagColSchema) { +// if (!mgmtTableCreateFromSuperTable(pTable)) { +// return NULL; +// } +// +// STabObj* pSuperTable = mgmtGetTable(pTable->pTagData); +// int32_t offset = mgmtGetTagsLength(pSuperTable, col) + TSDB_TABLE_ID_LEN; +// assert(offset > 0); +// +// if (pTagColSchema != NULL) { +// *pTagColSchema = ((SSchema*)pSuperTable->schema)[pSuperTable->numOfColumns + col]; +// } +// +// return (pTable->pTagData + offset); +//} -/** - * TODO: the tag offset value should be kept in memory to avoid dynamically calculating the value - * - * @param pTable - * @param col - * @param pTagColSchema - * @return - */ -char* mgmtTableGetTag(STabObj* pTable, int32_t col, SSchema* pTagColSchema) { - if (!mgmtTableCreateFromSuperTable(pTable)) { - return NULL; - } - - STabObj* pSuperTable = mgmtGetTable(pTable->pTagData); - int32_t offset = mgmtGetTagsLength(pSuperTable, col) + TSDB_TABLE_ID_LEN; - assert(offset > 0); - - if (pTagColSchema != NULL) { - *pTagColSchema = ((SSchema*)pSuperTable->schema)[pSuperTable->numOfColumns + col]; - } - - return (pTable->pTagData + offset); -} - -int32_t mgmtGetTagsLength(STabObj* pSuperTable, int32_t col) { // length before column col - assert(mgmtIsSuperTable(pSuperTable) && col >= 0); - +int32_t mgmtGetTagsLength(SSuperTableObj* pSuperTable, int32_t col) { // length before column col int32_t len = 0; int32_t tagColumnIndexOffset = pSuperTable->numOfColumns; diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index ffd7ca4aa2..18f23d6fb6 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -74,7 +74,7 @@ int mgmtInitVgroups() { mgmtVgroupActionInit(); SVgObj tObj; - tsVgUpdateSize = tObj.updateEnd - (char *)&tObj; + tsVgUpdateSize = tObj.updateEnd - (int8_t *)&tObj; vgSdb = sdbOpenTable(tsMaxVGroups, sizeof(SVgObj), "vgroups", SDB_KEYTYPE_AUTO, mgmtDirectory, mgmtVgroupAction); if (vgSdb == NULL) { @@ -294,14 +294,14 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { SVgObj *pVgroup = NULL; STabObj *pTable = NULL; if (pShow->payloadLen > 0 ) { - pTable = mgmtGetTable(pShow->payload); - if (NULL == pTable) { - return TSDB_CODE_INVALID_TABLE_ID; - } - - pVgroup = mgmtGetVgroup(pTable->gid.vgId); - if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; - +// pTable = mgmtGetTable(pShow->payload); +// if (NULL == pTable) { +// return TSDB_CODE_INVALID_TABLE_ID; +// } +// +// pVgroup = mgmtGetVgroup(pTable->gid.vgId); +// if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; +// maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; } else { SVgObj *pVgroup = pDb->pHead; @@ -476,7 +476,7 @@ void *mgmtVgroupActionUpdate(void *row, char *str, int size, int *ssize) { } void *mgmtVgroupActionEncode(void *row, char *str, int size, int *ssize) { SVgObj *pVgroup = (SVgObj *)row; - int tsize = pVgroup->updateEnd - (char *)pVgroup; + int tsize = pVgroup->updateEnd - (int8_t *)pVgroup; if (size < tsize) { *ssize = -1; } else { @@ -491,7 +491,7 @@ void *mgmtVgroupActionDecode(void *row, char *str, int size, int *ssize) { if (pVgroup == NULL) return NULL; memset(pVgroup, 0, sizeof(SVgObj)); - int tsize = pVgroup->updateEnd - (char *)pVgroup; + int tsize = pVgroup->updateEnd - (int8_t *)pVgroup; memcpy(pVgroup, str, tsize); return (void *)pVgroup; @@ -501,7 +501,7 @@ void *mgmtVgroupActionBatchUpdate(void *row, char *str, int size, int *ssize) { void *mgmtVgroupActionAfterBatchUpdate(void *row, char *str, int size, int *ssize) { return NULL; } void *mgmtVgroupActionReset(void *row, char *str, int size, int *ssize) { SVgObj *pVgroup = (SVgObj *)row; - int tsize = pVgroup->updateEnd - (char *)pVgroup; + int tsize = pVgroup->updateEnd - (int8_t *)pVgroup; memcpy(pVgroup, str, tsize); diff --git a/src/plugins/http/CMakeLists.txt b/src/plugins/http/CMakeLists.txt index d8dccb526a..9fd2999957 100644 --- a/src/plugins/http/CMakeLists.txt +++ b/src/plugins/http/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index 2ba8250eac..f60aca5c7a 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -17,6 +17,7 @@ #include "cJSON.h" #include "gcJson.h" #include "taosdef.h" +#include "tlog.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index b46fa11cde..3701be7543 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -27,6 +27,7 @@ #include "tglobalcfg.h" #include "tsocket.h" #include "ttimer.h" +#include "tlog.h" void httpToLowerUrl(char* url) { /*ignore case */ diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index c75d84d731..926db9d440 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -25,6 +25,8 @@ #include "httpJson.h" #include "httpResp.h" #include "taosmsg.h" +#include "tlog.h" +#include "taoserror.h" #define MAX_NUM_STR_SZ 25 @@ -451,7 +453,7 @@ void httpJsonPairStatus(JsonBuf* buf, int code) { } else if (code == TSDB_CODE_INVALID_TABLE) { httpJsonPair(buf, "desc", 4, "failed to create table", 22); } else - httpJsonPair(buf, "desc", 4, tstrerror(code), (int)strlen(tstrerror(code))); + httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code))); } } } \ No newline at end of file diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 3a37231490..39f208a9dd 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -19,6 +19,8 @@ #include "httpCode.h" #include "httpJson.h" #include "taosmsg.h" +#include "tlog.h" +#include "taoserror.h" const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; @@ -182,7 +184,7 @@ void httpSendErrorResp(HttpContext *pContext, int errNo) { httpSendErrorRespWith void httpSendTaosdErrorResp(HttpContext *pContext, int errCode) { int httpCode = 400; - httpSendErrorRespImp(pContext, httpCode, "Bad Request", errCode, tstrerror(errCode)); + httpSendErrorRespImp(pContext, httpCode, "Bad Request", errCode, (char*)tstrerror(errCode)); } void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg) { diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index 568936ede6..c6be951418 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -26,6 +26,7 @@ #include "taos.h" #include "ttime.h" #include "ttimer.h" +#include "tlog.h" void httpAccessSession(HttpContext *pContext) { HttpServer *server = pContext->pThread->pServer; diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 3171aee9ec..41b712048f 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -32,6 +32,7 @@ #include "httpHandle.h" #include "restHandle.h" #include "tgHandle.h" +#include "tlog.h" #ifdef CLUSTER void adminInitHandle(HttpServer* pServer); diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index b0f8b1eb0b..3791e4b60b 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -26,6 +26,7 @@ #include "shash.h" #include "taos.h" +#include "tlog.h" bool httpCheckUsedbSql(char *sql) { if (strstr(sql, "use ") != NULL) { diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a307700866..78c08ab866 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -15,6 +15,7 @@ #include "restHandle.h" #include "restJson.h" +#include "tlog.h" static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; @@ -70,8 +71,7 @@ bool restProcessSqlRequest(HttpContext* pContext, int timestampFmt) { /* * for async test - * / - /* + * if (httpCheckUsedbSql(sql)) { httpSendErrorResp(pContext, HTTP_NO_EXEC_USEDB); return false; diff --git a/src/plugins/http/src/restJson.c b/src/plugins/http/src/restJson.c index 7e98472d53..107449bab3 100644 --- a/src/plugins/http/src/restJson.c +++ b/src/plugins/http/src/restJson.c @@ -18,7 +18,7 @@ #include #include #include - +#include "tlog.h" #include "httpJson.h" #include "restHandle.h" #include "restJson.h" diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 9004dc4737..4e983381ca 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -18,6 +18,7 @@ #include "taosmsg.h" #include "tgJson.h" #include "taosdef.h" +#include "tlog.h" /* * taos.telegraf.cfg formats like diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index f706a56bd9..6dfd2c8e9a 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -22,6 +22,7 @@ #include "taosmsg.h" #include "tgHandle.h" #include "tgJson.h" +#include "tlog.h" void tgInitQueryJson(HttpContext *pContext) { JsonBuf *jsonBuf = httpMallocJsonBuf(pContext); diff --git a/src/plugins/monitor/CMakeLists.txt b/src/plugins/monitor/CMakeLists.txt index 44ac8aae0b..6bc41d2b3e 100644 --- a/src/plugins/monitor/CMakeLists.txt +++ b/src/plugins/monitor/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(./src SRC) diff --git a/src/plugins/monitor/src/monitorSystem.c b/src/plugins/monitor/src/monitorSystem.c index cac6c93588..f8653e4320 100644 --- a/src/plugins/monitor/src/monitorSystem.c +++ b/src/plugins/monitor/src/monitorSystem.c @@ -18,6 +18,7 @@ #include #include #include +#include "dnode.h" #include "monitorSystem.h" #include "tsclient.h" #include "taosdef.h" diff --git a/src/sdb/src/sdbEngine.c b/src/sdb/src/sdbEngine.c index 77b6f6d958..fdf7960724 100644 --- a/src/sdb/src/sdbEngine.c +++ b/src/sdb/src/sdbEngine.c @@ -53,6 +53,10 @@ SSdbTable *tableList[20]; int sdbNumOfTables; int64_t sdbVersion; +int64_t sdbGetVersion() { + return sdbVersion; +}; + void sdbFinishCommit(void *handle) { SSdbTable *pTable = (SSdbTable *)handle; uint32_t sdbEcommit = SDB_ENDCOMMIT; -- GitLab