From dfafa1be820cee1260512c1df0b6db9fa5c1e8fb Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 20 Feb 2020 14:45:50 +0800 Subject: [PATCH] reorganize the file mgmtSystem.c --- src/dnode/src/dnodeSystem.c | 16 ++--- src/inc/mnode.h | 9 +-- src/mnode/inc/mgmtSystem.h | 1 - src/mnode/src/mgmtDb.c | 2 +- src/mnode/src/mgmtDnodeInt.c | 4 +- src/mnode/src/mgmtShell.c | 14 ++--- src/mnode/src/mgmtSuperTable.c | 2 +- src/mnode/src/mgmtSystem.c | 112 +++++++++++++-------------------- src/mnode/src/mgmtUser.c | 2 +- src/mnode/src/mgmtVgroup.c | 4 +- src/util/inc/tglobalcfg.h | 2 +- src/vnode/detail/inc/vnode.h | 2 +- 12 files changed, 72 insertions(+), 98 deletions(-) diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 0f009f0f11..1937e7130f 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -85,6 +85,8 @@ void dnodeSetRunStatus(SDnodeRunStatus status) { } void dnodeCleanUpSystem() { + tclearModuleStatus(TSDB_MOD_MGMT); + if (dnodeGetRunStatus() == TSDB_DNODE_RUN_STATUS_STOPPED) { return; } else { @@ -131,29 +133,27 @@ void dnodeInitPlugins() { } int32_t dnodeInitSystem() { - char temp[128]; - struct stat dirstat; + tsRebootTime = taosGetTimestampSec(); + tscEmbedded = 1; dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_INITIALIZE); - taosResolveCRC(); - tsRebootTime = taosGetTimestampSec(); - tscEmbedded = 1; - // Read global configuration. tsReadGlobalLogConfig(); + struct stat dirstat; if (stat(logDir, &dirstat) < 0) { mkdir(logDir, 0755); } + char temp[128]; sprintf(temp, "%s/taosdlog", logDir); if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { printf("failed to init log file\n"); } - if (!tsReadGlobalConfig()) { // TODO : Change this function + if (!tsReadGlobalConfig()) { tsPrintGlobalConfig(); dError("TDengine read global config failed"); return -1; @@ -249,7 +249,7 @@ int32_t dnodeInitStorageImp() { sprintf(fileName, "%s/data", tsDirectory); mkdir(fileName, 0755); - sprintf(mgmtDirectory, "%s/mgmt", tsDirectory); + sprintf(tsMgmtDirectory, "%s/mgmt", tsDirectory); sprintf(tsDirectory, "%s/tsdb", dataDir); dnodeCheckDataDirOpenned(dataDir); diff --git a/src/inc/mnode.h b/src/inc/mnode.h index d0449489c6..b8723f5275 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -43,12 +43,9 @@ extern "C" { // internal globals extern char version[]; -extern void *mgmtTmr; -extern void *mgmtQhandle; -extern void *mgmtTranQhandle; -extern int mgmtShellConns; -extern int mgmtDnodeConns; -extern char mgmtDirectory[]; +extern void *tsMgmtTmr; +extern void *tsMgmtTranQhandle; +extern char tsMgmtDirectory[]; extern int tsAcctUpdateSize; extern int tsDbUpdateSize; diff --git a/src/mnode/inc/mgmtSystem.h b/src/mnode/inc/mgmtSystem.h index 6bbea549c7..0ee119043a 100644 --- a/src/mnode/inc/mgmtSystem.h +++ b/src/mnode/inc/mgmtSystem.h @@ -28,7 +28,6 @@ void mgmtCleanUpSystem(); extern int32_t (*mgmtInitSystem)(); extern int32_t (*mgmtCheckMgmtRunning)(); extern void (*mgmtDoStatistic)(void *handle, void *tmrId); -extern void (*mgmtStartMgmtTimer)(); extern void (*mgmtStopSystem)(); extern void (*mgmtCleanUpRedirect)(); diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 41a1f9ebaf..dd5bc0df51 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -83,7 +83,7 @@ int32_t mgmtInitDbs() { mgmtDbActionInit(); - dbSdb = sdbOpenTable(tsMaxDbs, sizeof(SDbObj), "db", SDB_KEYTYPE_STRING, mgmtDirectory, mgmtDbAction); + dbSdb = sdbOpenTable(tsMaxDbs, sizeof(SDbObj), "db", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtDbAction); if (dbSdb == NULL) { mError("failed to init db data"); return -1; diff --git a/src/mnode/src/mgmtDnodeInt.c b/src/mnode/src/mgmtDnodeInt.c index 9ce0a7f4d4..04545fd41f 100644 --- a/src/mnode/src/mgmtDnodeInt.c +++ b/src/mnode/src/mgmtDnodeInt.c @@ -556,7 +556,7 @@ void mgmtProcessDnodeStatusImp(void *handle, void *tmrId) { pVload->dropStatus = TSDB_VN_DROP_STATUS_READY; pVload->status = TSDB_VN_STATUS_OFFLINE; mPrint("dnode:%s, vid:%d, drop finished", taosIpStr(pObj->privateIp), vnode); - taosTmrStart(mgmtMonitorDbDrop, 10000, NULL, mgmtTmr); + taosTmrStart(mgmtMonitorDbDrop, 10000, NULL, tsMgmtTmr); } } @@ -590,7 +590,7 @@ void mgmtProcessDnodeStatusImp(void *handle, void *tmrId) { } } - taosTmrReset(mgmtProcessDnodeStatus, tsStatusInterval * 1000, NULL, mgmtTmr, &mgmtStatusTimer); + taosTmrReset(mgmtProcessDnodeStatus, tsStatusInterval * 1000, NULL, tsMgmtTmr, &mgmtStatusTimer); if (mgmtStatusTimer == NULL) { mError("Failed to start status timer"); } diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 66e4c7afab..d2cbc67335 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -46,7 +46,7 @@ static RetrieveMetaFp* mgmtRetrieveFp; static void mgmtInitShowMsgFp(); -void * pShellConn = NULL; +void * tsShellConn = NULL; SConnObj *connList; void * mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle); int (*mgmtProcessShellMsg[TSDB_MSG_TYPE_MAX])(char *, int, SConnObj *); @@ -95,8 +95,8 @@ int mgmtInitShell() { rpcInit.idleTime = tsShellActivityTimer * 2000; rpcInit.afp = mgmtRetriveUserAuthInfo; - pShellConn = rpcOpen(&rpcInit); - if (pShellConn == NULL) { + tsShellConn = rpcOpen(&rpcInit); + if (tsShellConn == NULL) { mError("failed to init tcp connection to shell"); return -1; } @@ -105,9 +105,9 @@ int mgmtInitShell() { } void mgmtCleanUpShell() { - if (pShellConn) { - rpcClose(pShellConn); - pShellConn = NULL; + if (tsShellConn) { + rpcClose(tsShellConn); + tsShellConn = NULL; } tfree(connList); } @@ -1489,7 +1489,7 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { // schedMsg.tfp = NULL; // schedMsg.thandle = pConn; // -// taosScheduleTask(mgmtTranQhandle, &schedMsg); +// taosScheduleTask(tsMgmtTranQhandle, &schedMsg); // } else { // mError("%s from shell is not processed", taosMsg[pMsg->msgType]); // } diff --git a/src/mnode/src/mgmtSuperTable.c b/src/mnode/src/mgmtSuperTable.c index f5ceeb026c..1f4af91c2f 100644 --- a/src/mnode/src/mgmtSuperTable.c +++ b/src/mnode/src/mgmtSuperTable.c @@ -175,7 +175,7 @@ int32_t mgmtInitSuperTables() { mgmtSuperTableActionInit(); tsSuperTableSdb = sdbOpenTable(tsMaxTables, sizeof(STabObj) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_MAX_SQL_LEN, - "meters", SDB_KEYTYPE_STRING, mgmtDirectory, mgmtSuperTableAction); + "meters", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtSuperTableAction); if (tsSuperTableSdb == NULL) { mError("failed to init meter data"); return -1; diff --git a/src/mnode/src/mgmtSystem.c b/src/mnode/src/mgmtSystem.c index 74cf029055..af28b341b4 100644 --- a/src/mnode/src/mgmtSystem.c +++ b/src/mnode/src/mgmtSystem.c @@ -15,8 +15,8 @@ #define _DEFAULT_SOURCE #include "os.h" - -#include "dnodeSystem.h" +#include "taosdef.h" +#include "tsched.h" #include "mnode.h" #include "mgmtAcct.h" #include "mgmtBalance.h" @@ -29,60 +29,39 @@ #include "mgmtTable.h" #include "mgmtShell.h" #include "dnodeModule.h" -#include "taosdef.h" -// global, not configurable -char mgmtDirectory[128]; -void * mgmtTmr; -void * mgmtQhandle = NULL; -void * mgmtTranQhandle = NULL; -void * mgmtStatisticTimer = NULL; -int mgmtShellConns = 0; -int mgmtDnodeConns = 0; -extern void * pShellConn; -extern void ** tsRpcQhandle; -extern SMgmtIpList mgmtIpList; -extern SMgmtIpList mgmtPublicIpList; -extern char mgmtIpStr[TSDB_MAX_MGMT_IPS][20]; -extern void * acctSdb; +char tsMgmtDirectory[128] = {0}; +void *tsMgmtTmr = NULL; +void *tsMgmtTranQhandle = NULL; +void *tsMgmtStatisTimer = NULL; void mgmtCleanUpSystem() { - if (tsModuleStatus & (1 << TSDB_MOD_MGMT)) { - mTrace("mgmt is running, clean it up"); - taosTmrStopA(&mgmtStatisticTimer); - sdbCleanUpPeers(); - mgmtCleanupBalance(); - mgmtCleanUpDnodeInt(); - mgmtCleanUpShell(); - mgmtCleanUpMeters(); - mgmtCleanUpVgroups(); - mgmtCleanUpDbs(); - mgmtCleanUpDnodes(); - mgmtCleanUpUsers(); - mgmtCleanUpAccts(); - taosTmrCleanUp(mgmtTmr); - taosCleanUpScheduler(mgmtQhandle); - taosCleanUpScheduler(mgmtTranQhandle); - } else { - mgmtCleanUpRedirect(); - } - - mgmtTmr = NULL; - mgmtQhandle = NULL; - mgmtShellConns = 0; - mgmtDnodeConns = 0; - tclearModuleStatus(TSDB_MOD_MGMT); - pShellConn = NULL; - - mTrace("mgmt is cleaned up"); + mPrint("starting to clean up mgmt"); + + taosTmrStopA(&tsMgmtStatisTimer); + mgmtCleanUpRedirect(); + sdbCleanUpPeers(); + mgmtCleanupBalance(); + mgmtCleanUpDnodeInt(); + mgmtCleanUpShell(); + mgmtCleanUpMeters(); + mgmtCleanUpVgroups(); + mgmtCleanUpDbs(); + mgmtCleanUpDnodes(); + mgmtCleanUpUsers(); + mgmtCleanUpAccts(); + taosTmrCleanUp(tsMgmtTmr); + taosCleanUpScheduler(tsMgmtTranQhandle); + + mPrint("mgmt is cleaned up"); } -int mgmtStartSystem() { +int32_t mgmtStartSystem() { mPrint("starting to initialize TDengine mgmt ..."); struct stat dirstat; - if (stat(mgmtDirectory, &dirstat) < 0) { - mkdir(mgmtDirectory, 0755); + if (stat(tsMgmtDirectory, &dirstat) < 0) { + mkdir(tsMgmtDirectory, 0755); } if (mgmtCheckMgmtRunning() != 0) { @@ -90,14 +69,10 @@ int mgmtStartSystem() { return 0; } - int numOfThreads = tsNumOfCores * tsNumOfThreadsPerCore / 2.0; - if (numOfThreads < 1) numOfThreads = 1; - mgmtQhandle = taosInitScheduler(tsMaxDnodes + tsMaxShellConns, numOfThreads, "mnode"); - - mgmtTranQhandle = taosInitScheduler(tsMaxDnodes + tsMaxShellConns, 1, "mnodeT"); + tsMgmtTranQhandle = taosInitScheduler(tsMaxDnodes + tsMaxShellConns, 1, "mnodeT"); - mgmtTmr = taosTmrInit((tsMaxDnodes + tsMaxShellConns) * 3, 200, 3600000, "MND"); - if (mgmtTmr == NULL) { + tsMgmtTmr = taosTmrInit((tsMaxDnodes + tsMaxShellConns) * 3, 200, 3600000, "MND"); + if (tsMgmtTmr == NULL) { mError("failed to init timer, exit"); return -1; } @@ -142,7 +117,7 @@ int mgmtStartSystem() { return -1; } - if (sdbInitPeers(mgmtDirectory) < 0) { + if (sdbInitPeers(tsMgmtDirectory) < 0) { mError("failed to init peers"); return -1; } @@ -153,9 +128,7 @@ int mgmtStartSystem() { mgmtCheckAcct(); - taosTmrReset(mgmtDoStatistic, tsStatusInterval * 30000, NULL, mgmtTmr, &mgmtStatisticTimer); - - mgmtStartMgmtTimer(); + taosTmrReset(mgmtDoStatistic, tsStatusInterval * 30000, NULL, tsMgmtTmr, &tsMgmtStatisTimer); mPrint("TDengine mgmt is initialized successfully"); @@ -163,26 +136,31 @@ int mgmtStartSystem() { } int32_t mgmtInitSystemImp() { - return mgmtStartSystem(); + int32_t code = mgmtStartSystem(); + if (code != 0) { + return code; + } + + taosTmrReset(mgmtProcessDnodeStatus, 500, NULL, tsMgmtTmr, &mgmtStatusTimer); + return code; } int32_t (*mgmtInitSystem)() = mgmtInitSystemImp; -int32_t mgmtCheckMgmtRunningImp() { return 0; } +int32_t mgmtCheckMgmtRunningImp() { + return 0; +} + int32_t (*mgmtCheckMgmtRunning)() = mgmtCheckMgmtRunningImp; void mgmtDoStatisticImp(void *handle, void *tmrId) {} -void (*mgmtDoStatistic)(void *handle, void *tmrId) = mgmtDoStatisticImp; -void mgmtStartMgmtTimerImp() { - taosTmrReset(mgmtProcessDnodeStatus, 500, NULL, mgmtTmr, &mgmtStatusTimer); -} -void (*mgmtStartMgmtTimer)() = mgmtStartMgmtTimerImp; +void (*mgmtDoStatistic)(void *handle, void *tmrId) = mgmtDoStatisticImp; void mgmtStopSystemImp() {} void (*mgmtStopSystem)() = mgmtStopSystemImp; void mgmtCleanUpRedirectImp() {} -void (*mgmtCleanUpRedirect)() = mgmtCleanUpRedirectImp; +void (*mgmtCleanUpRedirect)() = mgmtCleanUpRedirectImp; diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index 1e2a782d09..259b9d5e87 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -68,7 +68,7 @@ int mgmtInitUsers() { mgmtUserActionInit(); - userSdb = sdbOpenTable(tsMaxUsers, sizeof(SUserObj), "user", SDB_KEYTYPE_STRING, mgmtDirectory, mgmtUserAction); + userSdb = sdbOpenTable(tsMaxUsers, sizeof(SUserObj), "user", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtUserAction); if (userSdb == NULL) { mError("failed to init user data"); return -1; diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index 18f23d6fb6..0d7e8af293 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -76,7 +76,7 @@ int mgmtInitVgroups() { SVgObj tObj; tsVgUpdateSize = tObj.updateEnd - (int8_t *)&tObj; - vgSdb = sdbOpenTable(tsMaxVGroups, sizeof(SVgObj), "vgroups", SDB_KEYTYPE_AUTO, mgmtDirectory, mgmtVgroupAction); + vgSdb = sdbOpenTable(tsMaxVGroups, sizeof(SVgObj), "vgroups", SDB_KEYTYPE_AUTO, tsMgmtDirectory, mgmtVgroupAction); if (vgSdb == NULL) { mError("failed to init vgroup data"); return -1; @@ -205,7 +205,7 @@ SVgObj *mgmtCreateVgroup(SDbObj *pDb) { mError("db:%s, no enough free dnode to alloc %d vnodes", pDb->name, pVgroup->numOfVnodes); free(pVgroup); pDb->vgStatus = TSDB_VG_STATUS_FULL; - taosTmrReset(mgmtProcessVgTimer, 5000, pDb, mgmtTmr, &pDb->vgTimer); + taosTmrReset(mgmtProcessVgTimer, 5000, pDb, tsMgmtTmr, &pDb->vgTimer); return NULL; } diff --git a/src/util/inc/tglobalcfg.h b/src/util/inc/tglobalcfg.h index 6448e379b9..fa823c5a3b 100644 --- a/src/util/inc/tglobalcfg.h +++ b/src/util/inc/tglobalcfg.h @@ -262,7 +262,7 @@ SGlobalConfig *tsGetConfigOption(const char *option); #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) -extern char mgmtDirectory[]; +extern char tsMgmtDirectory[]; #ifdef __cplusplus diff --git a/src/vnode/detail/inc/vnode.h b/src/vnode/detail/inc/vnode.h index b3cb67b34b..481dbb19dd 100644 --- a/src/vnode/detail/inc/vnode.h +++ b/src/vnode/detail/inc/vnode.h @@ -564,7 +564,7 @@ extern int (*pDecompFunc[])(const char *const input, int compressedSize, const i // global variable and APIs provided by mgmt extern char mgmtStatus; -extern char mgmtDirectory[]; +extern char tsMgmtDirectory[]; extern const int16_t vnodeFileVersion; #ifdef __cplusplus -- GitLab