提交 dfafa1be 编写于 作者: S slguan

reorganize the file mgmtSystem.c

上级 23693d9c
......@@ -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);
......
......@@ -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;
......
......@@ -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)();
......
......@@ -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;
......
......@@ -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");
}
......
......@@ -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]);
// }
......
......@@ -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;
......
......@@ -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;
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册