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

rename files

上级 6c8cf998
......@@ -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
}
......
......@@ -13,13 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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
/*
* 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) {
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;
}
......@@ -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
......@@ -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));
......
/*
* 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.
先完成此消息的编辑!
想要评论请 注册