提交 de175185 编写于 作者: S Shengliang Guan

refactror: node mgmt

上级 8e61859d
...@@ -163,14 +163,14 @@ static SDnodeOpt dmGetOpt() { ...@@ -163,14 +163,14 @@ static SDnodeOpt dmGetOpt() {
static int32_t dmInitLog() { static int32_t dmInitLog() {
char logName[12] = {0}; char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); snprintf(logName, sizeof(logName), "%slog", dmNodeLogName(global.ntype));
return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0); return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
} }
static void dmSetProcInfo(int32_t argc, char **argv) { static void dmSetProcInfo(int32_t argc, char **argv) {
taosSetProcPath(argc, argv); taosSetProcPath(argc, argv);
if (global.ntype != DNODE && global.ntype != NODE_END) { if (global.ntype != DNODE && global.ntype != NODE_END) {
const char *name = dmProcName(global.ntype); const char *name = dmNodeProcName(global.ntype);
taosSetProcName(argc, argv, name); taosSetProcName(argc, argv, name);
} }
} }
......
...@@ -111,7 +111,7 @@ typedef struct SMgmtWrapper { ...@@ -111,7 +111,7 @@ typedef struct SMgmtWrapper {
char *path; char *path;
int32_t refCount; int32_t refCount;
SRWLatch latch; SRWLatch latch;
EDndNodeType ntype; EDndNodeType nodeType;
bool deployed; bool deployed;
bool required; bool required;
SMgmtFp fp; SMgmtFp fp;
......
...@@ -26,12 +26,13 @@ extern "C" { ...@@ -26,12 +26,13 @@ extern "C" {
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType); SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper); int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
void dmReleaseWrapper(SMgmtWrapper *pWrapper); void dmReleaseWrapper(SMgmtWrapper *pWrapper);
const char *dmStatName(EDndRunStatus stat); const char *dmStatStr(EDndRunStatus stype);
const char *dmLogName(EDndNodeType ntype); const char *dmNodeLogName(EDndNodeType ntype);
const char *dmProcName(EDndNodeType ntype); const char *dmNodeProcName(EDndNodeType ntype);
const char *dmEventName(EDndEvent ev); const char *dmEventStr(EDndEvent etype);
const char *dmProcStr(EDndProcType ptype);
void dmSetStatus(SDnode *pDnode, EDndRunStatus stat); void dmSetStatus(SDnode *pDnode, EDndRunStatus stype);
void dmSetEvent(SDnode *pDnode, EDndEvent event); void dmSetEvent(SDnode *pDnode, EDndEvent event);
void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
......
...@@ -173,7 +173,7 @@ int32_t dmReadShmFile(SMgmtWrapper *pWrapper) { ...@@ -173,7 +173,7 @@ int32_t dmReadShmFile(SMgmtWrapper *pWrapper) {
} }
} }
if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) { if (!tsMultiProcess || pWrapper->nodeType == DNODE || pWrapper->nodeType == NODE_END) {
if (pWrapper->procShm.id >= 0) { if (pWrapper->procShm.id >= 0) {
dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
taosDropShm(&pWrapper->procShm); taosDropShm(&pWrapper->procShm);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "dmInt.h"
const char *dmStatStr(EDndRunStatus stype) {
switch (stype) {
case DND_STAT_INIT:
return "init";
case DND_STAT_RUNNING:
return "running";
case DND_STAT_STOPPED:
return "stopped";
default:
return "UNKNOWN";
}
}
const char *dmNodeLogName(EDndNodeType ntype) {
switch (ntype) {
case VNODE:
return "vnode";
case QNODE:
return "qnode";
case SNODE:
return "snode";
case MNODE:
return "mnode";
case BNODE:
return "bnode";
default:
return "taosd";
}
}
const char *dmNodeProcName(EDndNodeType ntype) {
switch (ntype) {
case VNODE:
return "taosv";
case QNODE:
return "taosq";
case SNODE:
return "taoss";
case MNODE:
return "taosm";
case BNODE:
return "taosb";
default:
return "taosd";
}
}
const char *dmEventStr(EDndEvent ev) {
switch (ev) {
case DND_EVENT_START:
return "start";
case DND_EVENT_STOP:
return "stop";
case DND_EVENT_CHILD:
return "child";
default:
return "UNKNOWN";
}
}
const char *dmProcStr(EDndProcType etype) {
switch (etype) {
case DND_PROC_SINGLE:
return "start";
case DND_PROC_CHILD:
return "stop";
case DND_PROC_PARENT:
return "child";
case DND_PROC_TEST:
return "test";
default:
return "UNKNOWN";
}
}
...@@ -16,69 +16,9 @@ ...@@ -16,69 +16,9 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmInt.h" #include "dmInt.h"
const char *dmStatName(EDndRunStatus 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 *dmLogName(EDndNodeType ntype) {
switch (ntype) {
case VNODE:
return "vnode";
case QNODE:
return "qnode";
case SNODE:
return "snode";
case MNODE:
return "mnode";
case BNODE:
return "bnode";
default:
return "taosd";
}
}
const char *dmProcName(EDndNodeType ntype) {
switch (ntype) {
case VNODE:
return "taosv";
case QNODE:
return "taosq";
case SNODE:
return "taoss";
case MNODE:
return "taosm";
case BNODE:
return "taosb";
default:
return "taosd";
}
}
const char *dmEventName(EDndEvent ev) {
switch (ev) {
case DND_EVENT_START:
return "start";
case DND_EVENT_STOP:
return "stop";
case DND_EVENT_CHILD:
return "child";
default:
return "UNKNOWN";
}
}
void dmSetStatus(SDnode *pDnode, EDndRunStatus status) { void dmSetStatus(SDnode *pDnode, EDndRunStatus status) {
if (pDnode->status != status) { if (pDnode->status != status) {
dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status)); dDebug("dnode status set from %s to %s", dmStatStr(pDnode->status), dmStatStr(status));
pDnode->status = status; pDnode->status = status;
} }
} }
......
...@@ -27,21 +27,21 @@ static bool dmRequireNode(SMgmtWrapper *pWrapper) { ...@@ -27,21 +27,21 @@ static bool dmRequireNode(SMgmtWrapper *pWrapper) {
static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) { static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) {
int32_t shmsize = tsMnodeShmSize; int32_t shmsize = tsMnodeShmSize;
if (pWrapper->ntype == VNODE) { if (pWrapper->nodeType == VNODE) {
shmsize = tsVnodeShmSize; shmsize = tsVnodeShmSize;
} else if (pWrapper->ntype == QNODE) { } else if (pWrapper->nodeType == QNODE) {
shmsize = tsQnodeShmSize; shmsize = tsQnodeShmSize;
} else if (pWrapper->ntype == SNODE) { } else if (pWrapper->nodeType == SNODE) {
shmsize = tsSnodeShmSize; shmsize = tsSnodeShmSize;
} else if (pWrapper->ntype == MNODE) { } else if (pWrapper->nodeType == MNODE) {
shmsize = tsMnodeShmSize; shmsize = tsMnodeShmSize;
} else if (pWrapper->ntype == BNODE) { } else if (pWrapper->nodeType == BNODE) {
shmsize = tsBnodeShmSize; shmsize = tsBnodeShmSize;
} else { } else {
return -1; return -1;
} }
if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) { if (taosCreateShm(&pWrapper->procShm, pWrapper->nodeType, shmsize) != 0) {
terrno = TAOS_SYSTEM_ERROR(terrno); terrno = TAOS_SYSTEM_ERROR(terrno);
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
return -1; return -1;
...@@ -86,7 +86,7 @@ static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) { ...@@ -86,7 +86,7 @@ static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) {
if (pWrapper->pDnode->ntype == NODE_END) { if (pWrapper->pDnode->ntype == NODE_END) {
dInfo("node:%s, should be started manually in child process", pWrapper->name); dInfo("node:%s, should be started manually in child process", pWrapper->name);
} else { } else {
if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) { if (dmNewNodeProc(pWrapper, pWrapper->nodeType) != 0) {
return -1; return -1;
} }
} }
...@@ -149,7 +149,7 @@ int32_t dmStartNode(SMgmtWrapper *pWrapper) { ...@@ -149,7 +149,7 @@ int32_t dmStartNode(SMgmtWrapper *pWrapper) {
dInfo("node:%s, not start in parent process", pWrapper->name); dInfo("node:%s, not start in parent process", pWrapper->name);
} else if (pWrapper->procType == DND_PROC_CHILD) { } else if (pWrapper->procType == DND_PROC_CHILD) {
dInfo("node:%s, start in child process", pWrapper->name); dInfo("node:%s, start in child process", pWrapper->name);
if (pWrapper->ntype != DNODE) { if (pWrapper->nodeType != DNODE) {
if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1; return -1;
......
...@@ -104,7 +104,7 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { ...@@ -104,7 +104,7 @@ SDnode *dmCreate(const SDnodeOpt *pOption) {
pWrapper->path = strdup(path); pWrapper->path = strdup(path);
pWrapper->procShm.id = -1; pWrapper->procShm.id = -1;
pWrapper->pDnode = pDnode; pWrapper->pDnode = pDnode;
pWrapper->ntype = n; pWrapper->nodeType = n;
pWrapper->procType = DND_PROC_SINGLE; pWrapper->procType = DND_PROC_SINGLE;
taosInitRWLatch(&pWrapper->latch); taosInitRWLatch(&pWrapper->latch);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册