shm
This commit is contained in:
parent
35961a9c44
commit
a82511435a
|
@ -32,6 +32,7 @@ extern "C" {
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
|
#include "tprocess.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tthread.h"
|
#include "tthread.h"
|
||||||
|
@ -44,10 +45,8 @@ extern "C" {
|
||||||
#include "mnode.h"
|
#include "mnode.h"
|
||||||
#include "qnode.h"
|
#include "qnode.h"
|
||||||
#include "snode.h"
|
#include "snode.h"
|
||||||
#include "vnode.h"
|
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
#include "vnode.h"
|
||||||
#include "tprocess.h"
|
|
||||||
|
|
||||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||||
|
@ -56,19 +55,22 @@ extern "C" {
|
||||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
||||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
|
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_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 = 0, DND_ENV_READY = 1, DND_ENV_CLEANUP = 2 } EEnvStat;
|
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANU } EEnvStat;
|
||||||
typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps);
|
|
||||||
|
|
||||||
typedef int32_t (*MndMsgFp)(SDnode *pDnode, SMndMsg *pMnodeMsg);
|
typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps);
|
||||||
|
typedef int32_t (*MndMsgFp)(SDnode *pDnode, SMndMsg *pMsg);
|
||||||
|
|
||||||
EDndStatus dndGetStatus(SDnode *pDnode);
|
EDndStatus dndGetStatus(SDnode *pDnode);
|
||||||
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
||||||
const char *dndStatStr(EDndStatus stat);
|
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);
|
||||||
|
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,8 +155,6 @@ typedef struct SDnode {
|
||||||
EDndEvent event;
|
EDndEvent event;
|
||||||
} SDnode;
|
} SDnode;
|
||||||
|
|
||||||
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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 "dndInt.h"
|
||||||
|
|
||||||
|
EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; }
|
||||||
|
|
||||||
|
void dndSetStatus(SDnode *pDnode, EDndStatus status) {
|
||||||
|
if (pDnode->status != status) {
|
||||||
|
dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status));
|
||||||
|
pDnode->status = 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, char *pName, char *pDesc) {
|
||||||
|
SStartupReq *pStartup = &pDnode->startup;
|
||||||
|
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||||
|
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||||
|
pStartup->finished = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||||
|
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||||
|
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr dndCheckRunning(char *dataDir) {
|
||||||
|
char filepath[PATH_MAX] = {0};
|
||||||
|
snprintf(filepath, sizeof(filepath), "%s/.running", dataDir);
|
||||||
|
|
||||||
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to lock file:%s since %s, quit", filepath, terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = taosLockFile(pFile);
|
||||||
|
if (ret != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to lock file:%s since %s, quit", filepath, terrstr());
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -28,62 +28,6 @@
|
||||||
|
|
||||||
static int8_t once = DND_ENV_INIT;
|
static int8_t once = DND_ENV_INIT;
|
||||||
|
|
||||||
EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; }
|
|
||||||
|
|
||||||
void dndSetStatus(SDnode *pDnode, EDndStatus status) {
|
|
||||||
if (pDnode->status != status) {
|
|
||||||
dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status));
|
|
||||||
pDnode->status = 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, char *pName, char *pDesc) {
|
|
||||||
SStartupReq *pStartup = &pDnode->startup;
|
|
||||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
|
||||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
|
||||||
pStartup->finished = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
|
||||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
|
||||||
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TdFilePtr dndCheckRunning(char *dataDir) {
|
|
||||||
char filepath[PATH_MAX] = {0};
|
|
||||||
snprintf(filepath, sizeof(filepath), "%s/.running", dataDir);
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to lock file:%s since %s, quit", filepath, terrstr());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ret = taosLockFile(pFile);
|
|
||||||
if (ret != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to lock file:%s since %s, quit", filepath, terrstr());
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t dndInitDir(SDnode *pDnode, SDnodeObjCfg *pCfg) {
|
static int32_t dndInitDir(SDnode *pDnode, SDnodeObjCfg *pCfg) {
|
||||||
pDnode->pLockFile = dndCheckRunning(pCfg->dataDir);
|
pDnode->pLockFile = dndCheckRunning(pCfg->dataDir);
|
||||||
if (pDnode->pLockFile == NULL) {
|
if (pDnode->pLockFile == NULL) {
|
||||||
|
@ -326,15 +270,6 @@ void dndCleanup() {
|
||||||
dInfo("dnode env is cleaned up");
|
dInfo("dnode env is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndRun(SDnode *pDnode) {
|
void dndRun(SDnode *pDnode) {
|
||||||
while (pDnode->event != DND_EVENT_STOP) {
|
while (pDnode->event != DND_EVENT_STOP) {
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
|
|
Loading…
Reference in New Issue