commit
abc28ce5af
|
@ -116,7 +116,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char name[TSDB_FILENAME_LEN];
|
||||
int32_t level;
|
||||
int8_t level;
|
||||
SDiskSize size;
|
||||
} SMonDiskDesc;
|
||||
|
||||
|
@ -126,10 +126,17 @@ typedef struct {
|
|||
SMonDiskDesc tempdir;
|
||||
} SMonDiskInfo;
|
||||
|
||||
typedef enum {
|
||||
MON_LEVEL_ERROR = 0,
|
||||
MON_LEVEL_INFO = 1,
|
||||
MON_LEVEL_DEBUG = 2,
|
||||
MON_LEVEL_TRACE = 3,
|
||||
} EMonLogLevel;
|
||||
|
||||
typedef struct {
|
||||
int64_t ts;
|
||||
int8_t level;
|
||||
char content[MON_LOG_LEN];
|
||||
int64_t ts;
|
||||
EMonLogLevel level;
|
||||
char content[MON_LOG_LEN];
|
||||
} SMonLogItem;
|
||||
|
||||
typedef struct SMonInfo SMonInfo;
|
||||
|
|
|
@ -155,21 +155,40 @@ static void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t prima
|
|||
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
|
||||
}
|
||||
|
||||
static void taosSetTfsCfg(SConfig *pCfg) {
|
||||
static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
||||
SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
|
||||
if (pItem == NULL) return;
|
||||
memset(tsDataDir, 0, PATH_MAX);
|
||||
|
||||
int32_t size = taosArrayGetSize(pItem->array);
|
||||
if (size <= 0) {
|
||||
tsDiskCfgNum = 1;
|
||||
taosAddDataDir(0, pItem->str, 0, 1);
|
||||
tstrncpy(tsDataDir, pItem->str, PATH_MAX);
|
||||
if (taosMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
tsDiskCfgNum = size < TFS_MAX_DISKS ? size : TFS_MAX_DISKS;
|
||||
for (int32_t index = 0; index < tsDiskCfgNum; ++index) {
|
||||
SDiskCfg *pCfg = taosArrayGet(pItem->array, index);
|
||||
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
|
||||
if (pCfg->level == 0 && pCfg->primary == 1) {
|
||||
tstrncpy(tsDataDir, pCfg->dir, PATH_MAX);
|
||||
}
|
||||
if (taosMkDir(pCfg->dir) != 0) {
|
||||
uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tsDataDir[0] == 0) {
|
||||
uError("datadir not set");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct SConfig *taosGetCfg() {
|
||||
|
@ -358,7 +377,7 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
|
|||
fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32;
|
||||
}
|
||||
|
||||
static void taosSetClientCfg(SConfig *pCfg) {
|
||||
static int32_t taosSetClientCfg(SConfig *pCfg) {
|
||||
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN);
|
||||
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
||||
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
||||
|
@ -375,9 +394,13 @@ static void taosSetClientCfg(SConfig *pCfg) {
|
|||
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
|
||||
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
|
||||
|
||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
|
||||
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
|
||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
||||
if (taosMkDir(tsTempDir) != 0) {
|
||||
uError("failed to create tempDir:%s since %s", tsTempDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
|
||||
tsMaxTmrCtrl = cfgGetItem(pCfg, "maxTmrCtrl")->i32;
|
||||
|
@ -392,6 +415,8 @@ static void taosSetClientCfg(SConfig *pCfg) {
|
|||
tsMaxNumOfOrderedResults = cfgGetItem(pCfg, "maxNumOfOrderedRes")->i32;
|
||||
tsKeepOriginalColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||
tsMaxBinaryDisplayWidth = cfgGetItem(pCfg, "maxBinaryDisplayWidth")->i32;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void taosSetSystemCfg(SConfig *pCfg) {
|
||||
|
@ -411,11 +436,8 @@ static void taosSetSystemCfg(SConfig *pCfg) {
|
|||
tsVersion = 30000000;
|
||||
}
|
||||
|
||||
static void taosSetServerCfg(SConfig *pCfg) {
|
||||
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
|
||||
taosExpandDir(tsDataDir, tsDataDir, PATH_MAX);
|
||||
|
||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
||||
static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||
tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
||||
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
||||
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
|
||||
tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32;
|
||||
|
@ -444,6 +466,8 @@ static void taosSetServerCfg(SConfig *pCfg) {
|
|||
if (tsQueryBufferSize >= 0) {
|
||||
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
|
@ -504,8 +528,8 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
|||
tsCfg = cfgInit();
|
||||
|
||||
if (tsc) {
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
} else {
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
||||
|
@ -528,24 +552,14 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
|||
}
|
||||
|
||||
if (tsc) {
|
||||
taosSetClientCfg(tsCfg);
|
||||
if (taosSetClientCfg(tsCfg)) return -1;
|
||||
} else {
|
||||
taosSetClientCfg(tsCfg);
|
||||
taosSetServerCfg(tsCfg);
|
||||
taosSetTfsCfg(tsCfg);
|
||||
if (taosSetClientCfg(tsCfg)) return -1;
|
||||
if (taosSetServerCfg(tsCfg)) return -1;
|
||||
if (taosSetTfsCfg(tsCfg) != 0) return -1;
|
||||
}
|
||||
taosSetSystemCfg(tsCfg);
|
||||
|
||||
if (taosMkDir(tsTempDir) != 0) {
|
||||
uError("failed to create dir:%s since %s", tsTempDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!tsc && taosMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfgDumpCfg(tsCfg, tsc, false);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -924,4 +924,7 @@ static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t mndGetNumOfConnections(SMnode *pMnode) { return taosHashGetSize(pMnode->profileMgmt.cache->pHashTable); }
|
||||
int32_t mndGetNumOfConnections(SMnode *pMnode) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
return taosCacheGetNumOfObj(pMgmt->cache);
|
||||
}
|
|
@ -270,6 +270,21 @@ void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) {
|
|||
tjsonAddDoubleToObject(pTempdirJson, "total", pInfo->tempdir.size.total);
|
||||
}
|
||||
|
||||
static const char *monLogLevelStr(EMonLogLevel level) {
|
||||
switch (level) {
|
||||
case MON_LEVEL_ERROR:
|
||||
return "error";
|
||||
case MON_LEVEL_INFO:
|
||||
return "info";
|
||||
case MON_LEVEL_DEBUG:
|
||||
return "debug";
|
||||
case MON_LEVEL_TRACE:
|
||||
return "trace";
|
||||
default:
|
||||
return "undefine";
|
||||
}
|
||||
}
|
||||
|
||||
static void monSetLogInfo(SMonInfo *pMonitor) {
|
||||
SJson *pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) return;
|
||||
|
@ -291,7 +306,7 @@ static void monSetLogInfo(SMonInfo *pMonitor) {
|
|||
taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI);
|
||||
|
||||
tjsonAddStringToObject(pLogJson, "ts", buf);
|
||||
tjsonAddDoubleToObject(pLogJson, "level", pLogItem->level);
|
||||
tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level));
|
||||
tjsonAddStringToObject(pLogJson, "content", pLogItem->content);
|
||||
|
||||
if (tjsonAddItemToArray(pLogsJson, pLogJson) != 0) tjsonDelete(pLogJson);
|
||||
|
|
|
@ -195,19 +195,19 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) {
|
|||
void MonitorTest::AddLogInfo1() {
|
||||
SMonLogItem log1 = {0};
|
||||
log1.ts = taosGetTimestampMs();
|
||||
log1.level = 1;
|
||||
log1.level = MON_LEVEL_INFO;
|
||||
strcpy(log1.content, "1 -------------------------- a");
|
||||
monAddLogItem(&log1);
|
||||
|
||||
SMonLogItem log2 = {0};
|
||||
log2.ts = taosGetTimestampMs();
|
||||
log2.level = 1;
|
||||
log2.level = MON_LEVEL_ERROR;
|
||||
strcpy(log2.content, "1 ------------------------ b");
|
||||
monAddLogItem(&log2);
|
||||
|
||||
SMonLogItem log3 = {0};
|
||||
log3.ts = taosGetTimestampMs();
|
||||
log3.level = 1;
|
||||
log3.level = MON_LEVEL_DEBUG;
|
||||
strcpy(log3.content, "1 ------- c");
|
||||
monAddLogItem(&log3);
|
||||
}
|
||||
|
@ -215,13 +215,13 @@ void MonitorTest::AddLogInfo1() {
|
|||
void MonitorTest::AddLogInfo2() {
|
||||
SMonLogItem log1;
|
||||
log1.ts = taosGetTimestampMs();
|
||||
log1.level = 01;
|
||||
log1.level = MON_LEVEL_ERROR;
|
||||
strcpy(log1.content, "2 ------- a");
|
||||
monAddLogItem(&log1);
|
||||
|
||||
SMonLogItem log2;
|
||||
log2.ts = taosGetTimestampMs();
|
||||
log2.level = 0;
|
||||
log2.level = MON_LEVEL_ERROR;
|
||||
strcpy(log2.content, "2 ------- b");
|
||||
monAddLogItem(&log2);
|
||||
}
|
||||
|
|
|
@ -145,14 +145,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (taosMkDir(fullDir) != 0) {
|
||||
uError("failed to create dir:%s realpath:%s since %s", inputDir, fullDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
cfgFreeItem(pItem);
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(fullDir);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -647,7 +640,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE);
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0) {
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_CFG_FILE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue