From f40383e4eff6fee404b580bae4c7a5e051bcefdf Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 13 Mar 2022 14:32:42 +0800 Subject: [PATCH] rename files --- source/dnode/mgmt/dnode/inc/dndInt.h | 7 +- .../dnode/mgmt/{impl => dnode}/inc/dndMgmt.h | 8 +- source/dnode/mgmt/dnode/inc/dndMonitor.h | 31 ++ source/dnode/mgmt/dnode/src/dndInt.c | 11 +- source/dnode/mgmt/dnode/src/dndMain.c | 268 +++++++++++------- .../dnode/mgmt/{impl => dnode}/src/dndMgmt.c | 2 - source/dnode/mgmt/dnode/src/dndMonitor.c | 29 ++ 7 files changed, 229 insertions(+), 127 deletions(-) rename source/dnode/mgmt/{impl => dnode}/inc/dndMgmt.h (92%) create mode 100644 source/dnode/mgmt/dnode/inc/dndMonitor.h rename source/dnode/mgmt/{impl => dnode}/src/dndMgmt.c (99%) create mode 100644 source/dnode/mgmt/dnode/src/dndMonitor.c diff --git a/source/dnode/mgmt/dnode/inc/dndInt.h b/source/dnode/mgmt/dnode/inc/dndInt.h index e8e2e5953b..907890cd23 100644 --- a/source/dnode/mgmt/dnode/inc/dndInt.h +++ b/source/dnode/mgmt/dnode/inc/dndInt.h @@ -59,7 +59,7 @@ typedef enum { MNODE, NODE_MAX, VNODES, QNODE, SNODE, BNODE } ENodeType; typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType; typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus; typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType; -typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANU } EEnvStat; +typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStat; typedef struct SMgmtFp SMgmtFp; typedef struct SMgmtWrapper SMgmtWrapper; @@ -68,7 +68,7 @@ typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps); typedef int32_t (*MndMsgFp)(SDnode *pDnode, SMndMsg *pMsg); typedef SMgmtWrapper *(*MgmtOpenFp)(SDnode *pDnode, const char *path); typedef void (*MgmtCloseFp)(SDnode *pDnode, SMgmtWrapper *pMgmt); -typedef bool (*MgmtRequiredFp)(SDnode *pDnode, const char *path); +typedef bool (*MgmtRequiredFp)(SMgmtWrapper *pMgmt); typedef SArray *(*MgmtMsgFp)(SMgmtWrapper *pNode, SNodeMsg *pMsg); typedef struct { @@ -192,6 +192,7 @@ typedef struct SMgmtWrapper { SProcObj *pProc; void *pMgmt; SMgmtFp fp; + SDnode *pDnode; } SMgmtWrapper; typedef struct SDnode { @@ -203,6 +204,7 @@ typedef struct SDnode { TdFilePtr pLockFile; SDnodeMgmt dmgmt; STransMgmt tmgmt; + STfs *pTfs; SMgmtFp fps[NODE_MAX]; SMgmtWrapper mgmts[NODE_MAX]; } SDnode; @@ -213,7 +215,6 @@ const char *dndStatStr(EDndStatus stat); void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc); void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup); TdFilePtr dndCheckRunning(char *dataDir); -int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/inc/dndMgmt.h b/source/dnode/mgmt/dnode/inc/dndMgmt.h similarity index 92% rename from source/dnode/mgmt/impl/inc/dndMgmt.h rename to source/dnode/mgmt/dnode/inc/dndMgmt.h index 9cc0c4ae66..a9a114fb69 100644 --- a/source/dnode/mgmt/impl/inc/dndMgmt.h +++ b/source/dnode/mgmt/dnode/inc/dndMgmt.h @@ -13,13 +13,13 @@ * along with this program. If not, see . */ -#ifndef _TD_DND_DNODE_H_ -#define _TD_DND_DNODE_H_ +#ifndef _TD_DND_MGMT_H_ +#define _TD_DND_MGMT_H_ #ifdef __cplusplus extern "C" { #endif -#include "dndEnv.h" +#include "dndInt.h.h" int32_t dndInitMgmt(SDnode *pDnode); void dndStopMgmt(SDnode *pDnode); @@ -39,4 +39,4 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); } #endif -#endif /*_TD_DND_DNODE_H_*/ \ No newline at end of file +#endif /*_TD_DND_MGMT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/dnode/inc/dndMonitor.h b/source/dnode/mgmt/dnode/inc/dndMonitor.h new file mode 100644 index 0000000000..a153d5f975 --- /dev/null +++ b/source/dnode/mgmt/dnode/inc/dndMonitor.h @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +#ifndef _TD_DND_MONITOR_H_ +#define _TD_DND_MONITOR_H_ + +#include "dndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_MONITOR_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/dnode/src/dndInt.c b/source/dnode/mgmt/dnode/src/dndInt.c index d47b2d3a42..cd6fee812c 100644 --- a/source/dnode/mgmt/dnode/src/dndInt.c +++ b/source/dnode/mgmt/dnode/src/dndInt.c @@ -72,12 +72,7 @@ TdFilePtr dndCheckRunning(char *dataDir) { return pFile; } -int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) { - tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); - pInfo->logdir.size = tsLogSpace.size; - tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name)); - pInfo->tempdir.size = tsTempSpace.size; - - //return tfsGetMonitorInfo(pDnode->pTfs, pInfo); - return tfsGetMonitorInfo(NULL, pInfo); +void dndeHandleEvent(SDnode *pDnode, EDndEvent event) { + dInfo("dnode object receive event %d, data:%p", event, pDnode); + pDnode->event = event; } diff --git a/source/dnode/mgmt/dnode/src/dndMain.c b/source/dnode/mgmt/dnode/src/dndMain.c index 385cb698ea..20f65989a1 100644 --- a/source/dnode/mgmt/dnode/src/dndMain.c +++ b/source/dnode/mgmt/dnode/src/dndMain.c @@ -14,135 +14,194 @@ */ #define _DEFAULT_SOURCE -#include "dndBnode.h" -#include "dndMgmt.h" -#include "mm.h" -#include "dndQnode.h" -#include "dndSnode.h" -#include "dndTransport.h" -#include "dndVnodes.h" -#include "monitor.h" -#include "sync.h" -#include "tfs.h" -#include "wal.h" +#include "dndMain.h" +// #include "dndBnode.h" +// #include "dndMgmt.h" +// #include "mm.h" +// #include "dndQnode.h" +// #include "dndSnode.h" +// #include "dndTransport.h" +// #include "dndVnodes.h" +// #include "monitor.h" +// #include "sync.h" +// #include "tfs.h" +// #include "wal.h" static int8_t once = DND_ENV_INIT; -static int32_t dndInitDir(SDnode *pDnode, SDndCfg *pCfg) { - pDnode->pLockFile = dndCheckRunning(pCfg->dataDir); - if (pDnode->pLockFile == NULL) { - return -1; - } +SMgmtFp mmGetNodeFp() { + SMgmtFp nullFp = {0}; + return nullFp; +} - char path[PATH_MAX + 100]; - snprintf(path, sizeof(path), "%s%smnode", pCfg->dataDir, TD_DIRSEP); - pDnode->dir.mnode = tstrdup(path); - snprintf(path, sizeof(path), "%s%svnode", pCfg->dataDir, TD_DIRSEP); - pDnode->dir.vnodes = tstrdup(path); - snprintf(path, sizeof(path), "%s%sdnode", pCfg->dataDir, TD_DIRSEP); - pDnode->dir.dnode = tstrdup(path); - snprintf(path, sizeof(path), "%s%ssnode", pCfg->dataDir, TD_DIRSEP); - pDnode->dir.snode = tstrdup(path); - snprintf(path, sizeof(path), "%s%sbnode", pCfg->dataDir, TD_DIRSEP); - pDnode->dir.bnode = tstrdup(path); - - if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL || - pDnode->dir.snode == NULL || pDnode->dir.bnode == NULL) { - dError("failed to malloc dir object"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; +SMgmtFp vndGetNodeFp() { + SMgmtFp nullFp = {0}; + return nullFp; +} + +SMgmtFp qndGetNodeFp() { + SMgmtFp nullFp = {0}; + return nullFp; +} + +SMgmtFp sndGetNodeFp() { + SMgmtFp nullFp = {0}; + return nullFp; +} + +SMgmtFp bndGetNodeFp() { + SMgmtFp nullFp = {0}; + return nullFp; +} + +static void dndResetLog(SMgmtWrapper *pMgmt) { + char logname[24] = {0}; + snprintf(logname, sizeof(logname), "%slog", pMgmt->name); + + dInfo("node:%s, reset log to %s", pMgmt->name, logname); + taosCloseLog(); + taosInitLog(logname, 1); +} + +static bool dndRequireOpenNode(SMgmtWrapper *pMgmt) { + bool required = (*pMgmt->fp.requiredFp)(pMgmt); + if (!required) { + dDebug("node:%s, no need to start on this dnode", pMgmt->name); + } else { + dDebug("node:%s, need to start on this dnode", pMgmt->name); } + return required; +} - if (taosMkDir(pDnode->dir.dnode) != 0) { - dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; +static void dndClearDnodeMem(SDnode *pDnode) { + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pMgmt = &pDnode->mgmts[n]; + tfree(pMgmt->path); } + if (pDnode->pLockFile != NULL) { + taosUnLockFile(pDnode->pLockFile); + taosCloseFile(&pDnode->pLockFile); + } + dDebug("dnode object memory is cleared, data:%p", pDnode); +} - if (taosMkDir(pDnode->dir.mnode) != 0) { - dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; +static int32_t dndInitDnodeResource(SDnode *pDnode) { + SDiskCfg dCfg = {0}; + tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN); + dCfg.level = 0; + dCfg.primary = 1; + SDiskCfg *pDisks = pDnode->cfg.pDisks; + int32_t numOfDisks = pDnode->cfg.numOfDisks; + if (numOfDisks <= 0 || pDisks == NULL) { + pDisks = &dCfg; + numOfDisks = 1; } - if (taosMkDir(pDnode->dir.vnodes) != 0) { - dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + pDnode->pTfs = tfsOpen(pDisks, numOfDisks); + if (pDnode->pTfs == NULL) { + dError("failed to init tfs since %s", terrstr()); return -1; } - if (taosMkDir(pDnode->dir.snode) != 0) { - dError("failed to create dir:%s since %s", pDnode->dir.snode, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + if (dndInitMgmt(pDnode) != 0) { + dError("failed to init mgmt since %s", terrstr()); return -1; } - if (taosMkDir(pDnode->dir.bnode) != 0) { - dError("failed to create dir:%s since %s", pDnode->dir.bnode, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + if (dndInitTrans(pDnode) != 0) { + dError("failed to init transport since %s", terrstr()); return -1; } - memcpy(&pDnode->cfg, pCfg, sizeof(SDndCfg)); + dndSetStatus(pDnode, DND_STAT_RUNNING); + dndSendStatusReq(pDnode); + dndReportStartup(pDnode, "TDengine", "initialized successfully"); return 0; } -static void dndCloseDir(SDnode *pDnode) { - tfree(pDnode->dir.mnode); - tfree(pDnode->dir.vnodes); - tfree(pDnode->dir.dnode); - tfree(pDnode->dir.snode); - tfree(pDnode->dir.bnode); - - if (pDnode->pLockFile != NULL) { - taosUnLockFile(pDnode->pLockFile); - taosCloseFile(&pDnode->pLockFile); - pDnode->pLockFile = NULL; - } +static void dndClearDnodeResource(SDnode *pDnode) { + dndCleanupTrans(pDnode); + dndStopMgmt(pDnode); + tfsClose(pDnode->pTfs); + dDebug("dnode object resource is cleared, data:%p", pDnode); } SDnode *dndCreate(SDndCfg *pCfg) { dInfo("start to create dnode object"); + int32_t code = -1; + char path[PATH_MAX + 100]; + SDnode *pDnode = NULL; - SDnode *pDnode = calloc(1, sizeof(SDnode)); + pDnode = calloc(1, sizeof(SDnode)); if (pDnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - dError("failed to create dnode object since %s", terrstr()); - return NULL; + goto _OVER; } dndSetStatus(pDnode, DND_STAT_INIT); + pDnode->mgmts[MNODE].fp = mmGetNodeFp(); + pDnode->mgmts[VNODES].fp = vndGetNodeFp(); + pDnode->mgmts[QNODE].fp = qndGetNodeFp(); + pDnode->mgmts[SNODE].fp = sndGetNodeFp(); + pDnode->mgmts[BNODE].fp = bndGetNodeFp(); + pDnode->mgmts[MNODE].name = "mnode"; + pDnode->mgmts[VNODES].name = "vnodes"; + pDnode->mgmts[QNODE].name = "qnode"; + pDnode->mgmts[SNODE].name = "snode"; + pDnode->mgmts[BNODE].name = "bnode"; + memcpy(&pDnode->cfg, pCfg, sizeof(SDndCfg)); - if (dndInitDir(pDnode, pCfg) != 0) { - dError("failed to init dnode dir since %s", terrstr()); - dndClose(pDnode); - return NULL; + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pMgmt = &pDnode->mgmts[n]; + snprintf(path, sizeof(path), "%s%s%s", pCfg->dataDir, TD_DIRSEP, pDnode->mgmts[n].name); + pMgmt->path = strdup(path); + if (pDnode->mgmts[n].path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + pMgmt->procType = PROC_SINGLE; + pMgmt->required = dndRequireOpenNode(pMgmt); + if (pMgmt->required) { + if (taosMkDir(pMgmt->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to create dir:%s since %s", pMgmt->path, terrstr()); + goto _OVER; + } + } } - SDiskCfg dCfg = {0}; - tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN); - dCfg.level = 0; - dCfg.primary = 1; - SDiskCfg *pDisks = pDnode->cfg.pDisks; - int32_t numOfDisks = pDnode->cfg.numOfDisks; - if (numOfDisks <= 0 || pDisks == NULL) { - pDisks = &dCfg; - numOfDisks = 1; + pDnode->pLockFile = dndCheckRunning(pCfg->dataDir); + if (pDnode->pLockFile == NULL) { + goto _OVER; } - pDnode->pTfs = tfsOpen(pDisks, numOfDisks); - if (pDnode->pTfs == NULL) { - dError("failed to init tfs since %s", terrstr()); - dndClose(pDnode); - return NULL; + snprintf(path, sizeof(path), "%s%sdnode", pCfg->dataDir, TD_DIRSEP); + if (taosMkDir(path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to create dir:%s since %s", path, terrstr()); + goto _OVER; } - if (dndInitMgmt(pDnode) != 0) { - dError("failed to init mgmt since %s", terrstr()); - dndClose(pDnode); - return NULL; +_OVER: + if (code != 0 && pDnode) { + dndClearDnodeMem(pDnode); + tfree(pDnode); + dError("failed to create dnode object since %s", terrstr()); + } else { + dInfo("dnode object is created, data:%p", pDnode); } + return pDnode; +} + +#if 0 + + + + + + if (dndInitVnodes(pDnode) != 0) { dError("failed to init vnodes since %s", terrstr()); dndClose(pDnode); @@ -173,19 +232,18 @@ SDnode *dndCreate(SDndCfg *pCfg) { return NULL; } - if (dndInitTrans(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - dndClose(pDnode); - return NULL; - } - dndSetStatus(pDnode, DND_STAT_RUNNING); - dndSendStatusReq(pDnode); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); - dInfo("dnode object is created, data:%p", pDnode); +// mmCleanup(pDnode); + // dndCleanupBnode(pDnode); + // dndCleanupSnode(pDnode); + // dndCleanupQnode(pDnode); + // dndCleanupVnodes(pDnode); + // dndCleanupMgmt(pDnode); + return pDnode; } +#endif void dndClose(SDnode *pDnode) { if (pDnode == NULL) return; @@ -197,18 +255,10 @@ void dndClose(SDnode *pDnode) { dInfo("start to close dnode, data:%p", pDnode); dndSetStatus(pDnode, DND_STAT_STOPPED); - dndCleanupTrans(pDnode); - dndStopMgmt(pDnode); - mmCleanup(pDnode); - dndCleanupBnode(pDnode); - dndCleanupSnode(pDnode); - dndCleanupQnode(pDnode); - dndCleanupVnodes(pDnode); - dndCleanupMgmt(pDnode); - tfsClose(pDnode->pTfs); - dndCloseDir(pDnode); - free(pDnode); + dndClearDnodeResource(pDnode); + dndClearDnodeMem(pDnode); + tfree(pDnode); dInfo("dnode object is closed, data:%p", pDnode); } @@ -275,5 +325,3 @@ void dndRun(SDnode *pDnode) { taosMsleep(100); } } - -void dndeHandleEvent(SDnode *pDnode, EDndEvent event) { pDnode->event = event; } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/src/dndMgmt.c b/source/dnode/mgmt/dnode/src/dndMgmt.c similarity index 99% rename from source/dnode/mgmt/impl/src/dndMgmt.c rename to source/dnode/mgmt/dnode/src/dndMgmt.c index 64fc1450f0..0276aa1564 100644 --- a/source/dnode/mgmt/impl/src/dndMgmt.c +++ b/source/dnode/mgmt/dnode/src/dndMgmt.c @@ -187,7 +187,6 @@ static int32_t dndReadDnodes(SDnode *pDnode) { char *content = calloc(1, maxLen + 1); cJSON *root = NULL; - // fp = fopen(pMgmt->file, "r"); TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_READ); if (pFile == NULL) { dDebug("file %s not exist", pMgmt->file); @@ -310,7 +309,6 @@ PRASE_DNODE_OVER: static int32_t dndWriteDnodes(SDnode *pDnode) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; - // FILE *fp = fopen(pMgmt->file, "w"); TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { dError("failed to write %s since %s", pMgmt->file, strerror(errno)); diff --git a/source/dnode/mgmt/dnode/src/dndMonitor.c b/source/dnode/mgmt/dnode/src/dndMonitor.c new file mode 100644 index 0000000000..b5929427d9 --- /dev/null +++ b/source/dnode/mgmt/dnode/src/dndMonitor.c @@ -0,0 +1,29 @@ +/* + * 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 "dndMonitor.h" + +int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) { + tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); + pInfo->logdir.size = tsLogSpace.size; + tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name)); + pInfo->tempdir.size = tsTempSpace.size; + + if (pDnode->pTfs != NULL) { + return tfsGetMonitorInfo(NULL, pInfo); + } + return 0; +} -- GitLab