From 382adfac68782a4d8f611ec037282d58e7858ac8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 26 Oct 2020 10:47:46 +0800 Subject: [PATCH] TD-1413 --- src/client/src/tscSystem.c | 9 +++--- src/common/inc/tsystem.h | 38 ----------------------- src/common/src/tdisk.c | 31 ++++++++++++++++--- src/mnode/src/mnodePeer.c | 1 - src/os/inc/osSysinfo.h | 8 ++++- src/os/src/darwin/darwinSysInfo.c | 2 +- src/os/src/detail/osSysinfo.c | 44 +++++---------------------- src/os/src/windows/wSysinfo.c | 2 +- src/plugins/monitor/src/monitorMain.c | 5 --- src/rpc/src/rpcUdp.c | 1 - src/util/src/tconfig.c | 1 - 11 files changed, 47 insertions(+), 95 deletions(-) delete mode 100644 src/common/inc/tsystem.h diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 47c2d35a75..1895591e4a 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -17,7 +17,6 @@ #include "taosmsg.h" #include "tcache.h" #include "trpc.h" -#include "tsystem.h" #include "ttimer.h" #include "tutil.h" #include "tsched.h" @@ -43,7 +42,7 @@ static pthread_once_t tscinit = PTHREAD_ONCE_INIT; void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); //void tscUpdateEpSet(void *ahandle, SRpcEpSet *pEpSet); -void tscCheckDiskUsage(void *UNUSED_PARAM(para), void* UNUSED_PARAM(param)) { +void tscCheckDiskUsage(void *UNUSED_PARAM(para), void *UNUSED_PARAM(param)) { taosGetDisk(); taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr); } @@ -136,11 +135,11 @@ void taos_init_imp(void) { } tscTmr = taosTmrInit(tsMaxConnections * 2, 200, 60000, "TSC"); - if(0 == tscEmbedded){ - taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr); + if (0 == tscEmbedded) { + taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr); } - int64_t refreshTime = 10; // 10 seconds by default + int64_t refreshTime = 10; // 10 seconds by default if (tscMetaCache == NULL) { tscMetaCache = taosCacheInit(TSDB_DATA_TYPE_BINARY, refreshTime, false, tscFreeTableMetaHelper, "tableMeta"); tscObjCache = taosCacheInit(TSDB_CACHE_PTR_KEY, refreshTime / 2, false, tscFreeRegisteredSqlObj, "sqlObj"); diff --git a/src/common/inc/tsystem.h b/src/common/inc/tsystem.h deleted file mode 100644 index 93d305e49c..0000000000 --- a/src/common/inc/tsystem.h +++ /dev/null @@ -1,38 +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_TSYSTEM_H -#define TDENGINE_TSYSTEM_H - -#ifdef __cplusplus -extern "C" { -#endif - -bool taosGetSysMemory(float *memoryUsedMB); -bool taosGetProcMemory(float *memoryUsedMB); -bool taosGetDisk(); -bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); -bool taosGetBandSpeed(float *bandSpeedKb); -bool taosGetProcIO(float *readKB, float *writeKB); -void taosGetSystemInfo(); -void taosPrintOsInfo(); -void taosKillSystem(); -void taosSetCoreDump(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/common/src/tdisk.c b/src/common/src/tdisk.c index 0c7d633773..7eac65caa2 100644 --- a/src/common/src/tdisk.c +++ b/src/common/src/tdisk.c @@ -244,15 +244,15 @@ static int tdCheckDisk(char *dirName, int level, int primary) { } static int tdUpdateDiskMeta(SDisk *pDisk) { - struct statvfs dstat; - if (statvfs(pDisk->dir, &dstat) < 0) { + SysDiskSize dstat; + if (taosGetDiskSize(pDisk->dir, &dstat) < 0) { uError("failed to get dir %s information since %s", pDisk->dir, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - pDisk->dmeta.size = dstat.f_bsize * dstat.f_blocks; - pDisk->dmeta.free = dstat.f_bsize * dstat.f_bavail; + pDisk->dmeta.size = dstat.tsize; + pDisk->dmeta.free = dstat.avail; return 0; } @@ -349,4 +349,25 @@ static int tdAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary) pDnodeTier->nTiers = MAX(pDnodeTier->nTiers, level + 1); return 0; -} \ No newline at end of file +} + +void taosGetDisk() { + const double unit = 1024 * 1024 * 1024; + SysDiskSize diskSize; + + if (tscEmbedded) { + tdUpdateTiersInfo(tsDnodeTier); + tsTotalDataDirGB = (float)tsDnodeTier->meta.tsize / unit; + tsAvailDataDirGB = (float)tsDnodeTier->meta.avail / unit; + } + + if (taosGetDiskSize(tsLogDir, &diskSize)) { + tsTotalLogDirGB = (float)diskSize.tsize / unit; + tsAvailLogDirGB = (float)diskSize.avail / unit; + } + + if (taosGetDiskSize("/tmp", &diskSize)) { + tsTotalTmpDirGB = (float)diskSize.tsize / unit; + tsAvailTmpDirectorySpace = (float)diskSize.avail / unit; + } +} diff --git a/src/mnode/src/mnodePeer.c b/src/mnode/src/mnodePeer.c index 2a04f541c5..e95018ee0b 100644 --- a/src/mnode/src/mnodePeer.c +++ b/src/mnode/src/mnodePeer.c @@ -17,7 +17,6 @@ #include "os.h" #include "taoserror.h" #include "tsched.h" -#include "tsystem.h" #include "tutil.h" #include "tgrant.h" #include "tbalance.h" diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index 2b98f8b4bf..12a13a7160 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -21,10 +21,16 @@ extern "C" { #endif // TAOS_OS_FUNC_SYSINFO +typedef struct { + int64_t tsize; + int64_t avail; +} SysDiskSize; + +int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize); void taosGetSystemInfo(); bool taosGetProcIO(float *readKB, float *writeKB); bool taosGetBandSpeed(float *bandSpeedKb); -bool taosGetDisk(); +void taosGetDisk(); bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ; bool taosGetProcMemory(float *memoryUsedMB) ; bool taosGetSysMemory(float *memoryUsedMB); diff --git a/src/os/src/darwin/darwinSysInfo.c b/src/os/src/darwin/darwinSysInfo.c index f8aa02dcff..3014b141ee 100644 --- a/src/os/src/darwin/darwinSysInfo.c +++ b/src/os/src/darwin/darwinSysInfo.c @@ -67,7 +67,7 @@ void taosGetSystemInfo() { taosGetSystemLocale(); } -bool taosGetDisk() { return true; } +void taosGetDisk() {} bool taosGetProcIO(float *readKB, float *writeKB) { *readKB = 0; diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 87764de839..8cac60bfd6 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" #include "tconfig.h" +#include "tdisk.h" #include "tglobal.h" #include "tulog.h" @@ -297,45 +298,16 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { return true; } -bool taosGetDisk() { +int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { struct statvfs info; - const double unit = 1024 * 1024 * 1024; - -#if 0 - if (tscEmbedded) { - if (statvfs(tsDataDir, &info)) { - //tsTotalDataDirGB = 0; - //tsAvailDataDirGB = 0; - uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - return false; - } else { - tsTotalDataDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); - tsAvailDataDirGB = (float)((double)info.f_bavail * (double)info.f_frsize / unit); - } - } -#endif - - if (statvfs(tsLogDir, &info)) { - //tsTotalLogDirGB = 0; - //tsAvailLogDirGB = 0; - uError("failed to get disk size, logDir:%s errno:%s", tsLogDir, strerror(errno)); + if (statvfs(tsDataDir, &info)) { + uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); return false; } else { - tsTotalLogDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); - tsAvailLogDirGB = (float)((double)info.f_bavail * (double)info.f_frsize / unit); + diskSize->tsize = info.f_blocks * info.f_frsize; + diskSize->avail = info.f_bavail * info.f_frsize; + return true; } - - if (statvfs("/tmp", &info)) { - //tsTotalTmpDirGB = 0; - //tsAvailTmpDirectorySpace = 0; - uError("failed to get disk size, tmpDir:/tmp errno:%s", strerror(errno)); - return false; - } else { - tsTotalTmpDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); - tsAvailTmpDirectorySpace = (float)((double)info.f_bavail * (double)info.f_frsize / unit); - } - - return true; } static bool taosGetCardInfo(int64_t *bytes) { @@ -508,7 +480,7 @@ void taosGetSystemInfo() { float tmp1, tmp2; taosGetSysMemory(&tmp1); taosGetProcMemory(&tmp2); - taosGetDisk(); + // taosGetDisk(); taosGetBandSpeed(&tmp1); taosGetCpuUsage(&tmp1, &tmp2); taosGetProcIO(&tmp1, &tmp2); diff --git a/src/os/src/windows/wSysinfo.c b/src/os/src/windows/wSysinfo.c index 61adc3ee14..c77df71e8e 100644 --- a/src/os/src/windows/wSysinfo.c +++ b/src/os/src/windows/wSysinfo.c @@ -80,7 +80,7 @@ void taosGetSystemInfo() { taosGetSystemLocale(); } -bool taosGetDisk() { +void taosGetDisk() { const double unit = 1024 * 1024 * 1024; BOOL fResult; unsigned _int64 i64FreeBytesToCaller; diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index d5a661b31e..c182d85dac 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -21,7 +21,6 @@ #include "ttimer.h" #include "tutil.h" #include "tdisk.h" -#include "tsystem.h" #include "tscUtil.h" #include "tsclient.h" #include "dnode.h" @@ -126,10 +125,6 @@ static void *monitorThreadFunc(void *param) { break; } else { taosGetDisk(); - tdUpdateTiersInfo(tsDnodeTier); - const double unit = 1024 * 1024 * 1024; - tsTotalDataDirGB = tsDnodeTier->meta.tsize / unit; - tsAvailDataDirGB = tsDnodeTier->meta.avail / unit; } if (tsMonitor.start == 0) { diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 6f65304661..ad97c41083 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -15,7 +15,6 @@ #include "os.h" #include "tsocket.h" -#include "tsystem.h" #include "ttimer.h" #include "tutil.h" #include "taosdef.h" diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index c705848d5f..af54888cb4 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -22,7 +22,6 @@ #include "tkey.h" #include "tulog.h" #include "tsocket.h" -#include "tsystem.h" #include "tutil.h" SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};