From 4f353da40c9b57fb0b08fd34cd88efca2f0115ab Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 20:35:09 +0800 Subject: [PATCH] global config --- include/common/tglobal.h | 11 +------- include/os/osEnv.h | 15 +++++++++++ include/os/osSysinfo.h | 23 +++++++++++------ include/util/tlog.h | 1 - source/common/src/tglobal.c | 36 --------------------------- source/dnode/mgmt/daemon/src/dmnCfg.c | 16 ++++++------ source/dnode/mgmt/daemon/src/dmnLog.c | 2 ++ source/dnode/mgmt/impl/src/dndEnv.c | 12 --------- source/os/src/osEnv.c | 24 ++++++++++++++++++ source/util/src/tlog.c | 24 +++--------------- 10 files changed, 68 insertions(+), 96 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index ec3bac0736..3ad16c4cf4 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -56,16 +56,7 @@ extern int32_t tsProjectExecInterval; extern int64_t tsMaxRetentWindow; // system info -extern float tsTotalLogDirGB; -extern float tsTotalTmpDirGB; -extern float tsTotalDataDirGB; -extern float tsAvailLogDirGB; -extern float tsAvailTmpDirectorySpace; -extern float tsAvailDataDirGB; -extern float tsUsedDataDirGB; -extern float tsMinimalLogDirGB; -extern float tsReservedTmpDirectorySpace; -extern float tsMinimalDataDirGB; + extern uint32_t tsVersion; // build info diff --git a/include/os/osEnv.h b/include/os/osEnv.h index fec3b1abc4..2745520ae3 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -21,9 +21,24 @@ extern "C" { #endif extern char tsOsName[]; + extern char tsDataDir[]; +extern char tsLogDir[]; +extern char tsTempDir[]; extern char configDir[]; +extern struct SDiskSpace tsLogSpace; +extern struct SDiskSpace tsTempSpace; +extern struct SDiskSpace tsDataSpace; + +void taosUpdateLogSpace(); +void taosUpdateTempSpace(); +void taosUpdateDataSpace(); +bool taosLogSpaceAvailable(); +bool taosTmpSpaceAvailable(); +bool taosDataSpaceAvailable(); +void taosUpdateAllSpace(); + #ifdef __cplusplus } #endif diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 9dcb075489..6ab2a104df 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -25,20 +25,27 @@ extern "C" { #define TSDB_LOCALE_LEN 64 #define TSDB_TIMEZONE_LEN 96 +typedef struct { + int64_t total; + int64_t used; + int64_t avail; +} SDiskSize; + +typedef struct SDiskSpace { + int64_t reserved; + SDiskSize size; +} SDiskSpace; + extern int64_t tsPageSize; extern int64_t tsOpenMax; extern int64_t tsStreamMax; extern int32_t tsNumOfCores; extern int32_t tsTotalMemoryMB; -extern char tsTimezone[]; -extern char tsLocale[]; -extern char tsCharset[]; // default encode string +extern char tsTimezone[]; +extern char tsLocale[]; +extern char tsCharset[]; // default encode string + -typedef struct { - int64_t total; - int64_t used; - int64_t avail; -} SDiskSize; int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); int32_t taosGetCpuCores(); diff --git a/include/util/tlog.h b/include/util/tlog.h index cdcac84ab7..166e186508 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -22,7 +22,6 @@ extern "C" { #endif -extern char tsLogDir[]; extern bool tsLogInited; extern bool tsAsyncLog; extern int32_t tsNumOfLogLines; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 86af06d31a..72783bf4ab 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -119,13 +119,6 @@ bool tsdbForceKeepFile = false; int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L}; // system info -float tsTotalTmpDirGB = 0; -float tsTotalDataDirGB = 0; -float tsAvailTmpDirectorySpace = 0; -float tsAvailDataDirGB = 0; -float tsUsedDataDirGB = 0; -float tsReservedTmpDirectorySpace = 1.0f; -float tsMinimalDataDirGB = 2.0f; int32_t tsTotalMemoryMB = 0; uint32_t tsVersion = 0; @@ -422,35 +415,6 @@ static void doInitGlobalConfig(void) { taosAddConfigOption(cfg); - cfg.option = "minimalLogDirGB"; - cfg.ptr = &tsMinimalLogDirGB; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 0.001f; - cfg.maxValue = 10000000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_GB; - taosAddConfigOption(cfg); - - cfg.option = "minimalTmpDirGB"; - cfg.ptr = &tsReservedTmpDirectorySpace; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 0.001f; - cfg.maxValue = 10000000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_GB; - taosAddConfigOption(cfg); - - cfg.option = "minimalDataDirGB"; - cfg.ptr = &tsMinimalDataDirGB; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 0.001f; - cfg.maxValue = 10000000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_GB; - taosAddConfigOption(cfg); cfg.option = "slaveQuery"; cfg.ptr = &tsEnableSlaveQuery; diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index 85a9a28750..7bf538caed 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -41,17 +41,17 @@ static int32_t dmnAddEpCfg(SConfig *pCfg) { static int32_t dmnAddDirCfg(SConfig *pCfg) { if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1; - if (cfgAddDir(pCfg, "tmpDir", tsTempDir) != 0) return -1; + if (cfgAddDir(pCfg, "tempDir", tsTempDir) != 0) return -1; + if (cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000) != 0) return -1; + if (cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000) != 0) return -1; return 0; } -static int32_t dmnCheckDirCfg(SConfig *pCfg) { - SConfigItem *pItem = NULL; - - pItem = cfgGetItem(pCfg, "tmpDir"); - if (taosDirExist(pItem->str) != 0) { - return -1; - } +static int32_t dmnCheckDirCfg(SConfig *pCfg) { + tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX); + tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); + tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval; + tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; return 0; } diff --git a/source/dnode/mgmt/daemon/src/dmnLog.c b/source/dnode/mgmt/daemon/src/dmnLog.c index 3ec43cb7f3..22a7d7b080 100644 --- a/source/dnode/mgmt/daemon/src/dmnLog.c +++ b/source/dnode/mgmt/daemon/src/dmnLog.c @@ -18,6 +18,7 @@ int32_t dmnAddLogCfg(SConfig *pCfg) { if (cfgAddDir(pCfg, "logDir", "/var/log/taos") != 0) return -1; + if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000) != 0) return -1; if (cfgAddBool(pCfg, "asyncLog", 1) != 0) return -1; if (cfgAddInt32(pCfg, "numOfLogLines", 10000000, 1000, 2000000000) != 0) return -1; if (cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000) != 0) return -1; @@ -41,6 +42,7 @@ int32_t dmnAddLogCfg(SConfig *pCfg) { int32_t dmnSetLogCfg(SConfig *pCfg) { tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX); + tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval; tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32; diff --git a/source/dnode/mgmt/impl/src/dndEnv.c b/source/dnode/mgmt/impl/src/dndEnv.c index 02dced53c2..58517c8151 100644 --- a/source/dnode/mgmt/impl/src/dndEnv.c +++ b/source/dnode/mgmt/impl/src/dndEnv.c @@ -325,18 +325,6 @@ void taosGetDisk() { SDiskSize diskSize = tfsGetSize(pTfs); tfsUpdateSize(&fsMeta); - tsTotalDataDirGB = (float)(fsMeta.total / unit); - tsUsedDataDirGB = (float)(fsMeta.used / unit); - tsAvailDataDirGB = (float)(fsMeta.avail / unit); - if (taosGetDiskSize(tsLogDir, &diskSize) == 0) { - tsTotalLogDirGB = (float)(diskSize.total / unit); - tsAvailLogDirGB = (float)(diskSize.avail / unit); - } - - if (taosGetDiskSize(tsTempDir, &diskSize) == 0) { - tsTotalTmpDirGB = (float)(diskSize.total / unit); - tsAvailTmpDirectorySpace = (float)(diskSize.avail / unit); - } #endif } \ No newline at end of file diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 38e564fa9d..a7868323e2 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -16,6 +16,30 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "osEnv.h" +#include "osSysinfo.h" + +SDiskSpace tsLogSpace; +SDiskSpace tsTempSpace; +SDiskSpace tsDataSpace; + +void taosUpdateLogSpace() { taosGetDiskSize(tsLogDir, &tsLogSpace.size); } + +void taosUpdateTempSpace() { taosGetDiskSize(tsTempDir, &tsTempSpace.size); } + +void taosUpdateDataSpace() { taosGetDiskSize(tsDataDir, &tsDataSpace.size); } + +bool taosLogSpaceAvailable() { return tsDataSpace.reserved > tsDataSpace.size.avail; } + +bool taosTempSpaceAvailable() { return tsTempSpace.reserved > tsTempSpace.size.avail; } + +bool taosDataSpaceAvailable() { return tsDataSpace.reserved > tsDataSpace.size.avail; } + +void taosUpdateAllSpace() { + taosUpdateLogSpace(); + taosUpdateTempSpace(); + taosUpdateDataSpace(); +} #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index ecd0f0437b..79209d09f6 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -72,9 +72,6 @@ int8_t tscEmbeddedInUtil = 0; int32_t tsLogKeepDays = 0; bool tsAsyncLog = true; bool tsLogInited = false; -float tsTotalLogDirGB = 0; -float tsAvailLogDirGB = 0; -float tsMinimalLogDirGB = 1.0f; int64_t asyncLogLostLines = 0; int32_t writeInterval = DEFAULT_LOG_INTERVAL; @@ -383,12 +380,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { } void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { - if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { - printf("server disk:%s space remain %.3f GB, total %.1f GB, stop print log.\n", tsLogDir, tsAvailLogDirGB, - tsTotalLogDirGB); - fflush(stdout); - return; - } + if (!taosLogSpaceAvailable()) return; va_list argpointer; char buffer[MAX_LOGLINE_BUFFER_SIZE] = {0}; @@ -443,12 +435,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { } void taosDumpData(unsigned char *msg, int32_t len) { - if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { - printf("server disk:%s space remain %.3f GB, total %.1f GB, stop dump log.\n", tsLogDir, tsAvailLogDirGB, - tsTotalLogDirGB); - fflush(stdout); - return; - } + if (!taosLogSpaceAvailable()) return; char temp[256]; int32_t i, pos = 0, c = 0; @@ -471,12 +458,7 @@ void taosDumpData(unsigned char *msg, int32_t len) { } void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...) { - if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { - printf("server disk:%s space remain %.3f GB, total %.1f GB, stop write log.\n", tsLogDir, tsAvailLogDirGB, - tsTotalLogDirGB); - fflush(stdout); - return; - } + if (!taosLogSpaceAvailable()) return; va_list argpointer; char buffer[MAX_LOGLINE_DUMP_BUFFER_SIZE]; -- GitLab