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

rename files

上级 6c8cf998
...@@ -59,7 +59,7 @@ typedef enum { MNODE, NODE_MAX, VNODES, QNODE, SNODE, BNODE } ENodeType; ...@@ -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 { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType;
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus; typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus;
typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType; 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 SMgmtFp SMgmtFp;
typedef struct SMgmtWrapper SMgmtWrapper; typedef struct SMgmtWrapper SMgmtWrapper;
...@@ -68,7 +68,7 @@ typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps); ...@@ -68,7 +68,7 @@ typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps);
typedef int32_t (*MndMsgFp)(SDnode *pDnode, SMndMsg *pMsg); typedef int32_t (*MndMsgFp)(SDnode *pDnode, SMndMsg *pMsg);
typedef SMgmtWrapper *(*MgmtOpenFp)(SDnode *pDnode, const char *path); typedef SMgmtWrapper *(*MgmtOpenFp)(SDnode *pDnode, const char *path);
typedef void (*MgmtCloseFp)(SDnode *pDnode, SMgmtWrapper *pMgmt); 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 SArray *(*MgmtMsgFp)(SMgmtWrapper *pNode, SNodeMsg *pMsg);
typedef struct { typedef struct {
...@@ -192,6 +192,7 @@ typedef struct SMgmtWrapper { ...@@ -192,6 +192,7 @@ typedef struct SMgmtWrapper {
SProcObj *pProc; SProcObj *pProc;
void *pMgmt; void *pMgmt;
SMgmtFp fp; SMgmtFp fp;
SDnode *pDnode;
} SMgmtWrapper; } SMgmtWrapper;
typedef struct SDnode { typedef struct SDnode {
...@@ -203,6 +204,7 @@ typedef struct SDnode { ...@@ -203,6 +204,7 @@ typedef struct SDnode {
TdFilePtr pLockFile; TdFilePtr pLockFile;
SDnodeMgmt dmgmt; SDnodeMgmt dmgmt;
STransMgmt tmgmt; STransMgmt tmgmt;
STfs *pTfs;
SMgmtFp fps[NODE_MAX]; SMgmtFp fps[NODE_MAX];
SMgmtWrapper mgmts[NODE_MAX]; SMgmtWrapper mgmts[NODE_MAX];
} SDnode; } SDnode;
...@@ -213,7 +215,6 @@ const char *dndStatStr(EDndStatus stat); ...@@ -213,7 +215,6 @@ const char *dndStatStr(EDndStatus stat);
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc); void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc);
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup); void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
TdFilePtr dndCheckRunning(char *dataDir); TdFilePtr dndCheckRunning(char *dataDir);
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_DND_DNODE_H_ #ifndef _TD_DND_MGMT_H_
#define _TD_DND_DNODE_H_ #define _TD_DND_MGMT_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "dndEnv.h" #include "dndInt.h.h"
int32_t dndInitMgmt(SDnode *pDnode); int32_t dndInitMgmt(SDnode *pDnode);
void dndStopMgmt(SDnode *pDnode); void dndStopMgmt(SDnode *pDnode);
...@@ -39,4 +39,4 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); ...@@ -39,4 +39,4 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
} }
#endif #endif
#endif /*_TD_DND_DNODE_H_*/ #endif /*_TD_DND_MGMT_H_*/
\ No newline at end of file \ No newline at end of file
/*
* 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/>.
*/
#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
...@@ -72,12 +72,7 @@ TdFilePtr dndCheckRunning(char *dataDir) { ...@@ -72,12 +72,7 @@ TdFilePtr dndCheckRunning(char *dataDir) {
return pFile; return pFile;
} }
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) { void dndeHandleEvent(SDnode *pDnode, EDndEvent event) {
tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); dInfo("dnode object receive event %d, data:%p", event, pDnode);
pInfo->logdir.size = tsLogSpace.size; pDnode->event = event;
tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name));
pInfo->tempdir.size = tsTempSpace.size;
//return tfsGetMonitorInfo(pDnode->pTfs, pInfo);
return tfsGetMonitorInfo(NULL, pInfo);
} }
...@@ -14,135 +14,194 @@ ...@@ -14,135 +14,194 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndBnode.h" #include "dndMain.h"
#include "dndMgmt.h" // #include "dndBnode.h"
#include "mm.h" // #include "dndMgmt.h"
#include "dndQnode.h" // #include "mm.h"
#include "dndSnode.h" // #include "dndQnode.h"
#include "dndTransport.h" // #include "dndSnode.h"
#include "dndVnodes.h" // #include "dndTransport.h"
#include "monitor.h" // #include "dndVnodes.h"
#include "sync.h" // #include "monitor.h"
#include "tfs.h" // #include "sync.h"
#include "wal.h" // #include "tfs.h"
// #include "wal.h"
static int8_t once = DND_ENV_INIT; static int8_t once = DND_ENV_INIT;
static int32_t dndInitDir(SDnode *pDnode, SDndCfg *pCfg) { SMgmtFp mmGetNodeFp() {
pDnode->pLockFile = dndCheckRunning(pCfg->dataDir); SMgmtFp nullFp = {0};
if (pDnode->pLockFile == NULL) { return nullFp;
return -1; }
}
char path[PATH_MAX + 100]; SMgmtFp vndGetNodeFp() {
snprintf(path, sizeof(path), "%s%smnode", pCfg->dataDir, TD_DIRSEP); SMgmtFp nullFp = {0};
pDnode->dir.mnode = tstrdup(path); return nullFp;
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); SMgmtFp qndGetNodeFp() {
pDnode->dir.dnode = tstrdup(path); SMgmtFp nullFp = {0};
snprintf(path, sizeof(path), "%s%ssnode", pCfg->dataDir, TD_DIRSEP); return nullFp;
pDnode->dir.snode = tstrdup(path); }
snprintf(path, sizeof(path), "%s%sbnode", pCfg->dataDir, TD_DIRSEP);
pDnode->dir.bnode = tstrdup(path); SMgmtFp sndGetNodeFp() {
SMgmtFp nullFp = {0};
if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL || return nullFp;
pDnode->dir.snode == NULL || pDnode->dir.bnode == NULL) { }
dError("failed to malloc dir object");
terrno = TSDB_CODE_OUT_OF_MEMORY; SMgmtFp bndGetNodeFp() {
return -1; 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) { static void dndClearDnodeMem(SDnode *pDnode) {
dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno)); for (ENodeType n = 0; n < NODE_MAX; ++n) {
terrno = TAOS_SYSTEM_ERROR(errno); SMgmtWrapper *pMgmt = &pDnode->mgmts[n];
return -1; 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) { static int32_t dndInitDnodeResource(SDnode *pDnode) {
dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno)); SDiskCfg dCfg = {0};
terrno = TAOS_SYSTEM_ERROR(errno); tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN);
return -1; 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) { pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno)); if (pDnode->pTfs == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to init tfs since %s", terrstr());
return -1; return -1;
} }
if (taosMkDir(pDnode->dir.snode) != 0) { if (dndInitMgmt(pDnode) != 0) {
dError("failed to create dir:%s since %s", pDnode->dir.snode, strerror(errno)); dError("failed to init mgmt since %s", terrstr());
terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
if (taosMkDir(pDnode->dir.bnode) != 0) { if (dndInitTrans(pDnode) != 0) {
dError("failed to create dir:%s since %s", pDnode->dir.bnode, strerror(errno)); dError("failed to init transport since %s", terrstr());
terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
memcpy(&pDnode->cfg, pCfg, sizeof(SDndCfg)); dndSetStatus(pDnode, DND_STAT_RUNNING);
dndSendStatusReq(pDnode);
dndReportStartup(pDnode, "TDengine", "initialized successfully");
return 0; return 0;
} }
static void dndCloseDir(SDnode *pDnode) { static void dndClearDnodeResource(SDnode *pDnode) {
tfree(pDnode->dir.mnode); dndCleanupTrans(pDnode);
tfree(pDnode->dir.vnodes); dndStopMgmt(pDnode);
tfree(pDnode->dir.dnode); tfsClose(pDnode->pTfs);
tfree(pDnode->dir.snode); dDebug("dnode object resource is cleared, data:%p", pDnode);
tfree(pDnode->dir.bnode);
if (pDnode->pLockFile != NULL) {
taosUnLockFile(pDnode->pLockFile);
taosCloseFile(&pDnode->pLockFile);
pDnode->pLockFile = NULL;
}
} }
SDnode *dndCreate(SDndCfg *pCfg) { SDnode *dndCreate(SDndCfg *pCfg) {
dInfo("start to create dnode object"); 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) { if (pDnode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
dError("failed to create dnode object since %s", terrstr()); goto _OVER;
return NULL;
} }
dndSetStatus(pDnode, DND_STAT_INIT); 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) { for (ENodeType n = 0; n < NODE_MAX; ++n) {
dError("failed to init dnode dir since %s", terrstr()); SMgmtWrapper *pMgmt = &pDnode->mgmts[n];
dndClose(pDnode); snprintf(path, sizeof(path), "%s%s%s", pCfg->dataDir, TD_DIRSEP, pDnode->mgmts[n].name);
return NULL; pMgmt->path = strdup(path);
if (pDnode->mgmts[n].path == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
} }
SDiskCfg dCfg = {0}; pMgmt->procType = PROC_SINGLE;
tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN); pMgmt->required = dndRequireOpenNode(pMgmt);
dCfg.level = 0; if (pMgmt->required) {
dCfg.primary = 1; if (taosMkDir(pMgmt->path) != 0) {
SDiskCfg *pDisks = pDnode->cfg.pDisks; terrno = TAOS_SYSTEM_ERROR(errno);
int32_t numOfDisks = pDnode->cfg.numOfDisks; dError("failed to create dir:%s since %s", pMgmt->path, terrstr());
if (numOfDisks <= 0 || pDisks == NULL) { goto _OVER;
pDisks = &dCfg; }
numOfDisks = 1; }
} }
pDnode->pTfs = tfsOpen(pDisks, numOfDisks); pDnode->pLockFile = dndCheckRunning(pCfg->dataDir);
if (pDnode->pTfs == NULL) { if (pDnode->pLockFile == NULL) {
dError("failed to init tfs since %s", terrstr()); goto _OVER;
dndClose(pDnode);
return NULL;
} }
if (dndInitMgmt(pDnode) != 0) { snprintf(path, sizeof(path), "%s%sdnode", pCfg->dataDir, TD_DIRSEP);
dError("failed to init mgmt since %s", terrstr()); if (taosMkDir(path) != 0) {
dndClose(pDnode); terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; dError("failed to create dir:%s since %s", path, terrstr());
goto _OVER;
}
_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) { if (dndInitVnodes(pDnode) != 0) {
dError("failed to init vnodes since %s", terrstr()); dError("failed to init vnodes since %s", terrstr());
dndClose(pDnode); dndClose(pDnode);
...@@ -173,19 +232,18 @@ SDnode *dndCreate(SDndCfg *pCfg) { ...@@ -173,19 +232,18 @@ SDnode *dndCreate(SDndCfg *pCfg) {
return NULL; return NULL;
} }
if (dndInitTrans(pDnode) != 0) {
dError("failed to init transport since %s", terrstr());
dndClose(pDnode);
return NULL;
}
dndSetStatus(pDnode, DND_STAT_RUNNING); // mmCleanup(pDnode);
dndSendStatusReq(pDnode); // dndCleanupBnode(pDnode);
dndReportStartup(pDnode, "TDengine", "initialized successfully"); // dndCleanupSnode(pDnode);
dInfo("dnode object is created, data:%p", pDnode); // dndCleanupQnode(pDnode);
// dndCleanupVnodes(pDnode);
// dndCleanupMgmt(pDnode);
return pDnode; return pDnode;
} }
#endif
void dndClose(SDnode *pDnode) { void dndClose(SDnode *pDnode) {
if (pDnode == NULL) return; if (pDnode == NULL) return;
...@@ -197,18 +255,10 @@ void dndClose(SDnode *pDnode) { ...@@ -197,18 +255,10 @@ void dndClose(SDnode *pDnode) {
dInfo("start to close dnode, data:%p", pDnode); dInfo("start to close dnode, data:%p", pDnode);
dndSetStatus(pDnode, DND_STAT_STOPPED); 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); dndClearDnodeResource(pDnode);
free(pDnode); dndClearDnodeMem(pDnode);
tfree(pDnode);
dInfo("dnode object is closed, data:%p", pDnode); dInfo("dnode object is closed, data:%p", pDnode);
} }
...@@ -275,5 +325,3 @@ void dndRun(SDnode *pDnode) { ...@@ -275,5 +325,3 @@ void dndRun(SDnode *pDnode) {
taosMsleep(100); taosMsleep(100);
} }
} }
void dndeHandleEvent(SDnode *pDnode, EDndEvent event) { pDnode->event = event; }
\ No newline at end of file
...@@ -187,7 +187,6 @@ static int32_t dndReadDnodes(SDnode *pDnode) { ...@@ -187,7 +187,6 @@ static int32_t dndReadDnodes(SDnode *pDnode) {
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
cJSON *root = NULL; cJSON *root = NULL;
// fp = fopen(pMgmt->file, "r");
TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_READ); TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
dDebug("file %s not exist", pMgmt->file); dDebug("file %s not exist", pMgmt->file);
...@@ -310,7 +309,6 @@ PRASE_DNODE_OVER: ...@@ -310,7 +309,6 @@ PRASE_DNODE_OVER:
static int32_t dndWriteDnodes(SDnode *pDnode) { static int32_t dndWriteDnodes(SDnode *pDnode) {
SDnodeMgmt *pMgmt = &pDnode->dmgmt; SDnodeMgmt *pMgmt = &pDnode->dmgmt;
// FILE *fp = fopen(pMgmt->file, "w");
TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(pMgmt->file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
dError("failed to write %s since %s", pMgmt->file, strerror(errno)); dError("failed to write %s since %s", pMgmt->file, strerror(errno));
......
/*
* 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 "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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册