From fa354b85e5bb5374bc304800d3dc91b9346e8fdc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 16:05:24 +0800 Subject: [PATCH 1/7] shm --- source/util/src/tprocess.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f18e7d5777..71f819dbc1 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -140,14 +140,16 @@ static void taosProcDestroySem(SProcQueue *pQueue) { pQueue->sem = NULL; } } +#endif static void taosProcCleanupQueue(SProcQueue *pQueue) { +#if 0 if (pQueue != NULL) { taosProcDestroyMutex(pQueue); taosProcDestroySem(pQueue); } -} #endif +} static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody, int32_t rawBodyLen, ProcFuncType ftype) { @@ -317,7 +319,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pChildQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + cstart, csize); pProc->pParentQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + pstart, psize); if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { - // taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pChildQueue); taosMemoryFree(pProc); return NULL; } @@ -370,7 +372,7 @@ static void taosProcThreadLoop(SProcObj *pProc) { freeBodyFp = pProc->parentFreeBodyFp; } - uDebug("proc:%s, start to get msg from queue:%p, isChild:%d", pProc->name, pQueue, pProc->isChild); + uDebug("proc:%s, start to get msg from queue:%p", pProc->name, pQueue); while (1) { int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype, mallocHeadFp, freeHeadFp, @@ -406,7 +408,7 @@ int32_t taosProcRun(SProcObj *pProc) { static void taosProcStop(SProcObj *pProc) { if (!taosCheckPthreadValid(pProc->thread)) return; - uDebug("proc:%s, start to join thread:%" PRId64 ", isChild:%d", pProc->name, pProc->thread, pProc->isChild); + uDebug("proc:%s, start to join thread:%" PRId64, pProc->name, pProc->thread); SProcQueue *pQueue; if (pProc->isChild) { pQueue = pProc->pChildQueue; @@ -421,9 +423,9 @@ void taosProcCleanup(SProcObj *pProc) { if (pProc != NULL) { uDebug("proc:%s, start to clean up", pProc->name); taosProcStop(pProc); + taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pParentQueue); uDebug("proc:%s, is cleaned up", pProc->name); - // taosProcCleanupQueue(pProc->pChildQueue); - // taosProcCleanupQueue(pProc->pParentQueue); taosMemoryFree(pProc); } } From be2ab1f4f82f3bbd2c051d8d8603ff1ac9f7257d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 16:16:24 +0800 Subject: [PATCH 2/7] shm --- source/util/src/tprocess.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index 71f819dbc1..1d41bd4a48 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -224,7 +224,6 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea taosThreadMutexLock(&pQueue->mutex); if (pQueue->total - pQueue->avail <= 0) { taosThreadMutexUnlock(&pQueue->mutex); - tsem_post(&pQueue->sem); terrno = TSDB_CODE_OUT_OF_SHM_MEM; return 0; } @@ -378,7 +377,7 @@ static void taosProcThreadLoop(SProcObj *pProc) { int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype, mallocHeadFp, freeHeadFp, mallocBodyFp, freeBodyFp); if (numOfMsgs == 0) { - uInfo("proc:%s, get no msg from queue:%p and exit the proc thread", pProc->name, pQueue); + uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pProc->name, pQueue); break; } else if (numOfMsgs < 0) { uTrace("proc:%s, get no msg from queue:%p since %s", pProc->name, pQueue, terrstr()); From 68f2911ce2657345166b8a11326516e03ba6467e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 16:19:26 +0800 Subject: [PATCH 3/7] rename files --- source/dnode/mgmt/main/src/{dndInt.c => dndEnv.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/dnode/mgmt/main/src/{dndInt.c => dndEnv.c} (100%) diff --git a/source/dnode/mgmt/main/src/dndInt.c b/source/dnode/mgmt/main/src/dndEnv.c similarity index 100% rename from source/dnode/mgmt/main/src/dndInt.c rename to source/dnode/mgmt/main/src/dndEnv.c From bee82c6ff936da4c6b406f49e3d1d940ae029e96 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 16:19:47 +0800 Subject: [PATCH 4/7] rename files --- source/dnode/mgmt/main/src/{dndObj.c => dndInt.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/dnode/mgmt/main/src/{dndObj.c => dndInt.c} (100%) diff --git a/source/dnode/mgmt/main/src/dndObj.c b/source/dnode/mgmt/main/src/dndInt.c similarity index 100% rename from source/dnode/mgmt/main/src/dndObj.c rename to source/dnode/mgmt/main/src/dndInt.c From 781d31d39f71747043fca9c23702cdfc7a824af5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 16:41:27 +0800 Subject: [PATCH 5/7] adjust log --- source/dnode/mgmt/main/src/dndExec.c | 2 +- source/util/src/tconfig.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index 2999a30d67..c5d5707a99 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -276,8 +276,8 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { } static int32_t dndRunInChildProcess(SDnode *pDnode) { - dInfo("dnode run in child process"); SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + dInfo("%s run in child process", pWrapper->name); SMsgCb msgCb = dndCreateMsgcb(pWrapper); tmsgSetDefaultMsgCb(&msgCb); diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 04061cbaf1..9101d3c7c8 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -590,12 +590,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { } int32_t cfgLoadFromEnvVar(SConfig *pConfig) { - uInfo("load from global env variables success"); + uInfo("load from global env variables not implemented yet"); return 0; } int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { - uInfo("load from env file [%s] success", filepath); + uInfo("load from env file not implemented yet"); return 0; } @@ -649,11 +649,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { taosCloseFile(&pFile); if (line != NULL) taosMemoryFreeClear(line); - uInfo("load from cfg file [%s] success", filepath); + uInfo("load from cfg file %s success", filepath); return 0; } int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { - uInfo("load from apoll url [%s] success", url); + uInfo("load from apoll url not implemented yet"); return 0; } From 651fb094076777aa87e127bdd48916246ba79065 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 17:27:04 +0800 Subject: [PATCH 6/7] handle sigchild --- source/dnode/mgmt/main/exe/dndMain.c | 9 +-------- source/dnode/mgmt/main/src/dndExec.c | 10 +++++----- source/os/src/osProc.c | 3 +++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/source/dnode/mgmt/main/exe/dndMain.c b/source/dnode/mgmt/main/exe/dndMain.c index 61b480990d..0d2ddbfbbc 100644 --- a/source/dnode/mgmt/main/exe/dndMain.c +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -37,13 +37,6 @@ static void dndStopDnode(int signum, void *info, void *ctx) { } } -static void dndHandleChild(int signum, void *info, void *ctx) { - dInfo("sigchild received"); - if (global.pDnode != NULL) { - dndHandleEvent(global.pDnode, DND_EVENT_CHILD); - } -} - static void dndSetSignalHandle() { taosSetSignal(SIGTERM, dndStopDnode); taosSetSignal(SIGHUP, dndStopDnode); @@ -53,7 +46,7 @@ static void dndSetSignalHandle() { if (!tsMultiProcess) { } else if (global.ntype == DNODE || global.ntype == NODE_MAX) { - taosSetSignal(SIGCHLD, dndHandleChild); + taosIgnSignal(SIGCHLD); } else { taosKillChildOnParentStopped(); } diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index c5d5707a99..76614b2916 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -128,7 +128,7 @@ static int32_t dndNewProc(SMgmtWrapper *pWrapper, ENodeType n) { } pWrapper->procId = pid; - dInfo("node:%s, run in new process, pid:%d", pWrapper->name, pid); + dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid); return 0; } @@ -263,13 +263,13 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { if (!pWrapper->required) continue; if (pDnode->ntype == NODE_MAX) continue; - if (pWrapper->procId != 0 && !taosProcExists(pWrapper->procId)) { - dInfo("node:%s, process not exist, pid:%d", pWrapper->name, pWrapper->procId); + if (pWrapper->procId <= 0 || !taosProcExists(pWrapper->procId)) { + dInfo("node:%s, process:%d does not exist or is killed and needs to be restarted", pWrapper->name, pWrapper->procId); dndNewProc(pWrapper, n); } - - taosMsleep(100); } + + taosMsleep(100); } return 0; diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c index 00ed650cbb..2d2174a4c8 100644 --- a/source/os/src/osProc.c +++ b/source/os/src/osProc.c @@ -23,6 +23,9 @@ int32_t taosNewProc(char **args) { int32_t pid = fork(); if (pid == 0) { args[0] = tsProcPath; + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); return execvp(tsProcPath, args); } else { return pid; From d89ab513758f652c776b886a390a86cce21db343 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 31 Mar 2022 17:38:47 +0800 Subject: [PATCH 7/7] minor changes --- source/dnode/mgmt/main/src/dndExec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index 76614b2916..fdc6125fb0 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -264,7 +264,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { if (pDnode->ntype == NODE_MAX) continue; if (pWrapper->procId <= 0 || !taosProcExists(pWrapper->procId)) { - dInfo("node:%s, process:%d does not exist or is killed and needs to be restarted", pWrapper->name, pWrapper->procId); + dInfo("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); dndNewProc(pWrapper, n); } }