From 5476ccaad2dcd475721f94258f4c1745fdcde91e Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Fri, 8 May 2020 17:13:11 +0800 Subject: [PATCH] [td-225] use the dnodeConn instead of mgmtConn and vnodeConn --- src/client/inc/tsclient.h | 4 ++-- src/client/src/tscServer.c | 3 ++- src/client/src/tscSql.c | 13 ++++++++++--- src/client/src/tscSystem.c | 16 +++++----------- src/client/src/tscUtil.c | 4 ++++ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index cafb0b8fb1..61a5fdd311 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -304,6 +304,7 @@ typedef struct STscObj { struct SSqlObj * pHb; struct SSqlObj * sqlList; struct SSqlStream *streamList; + void* pDnodeConn; pthread_mutex_t mutex; } STscObj; @@ -359,7 +360,7 @@ typedef struct SSqlStream { struct SSqlStream *prev, *next; } SSqlStream; -int32_t tscInitRpc(const char *user, const char *secret); +int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn); void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion); @@ -425,7 +426,6 @@ void tscQueueAsyncFreeResult(SSqlObj *pSql); int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); void tscGetResultColumnChr(SSqlRes *pRes, SFieldInfo* pFieldInfo, int32_t column); -extern void * pDnodeConn; extern void * tscCacheHandle; extern void * tscTmr; extern void * tscQhandle; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6c23b079d1..35e2250dd8 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -191,6 +191,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { } int tscSendMsgToServer(SSqlObj *pSql) { + STscObj* pObj = pSql->pTscObj; SSqlCmd* pCmd = &pSql->cmd; char *pMsg = rpcMallocCont(pCmd->payloadLen); @@ -215,7 +216,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { .handle = pSql, .code = 0 }; - rpcSendRequest(pDnodeConn, &pSql->ipList, &rpcMsg); + rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 15d7e76b9a..a45db94b49 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -65,8 +65,9 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con terrno = TSDB_CODE_INVALID_PASS; return NULL; } - - if (tscInitRpc(user, pass) != 0) { + + void *pDnodeConn = NULL; + if (tscInitRpc(user, pass, &pDnodeConn) != 0) { terrno = TSDB_CODE_NETWORK_UNAVAIL; return NULL; } @@ -93,6 +94,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + rpcClose(pDnodeConn); return NULL; } @@ -106,8 +108,9 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con int32_t len = strlen(db); /* db name is too long */ if (len > TSDB_DB_NAME_LEN) { - free(pObj); terrno = TSDB_CODE_INVALID_DB; + rpcClose(pDnodeConn); + free(pObj); return NULL; } @@ -123,6 +126,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (NULL == pSql) { terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + rpcClose(pDnodeConn); free(pObj); return NULL; } @@ -134,6 +138,8 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con tsem_init(&pSql->rspSem, 0, 0); pObj->pSql = pSql; + pObj->pDnodeConn = pDnodeConn; + pSql->fp = fp; pSql->param = param; if (taos != NULL) { @@ -143,6 +149,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->cmd.command = TSDB_SQL_CONNECT; if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + rpcClose(pDnodeConn); free(pSql); free(pObj); return NULL; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index f7254468b6..d713a9ee5f 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -30,7 +30,6 @@ #include "tlocale.h" // global, not configurable -void * pDnodeConn; void * tscCacheHandle; void * tscTmr; void * tscQhandle; @@ -48,12 +47,12 @@ void tscCheckDiskUsage(void *UNUSED_PARAM(para), void* UNUSED_PARAM(param)) { taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr); } -int32_t tscInitRpc(const char *user, const char *secret) { +int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) { SRpcInit rpcInit; char secretEncrypt[32] = {0}; taosEncryptPass((uint8_t *)secret, strlen(secret), secretEncrypt); - if (pDnodeConn == NULL) { + if (*pDnodeConn == NULL) { memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = 0; rpcInit.label = "TSC"; @@ -66,9 +65,9 @@ int32_t tscInitRpc(const char *user, const char *secret) { rpcInit.ckey = "key"; rpcInit.secret = secretEncrypt; - pDnodeConn = rpcOpen(&rpcInit); - if (pDnodeConn == NULL) { - tscError("failed to init connection to vnode"); + *pDnodeConn = rpcOpen(&rpcInit); + if (*pDnodeConn == NULL) { + tscError("failed to init connection to TDengine"); return -1; } } @@ -168,11 +167,6 @@ void taos_cleanup() { taosCloseLog(); - if (pDnodeConn != NULL) { - rpcClose(pDnodeConn); - pDnodeConn = NULL; - } - taosTmrCleanUp(tscTmr); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 47d4de9f21..ccb363d9e8 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -762,6 +762,10 @@ void tscCloseTscObj(STscObj* pObj) { pthread_mutex_destroy(&pObj->mutex); + if (pObj->pDnodeConn != NULL) { + rpcClose(pObj->pDnodeConn); + } + tscTrace("%p DB connection is closed", pObj); tfree(pObj); } -- GitLab