From 223f78d86459e372f82dd4d2c8cab7eed4e3132c Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 16 Apr 2020 11:52:16 +0800 Subject: [PATCH 1/3] [td-98] fix empty rsp cause submit failure [td-98] fix empty rsp cause submit failure --- src/client/src/tscAsync.c | 5 +++-- src/client/src/tscServer.c | 5 ++--- src/client/src/tscSql.c | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 610027151f..01ab5e8ff4 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -45,9 +45,10 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const SSqlRes *pRes = &pSql->res; pSql->signature = pSql; - pSql->pTscObj = pObj; - pSql->fp = fp; pSql->param = param; + pSql->pTscObj = pObj; + pSql->maxRetry = TSDB_VNODES_SUPPORT; + pSql->fp = fp; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("failed to malloc payload"); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 84850dd42c..2b60355d6e 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -269,8 +269,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { return; } else { tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry); - - pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; // todo move away + pSql->res.code = rpcMsg->code; // keep the previous error code if (pSql->retry > pSql->maxRetry) { tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry); @@ -327,7 +326,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { * There is not response callback function for submit response. * The actual inserted number of points is the first number. */ - if (rpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT_RSP) { + if (rpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT_RSP && pRes->pRsp != NULL) { SShellSubmitRspMsg *pMsg = (SShellSubmitRspMsg*)pRes->pRsp; pMsg->code = htonl(pMsg->code); pMsg->numOfRows = htonl(pMsg->numOfRows); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 641d0b449c..a5e18a6b8d 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -129,6 +129,8 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->pTscObj = pObj; pSql->signature = pSql; + pSql->maxRetry = TSDB_VNODES_SUPPORT; + tsem_init(&pSql->rspSem, 0, 0); pObj->pSql = pSql; From 2cb57add4acb8d8451d4fa02267db4721922d15f Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 16 Apr 2020 13:58:11 +0800 Subject: [PATCH 2/3] [td-98] cleanup taos env after shell quit --- src/client/src/tscSystem.c | 36 ++++++++++++++++++++++++++++++++- src/inc/taos.h | 1 + src/kit/shell/inc/shell.h | 2 +- src/kit/shell/src/shellEngine.c | 10 +++++---- src/kit/shell/src/shellLinux.c | 13 +++++++++--- src/kit/shell/src/shellMain.c | 2 +- src/util/src/hash.c | 19 ++++++++--------- 7 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ea4cf12f9d..0ce767926e 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -171,17 +171,51 @@ void taos_init_imp() { if(0 == tscEmbedded){ taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr); } + int64_t refreshTime = tsMetricMetaKeepTimer < tsMeterMetaKeepTimer ? tsMetricMetaKeepTimer : tsMeterMetaKeepTimer; refreshTime = refreshTime > 2 ? 2 : refreshTime; refreshTime = refreshTime < 1 ? 1 : refreshTime; - if (tscCacheHandle == NULL) tscCacheHandle = taosCacheInit(tscTmr, refreshTime); + if (tscCacheHandle == NULL) { + tscCacheHandle = taosCacheInit(tscTmr, refreshTime); + } tscTrace("client is initialized successfully"); } void taos_init() { pthread_once(&tscinit, taos_init_imp); } +void taos_cleanup() { + if (tscCacheHandle != NULL) { + taosCacheCleanup(tscCacheHandle); +// tscCacheHandle = NULL; + } + + if (tscQhandle != NULL) { + taosCleanUpScheduler(tscQhandle); + tscQhandle = NULL; + } + + taosCloseLogger(); + + if (pVnodeConn != NULL) { + rpcClose(pVnodeConn); + pVnodeConn = NULL; + } + + if (pTscMgmtConn != NULL) { + rpcClose(pTscMgmtConn); + pTscMgmtConn = NULL; + } + + if (tsGlobalConfig != NULL) { + tfree(tsGlobalConfig); + } + + taosMsleep(1000); + taosTmrCleanUp(tscTmr); +} + static int taos_options_imp(TSDB_OPTION option, const char *pStr) { SGlobalConfig *cfg = NULL; diff --git a/src/inc/taos.h b/src/inc/taos.h index 4a815d8ee5..419685bd07 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -52,6 +52,7 @@ typedef struct taosField { #endif DLL_EXPORT void taos_init(); +DLL_EXPORT void taos_cleanup(); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT void taos_close(TAOS *taos); diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index 0315aa1b27..fcc5e0a87c 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -71,7 +71,7 @@ extern void* shellLoopQuery(void* arg); extern void taos_error(TAOS* con); extern int regex_match(const char* s, const char* reg, int cflags); void shellReadCommand(TAOS* con, char command[]); -void shellRunCommand(TAOS* con, char* command); +int32_t shellRunCommand(TAOS* con, char* command); void shellRunCommandOnServer(TAOS* con, char command[]); void read_history(); void write_history(); diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index e291fdc551..69d0aa6a40 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -166,10 +166,10 @@ void shellReplaceCtrlChar(char *str) { *pstr = '\0'; } -void shellRunCommand(TAOS *con, char *command) { +int32_t shellRunCommand(TAOS *con, char *command) { /* If command is empty just return */ if (regex_match(command, "^[ \t;]*$", REG_EXTENDED)) { - return; + return 0; } /* Update the history vector. */ @@ -193,11 +193,11 @@ void shellRunCommand(TAOS *con, char *command) { if (regex_match(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { taos_close(con); write_history(); - exitShell(); + return -1; } else if (regex_match(command, "^[\t ]*clear[ \t;]*$", REG_EXTENDED | REG_ICASE)) { // If clear the screen. system("clear"); - return; + return 0; } else if (regex_match(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) { /* If source file. */ char *c_ptr = strtok(command, " ;"); @@ -209,6 +209,8 @@ void shellRunCommand(TAOS *con, char *command) { } else { shellRunCommandOnServer(con, command); } + + return 0; } void shellRunCommandOnServer(TAOS *con, char command[]) { diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index cdf59a7293..15cee042e9 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -295,6 +295,7 @@ void *shellLoopQuery(void *arg) { tscError("failed to malloc command"); return NULL; } + while (1) { // Read command from shell. @@ -304,11 +305,16 @@ void *shellLoopQuery(void *arg) { reset_terminal_mode(); // Run the command - shellRunCommand(con, command); + if (shellRunCommand(con, command) != 0) { + break; + } } + + tfree(command); + exitShell(); pthread_cleanup_pop(1); - + return NULL; } @@ -487,6 +493,7 @@ void showOnScreen(Command *cmd) { void cleanup_handler(void *arg) { tcsetattr(0, TCSANOW, &oldtio); } void exitShell() { - tcsetattr(0, TCSANOW, &oldtio); + /*int32_t ret =*/ tcsetattr(STDIN_FILENO, TCSANOW, &oldtio); + taos_cleanup(); exit(EXIT_SUCCESS); } diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 81a41453e8..b39fba285f 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } - /* Interupt handler. */ + /* Interrupt handler. */ struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); diff --git a/src/util/src/hash.c b/src/util/src/hash.c index f0a23ec093..6beb195d36 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -101,8 +101,6 @@ static void doUpdateHashTable(SHashObj *pHashObj, SHashNode *pNode) { if (pNode->next) { (pNode->next)->prev = pNode; } - - pTrace("key:%s %p update hash table", pNode->key, pNode); } /** @@ -153,18 +151,18 @@ static void taosHashTableResize(SHashObj *pHashObj) { SHashNode *pNode = NULL; SHashNode *pNext = NULL; - int32_t newSize = pHashObj->capacity << 1U; + int32_t newSize = pHashObj->capacity << 1u; if (newSize > HASH_MAX_CAPACITY) { - pTrace("current capacity:%d, maximum capacity:%d, no resize applied due to limitation is reached", - pHashObj->capacity, HASH_MAX_CAPACITY); +// pTrace("current capacity:%d, maximum capacity:%d, no resize applied due to limitation is reached", +// pHashObj->capacity, HASH_MAX_CAPACITY); return; } - int64_t st = taosGetTimestampUs(); +// int64_t st = taosGetTimestampUs(); SHashEntry **pNewEntry = realloc(pHashObj->hashList, sizeof(SHashEntry *) * newSize); if (pNewEntry == NULL) { - pTrace("cache resize failed due to out of memory, capacity remain:%d", pHashObj->capacity); +// pTrace("cache resize failed due to out of memory, capacity remain:%d", pHashObj->capacity); return; } @@ -230,10 +228,9 @@ static void taosHashTableResize(SHashObj *pHashObj) { } } - int64_t et = taosGetTimestampUs(); - - pTrace("hash table resize completed, new capacity:%d, load factor:%f, elapsed time:%fms", pHashObj->capacity, - ((double)pHashObj->size) / pHashObj->capacity, (et - st) / 1000.0); +// int64_t et = taosGetTimestampUs(); +// pTrace("hash table resize completed, new capacity:%d, load factor:%f, elapsed time:%fms", pHashObj->capacity, +// ((double)pHashObj->size) / pHashObj->capacity, (et - st) / 1000.0); } /** From ff67258287b340bcb670fb2acc594e0fac19d2cf Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 16 Apr 2020 15:17:13 +0800 Subject: [PATCH 3/3] [td-98] do not sleep during shell quit --- src/client/src/tscSystem.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 0ce767926e..46f04b60c8 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -188,7 +188,6 @@ void taos_init() { pthread_once(&tscinit, taos_init_imp); } void taos_cleanup() { if (tscCacheHandle != NULL) { taosCacheCleanup(tscCacheHandle); -// tscCacheHandle = NULL; } if (tscQhandle != NULL) { @@ -212,7 +211,6 @@ void taos_cleanup() { tfree(tsGlobalConfig); } - taosMsleep(1000); taosTmrCleanUp(tscTmr); }