From 20f2a7b71e0d59b911196f9837263151ec8a1fa1 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 19 Mar 2021 13:21:43 +0800 Subject: [PATCH] [TD-3370]: fix used disk size, show acctual used instead of non-avail to current user --- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 1 + src/inc/tfs.h | 3 ++- src/os/inc/osSysinfo.h | 1 + src/os/src/darwin/darwinSysInfo.c | 3 +++ src/os/src/detail/osSysinfo.c | 3 +++ src/os/src/windows/wSysinfo.c | 5 ++++- src/plugins/monitor/src/monMain.c | 2 +- src/tfs/inc/tfsint.h | 5 ++++- src/tfs/src/tdisk.c | 1 + src/tfs/src/tfs.c | 2 ++ src/tfs/src/ttier.c | 3 ++- 12 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index df1a622101..3f96466cc0 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -163,6 +163,7 @@ extern float tsTotalDataDirGB; extern float tsAvailLogDirGB; extern float tsAvailTmpDirectorySpace; extern float tsAvailDataDirGB; +extern float tsUsedDataDirGB; extern float tsMinimalLogDirGB; extern float tsReservedTmpDirectorySpace; extern float tsMinimalDataDirGB; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 9e405fdfe1..4a5df9361b 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -210,6 +210,7 @@ float tsTotalTmpDirGB = 0; float tsTotalDataDirGB = 0; float tsAvailTmpDirectorySpace = 0; float tsAvailDataDirGB = 0; +float tsUsedDataDirGB = 0; float tsReservedTmpDirectorySpace = 1.0f; float tsMinimalDataDirGB = 1.0f; int32_t tsTotalMemoryMB = 0; diff --git a/src/inc/tfs.h b/src/inc/tfs.h index 76e9b17a62..4ed21bc6e1 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -35,6 +35,7 @@ typedef struct { // FS APIs ==================================== typedef struct { int64_t tsize; + int64_t used; int64_t avail; } SFSMeta; @@ -90,4 +91,4 @@ void tfsClosedir(TDIR *tdir); } #endif -#endif \ No newline at end of file +#endif diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index 25c9c97b1e..895b5dd499 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -23,6 +23,7 @@ extern "C" { // TAOS_OS_FUNC_SYSINFO typedef struct { int64_t tsize; + int64_t used; int64_t avail; } SysDiskSize; diff --git a/src/os/src/darwin/darwinSysInfo.c b/src/os/src/darwin/darwinSysInfo.c index 6af6285f56..55c07766b3 100644 --- a/src/os/src/darwin/darwinSysInfo.c +++ b/src/os/src/darwin/darwinSysInfo.c @@ -138,6 +138,8 @@ void taosPrintOsInfo() { // uInfo(" os streamMax: %" PRId64, tsStreamMax); uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); + uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB); + uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); struct utsname buf; @@ -222,6 +224,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } else { diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize; + diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; return 0; } } diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index f12ec93bf7..c0d46878a8 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -326,6 +326,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } else { diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize; + diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; return 0; } } @@ -506,6 +507,8 @@ void taosPrintOsInfo() { uInfo(" os streamMax: %" PRId64, tsStreamMax); uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); + uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB); + uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); struct utsname buf; diff --git a/src/os/src/windows/wSysinfo.c b/src/os/src/windows/wSysinfo.c index 48fb3c13a8..8a81e3079a 100644 --- a/src/os/src/windows/wSysinfo.c +++ b/src/os/src/windows/wSysinfo.c @@ -136,7 +136,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { (PULARGE_INTEGER)&i64FreeBytes); if (fResult) { diskSize->tsize = (int64_t)(i64TotalBytes); - diskSize->avail = (int64_t)(i64FreeBytes); + diskSize->avail = (int64_t)(i64FreeBytesToCaller); + diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); return 0; } else { uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); @@ -205,6 +206,8 @@ void taosGetSystemInfo() { void taosPrintOsInfo() { uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); + uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB); + uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); uInfo("=================================="); } diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index ac80ad6250..94af8e3ecd 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -292,7 +292,7 @@ static int32_t monBuildCpuSql(char *sql) { // unit is GB static int32_t monBuildDiskSql(char *sql) { - return sprintf(sql, ", %f, %d", (tsTotalDataDirGB - tsAvailDataDirGB), (int32_t)tsTotalDataDirGB); + return sprintf(sql, ", %f, %d", tsUsedDataDirGB, (int32_t)tsTotalDataDirGB); } // unit is Kb diff --git a/src/tfs/inc/tfsint.h b/src/tfs/inc/tfsint.h index fa4cd59723..619ef6df73 100644 --- a/src/tfs/inc/tfsint.h +++ b/src/tfs/inc/tfsint.h @@ -41,6 +41,7 @@ extern int fsDebugFlag; // tdisk.c ====================================================== typedef struct { int64_t size; + int64_t used; int64_t free; } SDiskMeta; @@ -56,6 +57,7 @@ typedef struct SDisk { #define DISK_DIR(pd) ((pd)->dir) #define DISK_META(pd) ((pd)->dmeta) #define DISK_SIZE(pd) ((pd)->dmeta.size) +#define DISK_USED_SIZE(pd) ((pd)->dmeta.used) #define DISK_FREE_SIZE(pd) ((pd)->dmeta.free) SDisk *tfsNewDisk(int level, int id, const char *dir); @@ -65,6 +67,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk); // ttier.c ====================================================== typedef struct { int64_t size; + int64_t used; int64_t free; int16_t nAvailDisks; // # of Available disks } STierMeta; @@ -96,4 +99,4 @@ void tfsPosNextId(STier *pTier); } #endif -#endif \ No newline at end of file +#endif diff --git a/src/tfs/src/tdisk.c b/src/tfs/src/tdisk.c index 37798d3a88..28c836e5d9 100644 --- a/src/tfs/src/tdisk.c +++ b/src/tfs/src/tdisk.c @@ -52,6 +52,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk) { } pDisk->dmeta.size = diskSize.tsize; + pDisk->dmeta.used = diskSize.used; pDisk->dmeta.free = diskSize.avail; return code; diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index 7b7c9b6127..63fc090f00 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -134,6 +134,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta) { tfsUpdateTierInfo(pTier, &tierMeta); pFSMeta->tsize += tierMeta.size; pFSMeta->avail += tierMeta.free; + pFSMeta->used += tierMeta.used; } tfsLock(); @@ -585,6 +586,7 @@ void taosGetDisk() { if (tscEmbedded) { tfsUpdateInfo(&fsMeta); tsTotalDataDirGB = (float)(fsMeta.tsize / unit); + tsUsedDataDirGB = (float)(fsMeta.used / unit); tsAvailDataDirGB = (float)(fsMeta.avail / unit); } diff --git a/src/tfs/src/ttier.c b/src/tfs/src/ttier.c index 2dce0c3194..3b19797acf 100644 --- a/src/tfs/src/ttier.c +++ b/src/tfs/src/ttier.c @@ -100,6 +100,7 @@ void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) { continue; } pTierMeta->size += DISK_SIZE(DISK_AT_TIER(pTier, id)); + pTierMeta->used += DISK_USED_SIZE(DISK_AT_TIER(pTier, id)); pTierMeta->free += DISK_FREE_SIZE(DISK_AT_TIER(pTier, id)); pTierMeta->nAvailDisks++; } @@ -166,4 +167,4 @@ void tfsPosNextId(STier *pTier) { } pTier->nextid = nextid; -} \ No newline at end of file +} -- GitLab