diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index a4b9318cdf2fae2e4c9ac2f1fc6f4ff542cf1a5d..b571df3b8fd43433a6728a1dabc8c6934e0ed185 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -20,6 +20,7 @@ #include "tconfig.h" #include "tglobal.h" #include "tfile.h" +#include "tstep.h" #include "twal.h" #include "trpc.h" #include "dnode.h" @@ -46,17 +47,9 @@ static int32_t dnodeInitStorage(); static void dnodeCleanupStorage(); static void dnodeSetRunStatus(SRunStatus status); static void dnodeCheckDataDirOpenned(char *dir); -static int32_t dnodeInitComponents(); -static void dnodeCleanupComponents(int32_t stepId); static int dnodeCreateDir(const char *dir); -typedef struct { - const char *const name; - int32_t (*init)(); - void (*cleanup)(); -} SDnodeComponent; - -static const SDnodeComponent tsDnodeComponents[] = { +static SStep tsDnodeSteps[] = { {"tfile", tfInit, tfCleanup}, {"rpc", rpcInit, rpcCleanup}, {"storage", dnodeInitStorage, dnodeCleanupStorage}, @@ -88,24 +81,14 @@ static int dnodeCreateDir(const char *dir) { return 0; } -static void dnodeCleanupComponents(int32_t stepId) { - for (int32_t i = stepId; i >= 0; i--) { - if (tsDnodeComponents[i].cleanup) { - (*tsDnodeComponents[i].cleanup)(); - } - } +static void dnodeCleanupComponents() { + int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); + taosStepCleanup(tsDnodeSteps, stepSize); } static int32_t dnodeInitComponents() { - int32_t code = 0; - for (int32_t i = 0; i < sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]); i++) { - if (tsDnodeComponents[i].init() != 0) { - dnodeCleanupComponents(i); - code = -1; - break; - } - } - return code; + int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); + return taosStepInit(tsDnodeSteps, stepSize); } int32_t dnodeInitSystem() { @@ -152,7 +135,7 @@ int32_t dnodeInitSystem() { void dnodeCleanUpSystem() { if (dnodeGetRunStatus() != TSDB_RUN_STATUS_STOPPED) { dnodeSetRunStatus(TSDB_RUN_STATUS_STOPPED); - dnodeCleanupComponents(sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]) - 1); + dnodeCleanupComponents(); taos_cleanup(); taosCloseLog(); } diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index d15b32da54d245b08146703aaed08a5b43ce8170..030c88114151e5387d27418cc00c6f2201e5e408 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -21,6 +21,7 @@ #include "tgrant.h" #include "ttimer.h" #include "tglobal.h" +#include "tstep.h" #include "mnode.h" #include "dnode.h" #include "mnodeDef.h" @@ -37,16 +38,10 @@ #include "mnodeShow.h" #include "mnodeProfile.h" -typedef struct { - const char *const name; - int (*init)(); - void (*cleanup)(); -} SMnodeComponent; - void *tsMnodeTmr = NULL; static bool tsMgmtIsRunning = false; -static const SMnodeComponent tsMnodeComponents[] = { +static SStep tsMnodeSteps[] = { {"sdbref", sdbInitRef, sdbCleanUpRef}, {"profile", mnodeInitProfile, mnodeCleanupProfile}, {"cluster", mnodeInitCluster, mnodeCleanupCluster}, @@ -67,22 +62,14 @@ static void mnodeInitTimer(); static void mnodeCleanupTimer(); static bool mnodeNeedStart() ; -static void mnodeCleanupComponents(int32_t stepId) { - for (int32_t i = stepId; i >= 0; i--) { - tsMnodeComponents[i].cleanup(); - } +static void mnodeCleanupComponents() { + int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); + taosStepCleanup(tsMnodeSteps, stepSize); } static int32_t mnodeInitComponents() { - int32_t code = 0; - for (int32_t i = 0; i < sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]); i++) { - if (tsMnodeComponents[i].init() != 0) { - mnodeCleanupComponents(i); - code = -1; - break; - } - } - return code; + int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); + return taosStepInit(tsMnodeSteps, stepSize); } int32_t mnodeStartSystem() { @@ -132,7 +119,7 @@ void mnodeCleanupSystem() { dnodeFreeMReadQueue(); dnodeFreeMPeerQueue(); mnodeCleanupTimer(); - mnodeCleanupComponents(sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]) - 1); + mnodeCleanupComponents(); mInfo("mnode is cleaned up"); } diff --git a/src/util/inc/tstep.h b/src/util/inc/tstep.h index 294fa79b6040b5ca1218b2e94c6a5df1fa19b4e6..257002b5735a03e9a7d176a9ffab744311dd9d41 100644 --- a/src/util/inc/tstep.h +++ b/src/util/inc/tstep.h @@ -24,7 +24,6 @@ typedef struct { const char *const name; int32_t (*initFp)(); void (*cleanupFp)(); - int32_t step; } SStep; int32_t taosStepInit(SStep *pSteps, int32_t stepSize); diff --git a/src/vnode/src/vnodeMgmt.c b/src/vnode/src/vnodeMgmt.c index 542ea7b2cea75ab0468da0519c81706508fffb13..67fa1b80b504c965abecbca1bd195d3887dbda68 100644 --- a/src/vnode/src/vnodeMgmt.c +++ b/src/vnode/src/vnodeMgmt.c @@ -28,11 +28,11 @@ static void vnodeCleanupHash(void); static void vnodeIncRef(void *ptNode); static SStep tsVnodeSteps[] = { - {"vsync", syncInit, syncCleanUp, 0}, - {"vwrite", vnodeInitWrite, vnodeCleanupWrite, 1}, - {"vread", vnodeInitRead, vnodeCleanupRead, 2}, - {"vhash", vnodeInitHash, vnodeCleanupHash, 3}, - {"vqueue", tsdbInitCommitQueue, tsdbDestroyCommitQueue, 4} + {"vsync", syncInit, syncCleanUp}, + {"vwrite", vnodeInitWrite, vnodeCleanupWrite}, + {"vread", vnodeInitRead, vnodeCleanupRead}, + {"vhash", vnodeInitHash, vnodeCleanupHash}, + {"vqueue", tsdbInitCommitQueue, tsdbDestroyCommitQueue} }; int32_t vnodeInitMgmt() {