refactor: make more object global
This commit is contained in:
parent
d751ff6aaa
commit
34fd89aa23
|
@ -22,66 +22,23 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------------ TYPES EXPOSED ---------------- */
|
|
||||||
typedef struct SDnode SDnode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the environment
|
* @brief Initialize the dnode
|
||||||
*
|
*
|
||||||
|
* @param rtype for internal debug usage, default is 0
|
||||||
* @return int32_t 0 for success and -1 for failure
|
* @return int32_t 0 for success and -1 for failure
|
||||||
*/
|
*/
|
||||||
int32_t dmInit();
|
int32_t dmInit(int8_t rtype);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clear the environment
|
* @brief Cleanup the dnode
|
||||||
*/
|
*/
|
||||||
void dmCleanup();
|
void dmCleanup();
|
||||||
|
|
||||||
/* ------------------------ SDnode ----------------------- */
|
|
||||||
typedef struct {
|
|
||||||
int32_t numOfSupportVnodes;
|
|
||||||
uint16_t serverPort;
|
|
||||||
char dataDir[PATH_MAX];
|
|
||||||
char localEp[TSDB_EP_LEN];
|
|
||||||
char localFqdn[TSDB_FQDN_LEN];
|
|
||||||
char firstEp[TSDB_EP_LEN];
|
|
||||||
char secondEp[TSDB_EP_LEN];
|
|
||||||
SDiskCfg *disks;
|
|
||||||
int32_t numOfDisks;
|
|
||||||
int8_t ntype;
|
|
||||||
} SDnodeOpt;
|
|
||||||
|
|
||||||
typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize and start the dnode.
|
* @brief Run dnode.
|
||||||
*
|
|
||||||
* @param pOption Option of the dnode.
|
|
||||||
* @return SDnode* The dnode object.
|
|
||||||
*/
|
*/
|
||||||
SDnode *dmCreate(const SDnodeOpt *pOption);
|
int32_t dmRun();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stop and cleanup the dnode.
|
|
||||||
*
|
|
||||||
* @param pDnode The dnode object to close.
|
|
||||||
*/
|
|
||||||
void dmClose(SDnode *pDnode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Run dnode until specific event is receive.
|
|
||||||
*
|
|
||||||
* @param pDnode The dnode object to run.
|
|
||||||
*/
|
|
||||||
int32_t dmRun(SDnode *pDnode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handle event in the dnode.
|
|
||||||
*
|
|
||||||
* @param pDnode The dnode object to close.
|
|
||||||
* @param event The event to handle.
|
|
||||||
*/
|
|
||||||
void dmSetEvent(SDnode *pDnode, EDndEvent event);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,38 +87,28 @@ typedef enum {
|
||||||
DND_FUNC_RELEASE = 4,
|
DND_FUNC_RELEASE = 4,
|
||||||
} EProcFuncType;
|
} EProcFuncType;
|
||||||
|
|
||||||
typedef int32_t (*ProcessCreateNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SRpcMsg *pMsg);
|
typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
|
||||||
typedef int32_t (*ProcessDropNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SRpcMsg *pMsg);
|
typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
|
||||||
typedef bool (*IsNodeRequiredFp)(struct SDnode *pDnode, EDndNodeType ntype);
|
typedef bool (*IsNodeRequiredFp)(EDndNodeType ntype);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
int64_t clusterId;
|
int64_t clusterId;
|
||||||
int64_t dnodeVer;
|
int64_t dnodeVer;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
int64_t rebootTime;
|
int64_t rebootTime;
|
||||||
bool dropped;
|
bool dropped;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
SEpSet mnodeEps;
|
SEpSet mnodeEps;
|
||||||
SArray *dnodeEps;
|
SArray *dnodeEps;
|
||||||
SHashObj *dnodeHash;
|
SHashObj *dnodeHash;
|
||||||
SRWLatch latch;
|
SRWLatch latch;
|
||||||
SMsgCb msgCb;
|
SMsgCb msgCb;
|
||||||
const char *localEp;
|
|
||||||
const char *localFqdn;
|
|
||||||
const char *firstEp;
|
|
||||||
const char *secondEp;
|
|
||||||
int32_t supportVnodes;
|
|
||||||
uint16_t serverPort;
|
|
||||||
int32_t numOfDisks;
|
|
||||||
SDiskCfg *disks;
|
|
||||||
const char *dataDir;
|
|
||||||
} SDnodeData;
|
} SDnodeData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *path;
|
const char *path;
|
||||||
const char *name;
|
const char *name;
|
||||||
struct SDnode *pDnode;
|
|
||||||
SDnodeData *pData;
|
SDnodeData *pData;
|
||||||
SMsgCb msgCb;
|
SMsgCb msgCb;
|
||||||
ProcessCreateNodeFp processCreateNodeFp;
|
ProcessCreateNodeFp processCreateNodeFp;
|
||||||
|
@ -162,7 +152,6 @@ const char *dmStatStr(EDndRunStatus stype);
|
||||||
const char *dmNodeLogName(EDndNodeType ntype);
|
const char *dmNodeLogName(EDndNodeType ntype);
|
||||||
const char *dmNodeProcName(EDndNodeType ntype);
|
const char *dmNodeProcName(EDndNodeType ntype);
|
||||||
const char *dmNodeName(EDndNodeType ntype);
|
const char *dmNodeName(EDndNodeType ntype);
|
||||||
const char *dmEventStr(EDndEvent etype);
|
|
||||||
const char *dmProcStr(EDndProcType ptype);
|
const char *dmProcStr(EDndProcType ptype);
|
||||||
const char *dmFuncStr(EProcFuncType etype);
|
const char *dmFuncStr(EProcFuncType etype);
|
||||||
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
|
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
|
||||||
|
|
|
@ -54,7 +54,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json", pData->dataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = 0;
|
code = 0;
|
||||||
|
@ -158,14 +158,14 @@ _OVER:
|
||||||
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
||||||
SDnodeEp dnodeEp = {0};
|
SDnodeEp dnodeEp = {0};
|
||||||
dnodeEp.isMnode = 1;
|
dnodeEp.isMnode = 1;
|
||||||
taosGetFqdnPortFromEp(pData->firstEp, &dnodeEp.ep);
|
taosGetFqdnPortFromEp(tsFirst, &dnodeEp.ep);
|
||||||
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmResetEps(pData, pData->dnodeEps);
|
dmResetEps(pData, pData->dnodeEps);
|
||||||
|
|
||||||
if (dmIsEpChanged(pData, pData->dnodeId, pData->localEp)) {
|
if (dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
||||||
dError("localEp %s different with %s and need reconfigured", pData->localEp, file);
|
dError("localEp %s different with %s and need reconfigured", tsLocalEp, file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,8 +177,8 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
|
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", pData->dataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", pData->dataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
|
|
|
@ -80,19 +80,6 @@ const char *dmNodeName(EDndNodeType ntype) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
const char *dmProcStr(EDndProcType etype) {
|
||||||
switch (etype) {
|
switch (etype) {
|
||||||
case DND_PROC_SINGLE:
|
case DND_PROC_SINGLE:
|
||||||
|
|
Loading…
Reference in New Issue