From d3c1202782e9d5a6b018e938851d01ad9f9d8809 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 2 Dec 2020 10:10:40 +0800 Subject: [PATCH] TD-1843 --- src/dnode/src/dnodeMain.c | 33 ++++++++------------------------- src/mnode/src/mnodeMain.c | 29 ++++++++--------------------- src/util/inc/tstep.h | 1 - src/vnode/src/vnodeMgmt.c | 10 +++++----- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index a4b9318cdf..b571df3b8f 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 d15b32da54..030c881141 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 294fa79b60..257002b573 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 542ea7b2ce..67fa1b80b5 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() { -- GitLab