diff --git a/src/dnode/inc/dnodeStep.h b/src/dnode/inc/dnodeStep.h index 88789e1245b07b33123f4bc3cb2977971342ae32..b260cb8d79309c9604440bae024cae1cc4a3615a 100644 --- a/src/dnode/inc/dnodeStep.h +++ b/src/dnode/inc/dnodeStep.h @@ -19,9 +19,12 @@ #ifdef __cplusplus extern "C" { #endif +#include "dnode.h" -void dnodeReportStep(char *name, char *desc, int8_t finished); -void dnodeSendStartupStep(SRpcMsg *pMsg); +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 dnodeSendStartupStep(SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index b571df3b8fd43433a6728a1dabc8c6934e0ed185..977a188ea939da4ce9299e69f873d20abb30b6a3 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -20,7 +20,6 @@ #include "tconfig.h" #include "tglobal.h" #include "tfile.h" -#include "tstep.h" #include "twal.h" #include "trpc.h" #include "dnode.h" @@ -83,12 +82,12 @@ static int dnodeCreateDir(const char *dir) { static void dnodeCleanupComponents() { int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); - taosStepCleanup(tsDnodeSteps, stepSize); + dnodeStepCleanup(tsDnodeSteps, stepSize); } static int32_t dnodeInitComponents() { int32_t stepSize = sizeof(tsDnodeSteps) / sizeof(SStep); - return taosStepInit(tsDnodeSteps, stepSize); + return dnodeStepInit(tsDnodeSteps, stepSize); } int32_t dnodeInitSystem() { diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index 19f5a36d8479dc4d04bd3c89df4e0b03a3e5f0eb..9adfcc12b1f6a5f0b6910357b7afc62a0462bf19 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -58,8 +58,6 @@ int32_t dnodeInitServer() { dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_GRANT] = dnodeDispatchToMPeerQueue; dnodeProcessReqMsgFp[TSDB_MSG_TYPE_DM_STATUS] = dnodeDispatchToMPeerQueue; - dnodeProcessReqMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep; - SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = tsDnodeDnodePort; @@ -94,8 +92,9 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { .pCont = NULL, .contLen = 0 }; - + if (pMsg->pCont == NULL) return; + if (pMsg->msgType == TSDB_MSG_TYPE_NETWORK_TEST) return dnodeSendStartupStep(pMsg); if (dnodeGetRunStatus() != TSDB_RUN_STATUS_RUNING) { rspMsg.code = TSDB_CODE_APP_NOT_READY; diff --git a/src/dnode/src/dnodeStep.c b/src/dnode/src/dnodeStep.c index 89d38b27948f7f6173046f9330525788d91123d1..f899ce93411dc6a0e540ef5d1bf3bd588cad2620 100644 --- a/src/dnode/src/dnodeStep.c +++ b/src/dnode/src/dnodeStep.c @@ -15,8 +15,10 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taoserror.h" #include "taosmsg.h" #include "dnodeInt.h" +#include "dnodeStep.h" static SStartupStep tsStartupStep; @@ -39,7 +41,43 @@ void dnodeSendStartupStep(SRpcMsg *pMsg) { if (step > 10) pStep->finished = 1; #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)}; rpcSendResponse(&rpcRsp); 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); +} diff --git a/src/inc/dnode.h b/src/inc/dnode.h index b2bf4d5e46bd612482f1aea14007dab9153f488c..644ca7aa68357ce656e2c65294760f908734087f 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -71,6 +71,14 @@ void dnodeDelayReprocessMWriteMsg(void *pMsg); 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); #ifdef __cplusplus diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index 030c88114151e5387d27418cc00c6f2201e5e408..983f144be13accb9f22de1bacfb60bd659857acf 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -21,7 +21,6 @@ #include "tgrant.h" #include "ttimer.h" #include "tglobal.h" -#include "tstep.h" #include "mnode.h" #include "dnode.h" #include "mnodeDef.h" @@ -64,12 +63,12 @@ static bool mnodeNeedStart() ; static void mnodeCleanupComponents() { int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); - taosStepCleanup(tsMnodeSteps, stepSize); + dnodeStepCleanup(tsMnodeSteps, stepSize); } static int32_t mnodeInitComponents() { int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep); - return taosStepInit(tsMnodeSteps, stepSize); + return dnodeStepInit(tsMnodeSteps, stepSize); } int32_t mnodeStartSystem() { diff --git a/src/util/inc/tstep.h b/src/util/inc/tstep.h deleted file mode 100644 index 257002b5735a03e9a7d176a9ffab744311dd9d41..0000000000000000000000000000000000000000 --- a/src/util/inc/tstep.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ - -#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 diff --git a/src/util/src/tnettest.c b/src/util/src/tnettest.c index 7c8178e82741ad89a77fa26033ff22891fb2fab2..c269d9a1ffe07c162123c44c397aba0da9593068 100644 --- a/src/util/src/tnettest.c +++ b/src/util/src/tnettest.c @@ -355,7 +355,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p pRpcConn = taosNetInitRpc(secretEncrypt, spi); if (NULL == pRpcConn) { uError("failed to init client rpc"); - return -1; + return TSDB_CODE_RPC_NETWORK_UNAVAIL; } memset(&epSet, 0, sizeof(SRpcEpSet)); @@ -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)) { uDebug("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); - return -1; + return rspMsg.code; } int32_t code = 0; @@ -406,7 +406,7 @@ static void taosNetTestStartup(char *host, int32_t port) { SStartupStep *pStep = malloc(sizeof(SStartupStep)); 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) { code = taosNetParseStartup(pStep); } @@ -414,9 +414,11 @@ static void taosNetTestStartup(char *host, int32_t port) { if (code > 0) { uDebug("continue check startup step"); } else { + if (code < 0) { + uError("failed to check startup step, code:0x%x %s", code, tstrerror(code)); + } break; } - taosMsleep(500); } free(pStep); diff --git a/src/util/src/tstep.c b/src/util/src/tstep.c deleted file mode 100644 index e418191c8dbd18161cd8626ec13ae54005ab8fcb..0000000000000000000000000000000000000000 --- a/src/util/src/tstep.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ - -#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); -} diff --git a/src/vnode/src/vnodeMgmt.c b/src/vnode/src/vnodeMgmt.c index 67fa1b80b504c965abecbca1bd195d3887dbda68..8c24859b60e1abc53d809dae589679dfc8d674c3 100644 --- a/src/vnode/src/vnodeMgmt.c +++ b/src/vnode/src/vnodeMgmt.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "tstep.h" +#include "dnode.h" #include "vnodeStatus.h" #include "vnodeRead.h" #include "vnodeWrite.h" @@ -37,12 +37,12 @@ static SStep tsVnodeSteps[] = { int32_t vnodeInitMgmt() { int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep); - return taosStepInit(tsVnodeSteps, stepSize); + return dnodeStepInit(tsVnodeSteps, stepSize); } void vnodeCleanupMgmt() { int32_t stepSize = sizeof(tsVnodeSteps) / sizeof(SStep); - taosStepCleanup(tsVnodeSteps, stepSize); + dnodeStepCleanup(tsVnodeSteps, stepSize); } static int32_t vnodeInitHash() {