diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 8f5d1dc52a39e0b51757ac1ea9d04145dc0af5bc..66d5fdcfbe03e7215263d2dd0a51fef7ae6c0de9 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -130,6 +130,7 @@ extern "C" { #define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered #define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered #define TSDB_CODE_INVALID_COMMIT_LOG 109 // invalid commit log may be caused by insufficient sotrage +#define TSDB_CODE_SERVER_NO_SPACE 110 // message type #define TSDB_MSG_TYPE_REG 1 diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 9fb9fb0ce07fe4d8c84df627ddfda17ba41ce01b..4d52b1614227c33b8f8ef197c96dd99b9bd953f4 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -30,6 +30,9 @@ extern int64_t tsOpenMax; extern int64_t tsStreamMax; extern int32_t tsNumOfCores; extern int32_t tsTotalDiskGB; +extern float tsDiskAvailGB; +extern float tsDiskUsedGB; +extern float tsDiskMinimalGB; extern int32_t tsTotalMemoryMB; extern int32_t tsVersion; diff --git a/src/inc/tsystem.h b/src/inc/tsystem.h index 521a831f3948020b4f19f5c27dfb040d1f7357e3..832956ae809bf1ac5bd6895da6a02b118c70487c 100644 --- a/src/inc/tsystem.h +++ b/src/inc/tsystem.h @@ -27,7 +27,7 @@ bool taosGetSysMemory(float *memoryUsedMB); bool taosGetProcMemory(float *memoryUsedMB); -bool taosGetDisk(float *diskUsedGB); +bool taosGetDisk(); bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); diff --git a/src/modules/monitor/src/monitorSystem.c b/src/modules/monitor/src/monitorSystem.c index ed6964df7a41bac6cbe64fcf99a33ace40dbd1e2..082cfb2e53ed1662b3576275fc134c3a3356a029 100644 --- a/src/modules/monitor/src/monitorSystem.c +++ b/src/modules/monitor/src/monitorSystem.c @@ -25,9 +25,10 @@ #include "ttimer.h" #include "tutil.h" -#define SQL_LENGTH 1024 -#define LOG_LEN_STR 80 -#define IP_LEN_STR 15 +#define SQL_LENGTH 1024 +#define LOG_LEN_STR 80 +#define IP_LEN_STR 15 +#define CHECK_INTERVAL 1000 typedef enum { MONITOR_CMD_CREATE_DB, @@ -53,6 +54,7 @@ typedef struct { int8_t state; char sql[SQL_LENGTH]; void * initTimer; + void * diskTimer; } MonitorConn; MonitorConn *monitor = NULL; @@ -69,9 +71,15 @@ void monitorSaveLog(int level, const char *const format, ...); void (*monitorCountReqFp)(SCountInfo *info) = NULL; void monitorExecuteSQL(char *sql); +void monitorCheckDiskUsage(void *para, void *unused) { + taosGetDisk(); + taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &monitor->diskTimer); +} + int monitorInitSystem() { monitor = (MonitorConn *)malloc(sizeof(MonitorConn)); memset(monitor, 0, sizeof(MonitorConn)); + taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &monitor->diskTimer); return 0; } @@ -265,13 +273,7 @@ int monitorBuildCpuSql(char *sql) { // unit is GB int monitorBuildDiskSql(char *sql) { - float diskUsedGB = 0; - bool suc = taosGetDisk(&diskUsedGB); - if (!suc) { - monitorError("monitor:%p, get disk info failed.", monitor->conn); - } - - return sprintf(sql, ", %f, %d", diskUsedGB, tsTotalDiskGB); + return sprintf(sql, ", %f, %d", tsDiskUsedGB, tsTotalDiskGB); } // unit is Kb diff --git a/src/rpc/src/tstring.c b/src/rpc/src/tstring.c index 3c52b0c8b4f7ef024cde3295f1c3932fecc08367..967008221b820a8697f023d89c46fb84027b771d 100644 --- a/src/rpc/src/tstring.c +++ b/src/rpc/src/tstring.c @@ -233,5 +233,6 @@ char *tsError[] = {"success", "invalid query message", "timestamp disordered in cache block", "timestamp disordered in file block", - "invalid commit log" + "invalid commit log", + "server no disk space", }; diff --git a/src/system/src/mgmtSystem.c b/src/system/src/mgmtSystem.c index 72cbd7c9c3ecea4448a054fd9d14b960b97819a7..018300bf61d7fe767739ffa86481a53a97128bb1 100644 --- a/src/system/src/mgmtSystem.c +++ b/src/system/src/mgmtSystem.c @@ -64,10 +64,7 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { float memoryUsedMB = 0; taosGetSysMemory(&memoryUsedMB); pObj->memoryAvailable = tsTotalMemoryMB - memoryUsedMB; - - float diskUsedGB = 0; - taosGetDisk(&diskUsedGB); - pObj->diskAvailable = tsTotalDiskGB - diskUsedGB; + pObj->diskAvailable = tsDiskAvailGB; for (int vnode = 0; vnode < pObj->numOfVnodes; ++vnode) { SVnodeLoad *pVload = &(pObj->vload[vnode]); diff --git a/src/system/src/vnodeShell.c b/src/system/src/vnodeShell.c index fda92d5d4c02dce2b066d79831eb573c3c7e72c2..27757d8a5cbef07123abc2f67a66a03b74bdb2e1 100644 --- a/src/system/src/vnodeShell.c +++ b/src/system/src/vnodeShell.c @@ -471,6 +471,12 @@ int vnodeProcessShellSubmitRequest(char *pMsg, int msgLen, SShellObj *pObj) { goto _submit_over; } + if (tsDiskAvailGB < tsDiskMinimalGB) { + dError("server disk space remain %.3f GB, need at least %.2f GB, stop writing", tsDiskAvailGB, tsDiskMinimalGB); + code = TSDB_CODE_SERVER_NO_SPACE; + goto _submit_over; + } + pObj->count = pSubmit->numOfSid; // for import pObj->code = 0; // for import pObj->numOfTotalPoints = 0; // for import diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index e16da7b40749565b12e2f5769c039ee8f6c48ffd..f9a9e2666a0beb6c84cf919c408c7baee60f99e0 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -33,9 +33,12 @@ int64_t tsPageSize; int64_t tsOpenMax; int64_t tsStreamMax; -int32_t tsNumOfCores; -int32_t tsTotalDiskGB; -int32_t tsTotalMemoryMB; +int32_t tsNumOfCores = 1; +int32_t tsTotalDiskGB = 0; +float tsDiskAvailGB = 0; +float tsDiskUsedGB = 0; +float tsDiskMinimalGB = 0.5; +int32_t tsTotalMemoryMB = 0; int32_t tsVersion = 0; // global, not configurable @@ -733,7 +736,7 @@ int tsCfgDynamicOptions(char *msg) { tsPrintGlobalConfig(); return code; } - + if (strncasecmp(option, "resetQueryCache", 15) == 0) { if (taosLogSqlFp) { pPrint("the query cache of internal client will reset"); diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index b27161cc01977cd40575430766420d104d65b627..c19f844c1eb34b17358c1cafb1561e9cdccccd03 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -323,6 +323,10 @@ char *tprefix(char *prefix) { } void tprintf(const char *const flags, int dflag, const char *const format, ...) { + if (tsTotalDiskGB != 0 && tsDiskAvailGB < (tsDiskMinimalGB/2)) { + printf("server disk space remain %.3f GB, stop write log\n", tsDiskAvailGB); + } + va_list argpointer; char buffer[MAX_LOGLINE_SIZE + 10] = {0}; int len; @@ -369,6 +373,11 @@ void tprintf(const char *const flags, int dflag, const char *const format, ...) } void taosDumpData(unsigned char *msg, int len) { + if (tsTotalDiskGB != 0 && tsDiskAvailGB < (tsDiskMinimalGB/2)) { + printf("server disk space remain %.3f GB, stop write log\n", tsDiskAvailGB); + return; + } + char temp[256]; int i, pos = 0, c = 0; @@ -392,6 +401,11 @@ void taosDumpData(unsigned char *msg, int len) { } void taosPrintLongString(const char *const flags, int dflag, const char *const format, ...) { + if (tsTotalDiskGB != 0 && tsDiskAvailGB < (tsDiskMinimalGB/2)) { + printf("server disk space remain %.3f GB, stop write log\n", tsDiskAvailGB); + return; + } + va_list argpointer; char buffer[65 * 1024 + 10]; int len; diff --git a/src/util/src/tsystem.c b/src/util/src/tsystem.c index 5b4754db992b8d1008f36c9bd1fd2c4bb64fc0da..1309d532d43451da52e9044e0198d7a6d8dbd84c 100644 --- a/src/util/src/tsystem.c +++ b/src/util/src/tsystem.c @@ -322,19 +322,19 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { return true; } -bool taosGetDisk(float *diskUsedGB) { +bool taosGetDisk() { struct statvfs info; const double unit = 1024 * 1024 * 1024; if (statvfs(tsDirectory, &info)) { - *diskUsedGB = 0; + tsDiskUsedGB = 0; tsTotalDiskGB = 0; return false; } - float diskAvail = (float)((double)info.f_bavail * (double)info.f_frsize / unit); + tsDiskAvailGB = (float)((double)info.f_bavail * (double)info.f_frsize / unit); tsTotalDiskGB = (int32_t)((double)info.f_blocks * (double)info.f_frsize / unit); - *diskUsedGB = (float)tsTotalDiskGB - diskAvail; + tsDiskUsedGB = (float)tsTotalDiskGB - tsDiskAvailGB; return true; } @@ -549,7 +549,7 @@ void taosGetSystemInfo() { float tmp1, tmp2; taosGetSysMemory(&tmp1); taosGetProcMemory(&tmp2); - taosGetDisk(&tmp1); + taosGetDisk(); taosGetBandSpeed(&tmp1); taosGetCpuUsage(&tmp1, &tmp2); taosGetProcIO(&tmp1, &tmp2);