提交 4cc2e903 编写于 作者: S Shengliang Guan

TD-1843

上级 8b4e85dd
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "dnode.h"
int32_t dnodeStepInit(SStep *pSteps, int32_t stepSize);
void dnodeStepCleanup(SStep *pSteps, int32_t stepSize);
void dnodeReportStep(char *name, char *desc, int8_t finished); void dnodeReportStep(char *name, char *desc, int8_t finished);
void dnodeSendStartupStep(SRpcMsg *pMsg); void dnodeSendStartupStep(SRpcMsg *pMsg);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#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"
...@@ -83,12 +82,12 @@ static int dnodeCreateDir(const char *dir) { ...@@ -83,12 +82,12 @@ static int dnodeCreateDir(const char *dir) {
static void dnodeCleanupComponents() { static void dnodeCleanupComponents() {
int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep);
taosStepCleanup(tsDnodeSteps, stepSize); dnodeStepCleanup(tsDnodeSteps, stepSize);
} }
static int32_t dnodeInitComponents() { static int32_t dnodeInitComponents() {
int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep);
return taosStepInit(tsDnodeSteps, stepSize); return dnodeStepInit(tsDnodeSteps, stepSize);
} }
int32_t dnodeInitSystem() { int32_t dnodeInitSystem() {
......
...@@ -58,8 +58,6 @@ int32_t dnodeInitServer() { ...@@ -58,8 +58,6 @@ int32_t dnodeInitServer() {
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_GRANT] = dnodeDispatchToMPeerQueue; dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_GRANT] = dnodeDispatchToMPeerQueue;
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_STATUS] = dnodeDispatchToMPeerQueue; dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_STATUS] = dnodeDispatchToMPeerQueue;
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep;
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localPort = tsDnodeDnodePort; rpcInit.localPort = tsDnodeDnodePort;
...@@ -96,6 +94,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { ...@@ -96,6 +94,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
}; };
if (pMsg->pCont == NULL) return; if (pMsg->pCont == NULL) return;
if (pMsg->msgType == TSDB_MSG_TYPE_NETWORK_TEST) return dnodeSendStartupStep(pMsg);
if (dnodeGetRunStatus() != TSDB_RUN_STATUS_RUNING) { if (dnodeGetRunStatus() != TSDB_RUN_STATUS_RUNING) {
rspMsg.code = TSDB_CODE_APP_NOT_READY; rspMsg.code = TSDB_CODE_APP_NOT_READY;
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeStep.h"
static SStartupStep tsStartupStep; static SStartupStep tsStartupStep;
...@@ -39,7 +41,43 @@ void dnodeSendStartupStep(SRpcMsg *pMsg) { ...@@ -39,7 +41,43 @@ void dnodeSendStartupStep(SRpcMsg *pMsg) {
if (step > 10) pStep->finished = 1; if (step > 10) pStep->finished = 1;
#endif #endif
dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStep->name, pStep->desc, pStep->finished);
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)}; SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
} }
void taosStepCleanupImp(SStep *pSteps, int32_t stepId) {
for (int32_t step = stepId; step >= 0; step--) {
SStep *pStep = pSteps + step;
dDebug("step:%s will cleanup", pStep->name);
if (pStep->cleanupFp != NULL) {
(*pStep->cleanupFp)();
}
}
}
int32_t dnodeStepInit(SStep *pSteps, int32_t stepSize) {
for (int32_t step = 0; step < stepSize; step++) {
SStep *pStep = pSteps + step;
if (pStep->initFp == NULL) continue;
dnodeReportStep(pStep->name, "Start initialization", 0);
int32_t code = (*pStep->initFp)();
if (code != 0) {
dDebug("step:%s will init", pStep->name);
taosStepCleanupImp(pSteps, step);
return code;
}
dnodeReportStep(pStep->name, "Initialization complete", step + 1 >= stepSize);
}
return 0;
}
void dnodeStepCleanup(SStep *pSteps, int32_t stepSize) {
return taosStepCleanupImp(pSteps, stepSize - 1);
}
...@@ -71,6 +71,14 @@ void dnodeDelayReprocessMWriteMsg(void *pMsg); ...@@ -71,6 +71,14 @@ void dnodeDelayReprocessMWriteMsg(void *pMsg);
void dnodeSendStatusMsgToMnode(); void dnodeSendStatusMsgToMnode();
typedef struct {
char *name;
int32_t (*initFp)();
void (*cleanupFp)();
} SStep;
int32_t dnodeStepInit(SStep *pSteps, int32_t stepSize);
void dnodeStepCleanup(SStep *pSteps, int32_t stepSize);
void dnodeReportStep(char *name, char *desc, int8_t finished); void dnodeReportStep(char *name, char *desc, int8_t finished);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#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"
...@@ -64,12 +63,12 @@ static bool mnodeNeedStart() ; ...@@ -64,12 +63,12 @@ static bool mnodeNeedStart() ;
static void mnodeCleanupComponents() { static void mnodeCleanupComponents() {
int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
taosStepCleanup(tsMnodeSteps, stepSize); dnodeStepCleanup(tsMnodeSteps, stepSize);
} }
static int32_t mnodeInitComponents() { static int32_t mnodeInitComponents() {
int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
return taosStepInit(tsMnodeSteps, stepSize); return dnodeStepInit(tsMnodeSteps, stepSize);
} }
int32_t mnodeStartSystem() { int32_t mnodeStartSystem() {
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_TSTEP_H
#define TDENGINE_TSTEP_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
const char *const name;
int32_t (*initFp)();
void (*cleanupFp)();
} SStep;
int32_t taosStepInit(SStep *pSteps, int32_t stepSize);
void taosStepCleanup(SStep *pSteps, int32_t stepSize);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TUTIL_H
...@@ -355,7 +355,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p ...@@ -355,7 +355,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p
pRpcConn = taosNetInitRpc(secretEncrypt, spi); pRpcConn = taosNetInitRpc(secretEncrypt, spi);
if (NULL == pRpcConn) { if (NULL == pRpcConn) {
uError("failed to init client rpc"); uError("failed to init client rpc");
return -1; return TSDB_CODE_RPC_NETWORK_UNAVAIL;
} }
memset(&epSet, 0, sizeof(SRpcEpSet)); memset(&epSet, 0, sizeof(SRpcEpSet));
...@@ -376,7 +376,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p ...@@ -376,7 +376,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p
if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) { if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) {
uDebug("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); uDebug("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code));
return -1; return rspMsg.code;
} }
int32_t code = 0; int32_t code = 0;
...@@ -406,7 +406,7 @@ static void taosNetTestStartup(char *host, int32_t port) { ...@@ -406,7 +406,7 @@ static void taosNetTestStartup(char *host, int32_t port) {
SStartupStep *pStep = malloc(sizeof(SStartupStep)); SStartupStep *pStep = malloc(sizeof(SStartupStep));
while (1) { while (1) {
int32_t code = taosNetCheckRpc(host, port, 20, 0, pStep); int32_t code = taosNetCheckRpc(host, port + TSDB_PORT_DNODEDNODE, 20, 0, pStep);
if (code > 0) { if (code > 0) {
code = taosNetParseStartup(pStep); code = taosNetParseStartup(pStep);
} }
...@@ -414,9 +414,11 @@ static void taosNetTestStartup(char *host, int32_t port) { ...@@ -414,9 +414,11 @@ static void taosNetTestStartup(char *host, int32_t port) {
if (code > 0) { if (code > 0) {
uDebug("continue check startup step"); uDebug("continue check startup step");
} else { } else {
if (code < 0) {
uError("failed to check startup step, code:0x%x %s", code, tstrerror(code));
}
break; break;
} }
taosMsleep(500);
} }
free(pStep); free(pStep);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tstep.h"
#include "tulog.h"
#include "taoserror.h"
void taosStepCleanupImp(SStep *pSteps, int32_t stepId) {
for (int32_t step = stepId; step >= 0; step--) {
SStep *pStep = pSteps + step;
uDebug("step:%s will cleanup", pStep->name);
if (pStep->cleanupFp != NULL) {
(*pStep->cleanupFp)();
}
}
}
int32_t taosStepInit(SStep *pSteps, int32_t stepSize) {
for (int32_t step = 0; step < stepSize; step++) {
SStep *pStep = pSteps + step;
if (pStep->initFp == NULL) continue;
int32_t code = (*pStep->initFp)();
if (code != 0) {
uDebug("step:%s will init", pStep->name);
taosStepCleanupImp(pSteps, step);
return code;
}
}
return 0;
}
void taosStepCleanup(SStep *pSteps, int32_t stepSize) {
return taosStepCleanupImp(pSteps, stepSize - 1);
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tstep.h" #include "dnode.h"
#include "vnodeStatus.h" #include "vnodeStatus.h"
#include "vnodeRead.h" #include "vnodeRead.h"
#include "vnodeWrite.h" #include "vnodeWrite.h"
...@@ -37,12 +37,12 @@ static SStep tsVnodeSteps[] = { ...@@ -37,12 +37,12 @@ static SStep tsVnodeSteps[] = {
int32_t vnodeInitMgmt() { int32_t vnodeInitMgmt() {
int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep);
return taosStepInit(tsVnodeSteps, stepSize); return dnodeStepInit(tsVnodeSteps, stepSize);
} }
void vnodeCleanupMgmt() { void vnodeCleanupMgmt() {
int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep); int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep);
taosStepCleanup(tsVnodeSteps, stepSize); dnodeStepCleanup(tsVnodeSteps, stepSize);
} }
static int32_t vnodeInitHash() { static int32_t vnodeInitHash() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册