From 1db01cf034019218b372efc4b5e0ac2f1c41d547 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 21 Jan 2021 11:17:17 +0800 Subject: [PATCH 1/3] TD-2805 --- src/balance/src/bnThread.c | 2 +- src/dnode/src/dnodeTelemetry.c | 2 +- src/plugins/http/src/httpServer.c | 5 ++++- src/plugins/monitor/src/monMain.c | 5 ++++- src/rpc/src/rpcTcp.c | 2 +- src/util/src/tcache.c | 4 +++- src/vnode/src/vnodeMain.c | 3 ++- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/balance/src/bnThread.c b/src/balance/src/bnThread.c index 84f8694fca..3931acd053 100644 --- a/src/balance/src/bnThread.c +++ b/src/balance/src/bnThread.c @@ -56,7 +56,7 @@ int32_t bnInitThread() { pthread_attr_destroy(&thattr); if (ret != 0) { - mError("failed to create balance thread since %s", strerror(errno)); + mError("failed to create balance thread since %s", strerror(ret)); return -1; } diff --git a/src/dnode/src/dnodeTelemetry.c b/src/dnode/src/dnodeTelemetry.c index ff9598ecc5..c63536818a 100644 --- a/src/dnode/src/dnodeTelemetry.c +++ b/src/dnode/src/dnodeTelemetry.c @@ -291,7 +291,7 @@ int32_t dnodeInitTelemetry() { int32_t code = pthread_create(&tsTelemetryThread, &attr, telemetryThread, NULL); pthread_attr_destroy(&attr); if (code != 0) { - dTrace("failed to create telemetry thread, reason:%s", strerror(errno)); + dTrace("failed to create telemetry thread, reason:%s", strerror(code)); } dInfo("dnode telemetry is initialized"); diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 4896d50c6c..2bb33ed777 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -60,7 +60,10 @@ void httpCleanUpConnect() { HttpServer *pServer = &tsHttpServer; if (pServer->pThreads == NULL) return; - pthread_join(pServer->thread, NULL); + if (taosCheckPthreadValid(pServer->thread) { + pthread_join(pServer->thread, NULL); + } + for (int32_t i = 0; i < pServer->numOfThreads; ++i) { HttpThread* pThread = pServer->pThreads + i; if (pThread != NULL) { diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index 9443b1ce12..3b0b6a2fef 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -246,7 +246,10 @@ void monStopSystem() { void monCleanupSystem() { tsMonitor.quiting = 1; monStopSystem(); - pthread_join(tsMonitor.thread, NULL); + if (taosCheckPthreadValid(tsMonitor.thread)) { + pthread_join(tsMonitor.thread, NULL); + } + if (tsMonitor.conn != NULL) { taos_close(tsMonitor.conn); tsMonitor.conn = NULL; diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index daf3bd86c1..6cdf3eff9a 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -154,7 +154,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread if (code == 0) { code = pthread_create(&pServerObj->thread, &thattr, taosAcceptTcpConnection, (void *)pServerObj); if (code != 0) { - tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); + tError("%s failed to create TCP accept thread(%s)", label, strerror(code)); } } diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 3afdf41d05..c0cc8ce339 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -510,7 +510,9 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { } pCacheObj->deleting = 1; - pthread_join(pCacheObj->refreshWorker, NULL); + if (taosCheckPthreadValid(pCacheObj->refreshWorker)) { + pthread_join(pCacheObj->refreshWorker, NULL); + } uInfo("cache:%s will be cleaned up", pCacheObj->name); doCleanupDataCache(pCacheObj); diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 5f6f3fe105..3e72562c55 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -201,6 +201,8 @@ int32_t vnodeOpen(int32_t vgId) { pthread_mutex_init(&pVnode->statusMutex, NULL); vnodeSetInitStatus(pVnode); + tsdbIncCommitRef(pVnode->vgId); + int32_t code = vnodeReadCfg(pVnode); if (code != TSDB_CODE_SUCCESS) { vnodeCleanUp(pVnode); @@ -297,7 +299,6 @@ int32_t vnodeOpen(int32_t vgId) { pVnode->events = NULL; vDebug("vgId:%d, vnode is opened in %s, pVnode:%p", pVnode->vgId, rootDir, pVnode); - tsdbIncCommitRef(pVnode->vgId); vnodeAddIntoHash(pVnode); From 29394ec81ff0a7baafdd940bb70b00e7da6b0421 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 21 Jan 2021 11:33:36 +0800 Subject: [PATCH 2/3] TD-2805 --- src/plugins/http/src/httpServer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 2bb33ed777..bc768788d8 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -60,7 +60,7 @@ void httpCleanUpConnect() { HttpServer *pServer = &tsHttpServer; if (pServer->pThreads == NULL) return; - if (taosCheckPthreadValid(pServer->thread) { + if (taosCheckPthreadValid(pServer->thread)) { pthread_join(pServer->thread, NULL); } From 34efc16820e3335c797e6ce63e0654991e3258c9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 21 Jan 2021 15:42:24 +0800 Subject: [PATCH 3/3] TD-2808 --- tests/tsim/src/simMain.c | 6 +++++- tests/tsim/src/simSystem.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 8f13254f68..f30442ef41 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -20,6 +20,7 @@ #undef TAOS_MEM_CHECK bool simAsyncQuery = false; +bool simExecSuccess = false; void simHandleSignal(int32_t signo) { simSystemCleanUp(); @@ -62,5 +63,8 @@ int32_t main(int32_t argc, char *argv[]) { simScriptList[++simScriptPos] = script; simExecuteScript(script); - return 0; + int32_t ret = simExecSuccess ? 0 : -1; + simError("execute result %d", ret); + + return ret; } \ No newline at end of file diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index bf47c56718..2a1048334a 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -21,6 +21,7 @@ #include "ttimer.h" #include "tutil.h" #include "tsocket.h" +#include "taoserror.h" #undef TAOS_MEM_CHECK SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; @@ -31,6 +32,8 @@ int32_t simDebugFlag = 135; void simCloseTaosdConnect(SScript *script); char simHostName[128]; +extern bool simExecSuccess; + char *simParseArbitratorName(char *varName) { static char hostName[140]; sprintf(hostName, "%s:%d", simHostName, 8000); @@ -118,10 +121,12 @@ SScript *simProcessCallOver(SScript *script) { if (script->type == SIM_SCRIPT_TYPE_MAIN) { simDebug("script:%s, is main script, set stop flag", script->fileName); if (script->killed) { + simExecSuccess = false; simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s", script->fileName, script->error); return NULL; } else { + simExecSuccess = true; simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX, script->fileName); simCloseTaosdConnect(script);