提交 d3c12027 编写于 作者: S Shengliang Guan

TD-1843

上级 bd0f7fff
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "tconfig.h" #include "tconfig.h"
#include "tglobal.h" #include "tglobal.h"
#include "tfile.h" #include "tfile.h"
#include "tstep.h"
#include "twal.h" #include "twal.h"
#include "trpc.h" #include "trpc.h"
#include "dnode.h" #include "dnode.h"
...@@ -46,17 +47,9 @@ static int32_t dnodeInitStorage(); ...@@ -46,17 +47,9 @@ static int32_t dnodeInitStorage();
static void dnodeCleanupStorage(); static void dnodeCleanupStorage();
static void dnodeSetRunStatus(SRunStatus status); static void dnodeSetRunStatus(SRunStatus status);
static void dnodeCheckDataDirOpenned(char *dir); static void dnodeCheckDataDirOpenned(char *dir);
static int32_t dnodeInitComponents();
static void dnodeCleanupComponents(int32_t stepId);
static int dnodeCreateDir(const char *dir); static int dnodeCreateDir(const char *dir);
typedef struct { static SStep tsDnodeSteps[] = {
const char *const name;
int32_t (*init)();
void (*cleanup)();
} SDnodeComponent;
static const SDnodeComponent tsDnodeComponents[] = {
{"tfile", tfInit, tfCleanup}, {"tfile", tfInit, tfCleanup},
{"rpc", rpcInit, rpcCleanup}, {"rpc", rpcInit, rpcCleanup},
{"storage", dnodeInitStorage, dnodeCleanupStorage}, {"storage", dnodeInitStorage, dnodeCleanupStorage},
...@@ -88,24 +81,14 @@ static int dnodeCreateDir(const char *dir) { ...@@ -88,24 +81,14 @@ static int dnodeCreateDir(const char *dir) {
return 0; return 0;
} }
static void dnodeCleanupComponents(int32_t stepId) { static void dnodeCleanupComponents() {
for (int32_t i = stepId; i >= 0; i--) { int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep);
if (tsDnodeComponents[i].cleanup) { taosStepCleanup(tsDnodeSteps, stepSize);
(*tsDnodeComponents[i].cleanup)();
}
}
} }
static int32_t dnodeInitComponents() { static int32_t dnodeInitComponents() {
int32_t code = 0; int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep);
for (int32_t i = 0; i < sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]); i++) { return taosStepInit(tsDnodeSteps, stepSize);
if (tsDnodeComponents[i].init() != 0) {
dnodeCleanupComponents(i);
code = -1;
break;
}
}
return code;
} }
int32_t dnodeInitSystem() { int32_t dnodeInitSystem() {
...@@ -152,7 +135,7 @@ int32_t dnodeInitSystem() { ...@@ -152,7 +135,7 @@ int32_t dnodeInitSystem() {
void dnodeCleanUpSystem() { void dnodeCleanUpSystem() {
if (dnodeGetRunStatus() != TSDB_RUN_STATUS_STOPPED) { if (dnodeGetRunStatus() != TSDB_RUN_STATUS_STOPPED) {
dnodeSetRunStatus(TSDB_RUN_STATUS_STOPPED); dnodeSetRunStatus(TSDB_RUN_STATUS_STOPPED);
dnodeCleanupComponents(sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]) - 1); dnodeCleanupComponents();
taos_cleanup(); taos_cleanup();
taosCloseLog(); taosCloseLog();
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "tgrant.h" #include "tgrant.h"
#include "ttimer.h" #include "ttimer.h"
#include "tglobal.h" #include "tglobal.h"
#include "tstep.h"
#include "mnode.h" #include "mnode.h"
#include "dnode.h" #include "dnode.h"
#include "mnodeDef.h" #include "mnodeDef.h"
...@@ -37,16 +38,10 @@ ...@@ -37,16 +38,10 @@
#include "mnodeShow.h" #include "mnodeShow.h"
#include "mnodeProfile.h" #include "mnodeProfile.h"
typedef struct {
const char *const name;
int (*init)();
void (*cleanup)();
} SMnodeComponent;
void *tsMnodeTmr = NULL; void *tsMnodeTmr = NULL;
static bool tsMgmtIsRunning = false; static bool tsMgmtIsRunning = false;
static const SMnodeComponent tsMnodeComponents[] = { static SStep tsMnodeSteps[] = {
{"sdbref", sdbInitRef, sdbCleanUpRef}, {"sdbref", sdbInitRef, sdbCleanUpRef},
{"profile", mnodeInitProfile, mnodeCleanupProfile}, {"profile", mnodeInitProfile, mnodeCleanupProfile},
{"cluster", mnodeInitCluster, mnodeCleanupCluster}, {"cluster", mnodeInitCluster, mnodeCleanupCluster},
...@@ -67,22 +62,14 @@ static void mnodeInitTimer(); ...@@ -67,22 +62,14 @@ static void mnodeInitTimer();
static void mnodeCleanupTimer(); static void mnodeCleanupTimer();
static bool mnodeNeedStart() ; static bool mnodeNeedStart() ;
static void mnodeCleanupComponents(int32_t stepId) { static void mnodeCleanupComponents() {
for (int32_t i = stepId; i >= 0; i--) { int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
tsMnodeComponents[i].cleanup(); taosStepCleanup(tsMnodeSteps, stepSize);
}
} }
static int32_t mnodeInitComponents() { static int32_t mnodeInitComponents() {
int32_t code = 0; int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
for (int32_t i = 0; i < sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]); i++) { return taosStepInit(tsMnodeSteps, stepSize);
if (tsMnodeComponents[i].init() != 0) {
mnodeCleanupComponents(i);
code = -1;
break;
}
}
return code;
} }
int32_t mnodeStartSystem() { int32_t mnodeStartSystem() {
...@@ -132,7 +119,7 @@ void mnodeCleanupSystem() { ...@@ -132,7 +119,7 @@ void mnodeCleanupSystem() {
dnodeFreeMReadQueue(); dnodeFreeMReadQueue();
dnodeFreeMPeerQueue(); dnodeFreeMPeerQueue();
mnodeCleanupTimer(); mnodeCleanupTimer();
mnodeCleanupComponents(sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]) - 1); mnodeCleanupComponents();
mInfo("mnode is cleaned up"); mInfo("mnode is cleaned up");
} }
......
...@@ -24,7 +24,6 @@ typedef struct { ...@@ -24,7 +24,6 @@ typedef struct {
const char *const name; const char *const name;
int32_t (*initFp)(); int32_t (*initFp)();
void (*cleanupFp)(); void (*cleanupFp)();
int32_t step;
} SStep; } SStep;
int32_t taosStepInit(SStep *pSteps, int32_t stepSize); int32_t taosStepInit(SStep *pSteps, int32_t stepSize);
......
...@@ -28,11 +28,11 @@ static void vnodeCleanupHash(void); ...@@ -28,11 +28,11 @@ static void vnodeCleanupHash(void);
static void vnodeIncRef(void *ptNode); static void vnodeIncRef(void *ptNode);
static SStep tsVnodeSteps[] = { static SStep tsVnodeSteps[] = {
{"vsync", syncInit, syncCleanUp, 0}, {"vsync", syncInit, syncCleanUp},
{"vwrite", vnodeInitWrite, vnodeCleanupWrite, 1}, {"vwrite", vnodeInitWrite, vnodeCleanupWrite},
{"vread", vnodeInitRead, vnodeCleanupRead, 2}, {"vread", vnodeInitRead, vnodeCleanupRead},
{"vhash", vnodeInitHash, vnodeCleanupHash, 3}, {"vhash", vnodeInitHash, vnodeCleanupHash},
{"vqueue", tsdbInitCommitQueue, tsdbDestroyCommitQueue, 4} {"vqueue", tsdbInitCommitQueue, tsdbDestroyCommitQueue}
}; };
int32_t vnodeInitMgmt() { int32_t vnodeInitMgmt() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册