From dd94e2da5a2bdac6ce7ccb2dea91cefcf7463d17 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 29 Mar 2022 21:13:09 +0800 Subject: [PATCH] shm --- include/os/os.h | 3 ++ source/dnode/mgmt/main/exe/dndMain.c | 42 ++++++++++++------ source/dnode/mgmt/main/inc/dnd.h | 12 +++--- source/dnode/mgmt/main/src/dndInt.c | 13 ------ source/dnode/mgmt/main/src/dndStr.c | 64 ++++++++++++++++++++++++++++ source/util/src/tprocess.c | 4 -- 6 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 source/dnode/mgmt/main/src/dndStr.c diff --git a/include/os/os.h b/include/os/os.h index e7ce7d09ea..fa9d61b997 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -42,6 +42,9 @@ extern "C" { #include #include #include +#include +#include +#include #if defined(DARWIN) #else diff --git a/source/dnode/mgmt/main/exe/dndMain.c b/source/dnode/mgmt/main/exe/dndMain.c index 334d52d52b..634e2caa28 100644 --- a/source/dnode/mgmt/main/exe/dndMain.c +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -18,14 +18,15 @@ #include "tconfig.h" static struct { - bool dumpConfig; - bool generateGrant; - bool printAuth; - bool printVersion; - int8_t node; - char envFile[PATH_MAX]; - char apolloUrl[PATH_MAX]; - SDnode *pDnode; + bool dumpConfig; + bool generateGrant; + bool printAuth; + bool printVersion; + char envFile[PATH_MAX]; + char apolloUrl[PATH_MAX]; + SArray *pArgs; // SConfigPair + SDnode *pDnode; + ENodeType ntype; } global = {0}; static void dndSigintHandle(int signum, void *info, void *ctx) { @@ -64,7 +65,7 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { } else if (strcmp(argv[i], "-k") == 0) { global.generateGrant = true; } else if (strcmp(argv[i], "-n") == 0) { - global.node = atoi(argv[++i]); + global.ntype = atoi(argv[++i]); } else if (strcmp(argv[i], "-C") == 0) { global.dumpConfig = true; } else if (strcmp(argv[i], "-V") == 0) { @@ -97,7 +98,7 @@ static void dndDumpCfg() { cfgDumpCfg(pCfg, 0, 1); } -SDnodeOpt dndGetOpt() { +static SDnodeOpt dndGetOpt() { SConfig *pCfg = taosGetCfg(); SDnodeOpt option = {0}; @@ -113,6 +114,20 @@ SDnodeOpt dndGetOpt() { return option; } +static int32_t dndInitLog() { + char logName[12] = {0}; + snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); + return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); +} + +static void dndSetProcName(char **argv) { + if (global.ntype != 0) { + const char *name = dndNodeProcStr(global.ntype); + prctl(PR_SET_NAME, name); + strcpy(argv[0], name); + } +} + static int32_t dndRunDnode() { if (dndInit() != 0) { dError("failed to initialize environment since %s", terrstr()); @@ -162,12 +177,12 @@ int main(int argc, char const *argv[]) { return 0; } - if (taosCreateLog("taosdlog", 1, configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { - printf("failed to start since read log config error\n"); + if (dndInitLog() != 0) { + printf("failed to start since init log error\n"); return -1; } - if (taosInitCfg(configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { + if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { dError("failed to start since read config error"); return -1; } @@ -179,5 +194,6 @@ int main(int argc, char const *argv[]) { return 0; } + dndSetProcName((char **)argv); return dndRunDnode(); } diff --git a/source/dnode/mgmt/main/inc/dnd.h b/source/dnode/mgmt/main/inc/dnd.h index 57f127ec26..046200510d 100644 --- a/source/dnode/mgmt/main/inc/dnd.h +++ b/source/dnode/mgmt/main/inc/dnd.h @@ -131,11 +131,13 @@ typedef struct SDnode { SMgmtWrapper wrappers[NODE_MAX]; } SDnode; -EDndStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndSendMonitorReport(SDnode *pDnode); +const char *dndNodeLogStr(ENodeType ntype); +const char *dndNodeProcStr(ENodeType ntype); +EDndStatus dndGetStatus(SDnode *pDnode); +void dndSetStatus(SDnode *pDnode, EDndStatus stat); +void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId); +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dndSendMonitorReport(SDnode *pDnode); int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/main/src/dndInt.c b/source/dnode/mgmt/main/src/dndInt.c index 33d6bb0ee3..a9b1982138 100644 --- a/source/dnode/mgmt/main/src/dndInt.c +++ b/source/dnode/mgmt/main/src/dndInt.c @@ -80,19 +80,6 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) { } } -const char *dndStatStr(EDndStatus status) { - switch (status) { - case DND_STAT_INIT: - return "init"; - case DND_STAT_RUNNING: - return "running"; - case DND_STAT_STOPPED: - return "stopped"; - default: - return "unknown"; - } -} - void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { SStartupReq *pStartup = &pDnode->startup; tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); diff --git a/source/dnode/mgmt/main/src/dndStr.c b/source/dnode/mgmt/main/src/dndStr.c new file mode 100644 index 0000000000..00d8b0d6e0 --- /dev/null +++ b/source/dnode/mgmt/main/src/dndStr.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dndInt.h" + +const char *dndStatStr(EDndStatus status) { + switch (status) { + case DND_STAT_INIT: + return "init"; + case DND_STAT_RUNNING: + return "running"; + case DND_STAT_STOPPED: + return "stopped"; + default: + return "unknown"; + } +} + +const char *dndNodeLogStr(ENodeType ntype) { + switch (ntype) { + case VNODES: + return "vnode"; + case QNODE: + return "qnode"; + case SNODE: + return "snode"; + case MNODE: + return "mnode"; + case BNODE: + return "bnode"; + default: + return "taosd"; + } +} + +const char *dndNodeProcStr(ENodeType ntype) { + switch (ntype) { + case VNODES: + return "taosv"; + case QNODE: + return "taosq"; + case SNODE: + return "taoss"; + case MNODE: + return "taosm"; + case BNODE: + return "taosb"; + default: + return "taosd"; + } +} diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index b2d4d1eddc..86cec2d271 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -19,10 +19,6 @@ #include "tlog.h" #include "tqueue.h" -// todo -#include -#include - #define SHM_DEFAULT_SIZE (20 * 1024 * 1024) typedef void *(*ProcThreadFp)(void *param); -- GitLab