diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index b48fd232045a03608b593511982476d329f5d05f..10ae1e32ed07766218b4c5ab8f0cc8abf40f3a84 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -22,66 +22,23 @@ extern "C" { #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 */ -int32_t dmInit(); +int32_t dmInit(int8_t rtype); /** - * @brief Clear the environment + * @brief Cleanup the dnode */ 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. - * - * @param pOption Option of the dnode. - * @return SDnode* The dnode object. - */ -SDnode *dmCreate(const SDnodeOpt *pOption); - -/** - * @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. + * @brief Run dnode. */ -void dmSetEvent(SDnode *pDnode, EDndEvent event); +int32_t dmRun(); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index dc5999a7e6f09d6a6b14a89955522604e9a32ad5..22e6fcf34ce7bc48aa37ad5b616a94d549b8be00 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -87,38 +87,28 @@ typedef enum { DND_FUNC_RELEASE = 4, } EProcFuncType; -typedef int32_t (*ProcessCreateNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SRpcMsg *pMsg); -typedef int32_t (*ProcessDropNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SRpcMsg *pMsg); -typedef bool (*IsNodeRequiredFp)(struct SDnode *pDnode, EDndNodeType ntype); +typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); +typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); +typedef bool (*IsNodeRequiredFp)(EDndNodeType ntype); typedef struct { - int32_t dnodeId; - int64_t clusterId; - int64_t dnodeVer; - int64_t updateTime; - int64_t rebootTime; - bool dropped; - bool stopped; - SEpSet mnodeEps; - SArray *dnodeEps; - SHashObj *dnodeHash; - SRWLatch latch; - 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; + int32_t dnodeId; + int64_t clusterId; + int64_t dnodeVer; + int64_t updateTime; + int64_t rebootTime; + bool dropped; + bool stopped; + SEpSet mnodeEps; + SArray *dnodeEps; + SHashObj *dnodeHash; + SRWLatch latch; + SMsgCb msgCb; } SDnodeData; typedef struct { const char *path; const char *name; - struct SDnode *pDnode; SDnodeData *pData; SMsgCb msgCb; ProcessCreateNodeFp processCreateNodeFp; @@ -162,7 +152,6 @@ const char *dmStatStr(EDndRunStatus stype); const char *dmNodeLogName(EDndNodeType ntype); const char *dmNodeProcName(EDndNodeType ntype); const char *dmNodeName(EDndNodeType ntype); -const char *dmEventStr(EDndEvent etype); const char *dmProcStr(EDndProcType ptype); const char *dmFuncStr(EProcFuncType etype); void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId); diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index e488aa10827c574d5bb8e627664046dff728ff34..a6c9fda64d5d64a77b9ef3d7701bb6232e711d3a 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -54,7 +54,7 @@ int32_t dmReadEps(SDnodeData *pData) { 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); if (pFile == NULL) { code = 0; @@ -158,14 +158,14 @@ _OVER: if (taosArrayGetSize(pData->dnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; - taosGetFqdnPortFromEp(pData->firstEp, &dnodeEp.ep); + taosGetFqdnPortFromEp(tsFirst, &dnodeEp.ep); taosArrayPush(pData->dnodeEps, &dnodeEp); } dmResetEps(pData, pData->dnodeEps); - if (dmIsEpChanged(pData, pData->dnodeId, pData->localEp)) { - dError("localEp %s different with %s and need reconfigured", pData->localEp, file); + if (dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) { + dError("localEp %s different with %s and need reconfigured", tsLocalEp, file); return -1; } @@ -177,8 +177,8 @@ int32_t dmWriteEps(SDnodeData *pData) { char file[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0}; - snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", pData->dataDir, TD_DIRSEP, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", 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", tsDataDir, TD_DIRSEP, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index 986a3056aa56885120ae1e9aa76ba71117710964..832e15a1e00b92d614f87f44e0accc02853c9107 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -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) { switch (etype) { case DND_PROC_SINGLE: