From d67339bfc847807667707ad71365a34c35f50e43 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 3 Aug 2022 20:17:53 +0800 Subject: [PATCH] os: fix minimalDirGB invalid error --- include/os/osEnv.h | 2 ++ source/common/src/ttszip.c | 6 ++++++ source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 6 +++++- source/dnode/mgmt/node_mgmt/src/dmEnv.c | 18 ++++++++++++++++++ source/os/src/osEnv.c | 4 ++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/os/osEnv.h b/include/os/osEnv.h index a3f92a0b29..798bfc197e 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -49,6 +49,8 @@ void osDefaultInit(); void osUpdate(); void osCleanup(); bool osLogSpaceAvailable(); +bool osDataSpaceAvailable(); +bool osTempSpaceAvailable(); void osSetTimezone(const char *timezone); void osSetSystemLocale(const char *inLocale, const char *inCharSet); diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index 03353b0de6..e2adb94909 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -30,6 +30,12 @@ static int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader); * @return */ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { + if (!osTempSpaceAvailable()) { + terrno = TSDB_CODE_TSC_NO_DISKSPACE; + tscError("tmp file created failed since %s", terrstr()); + return NULL; + } + STSBuf* pTSBuf = taosMemoryCalloc(1, sizeof(STSBuf)); if (pTSBuf == NULL) { return NULL; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index e4d6de849c..1a226abe5c 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -176,7 +176,11 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp taosWriteQitem(pVnode->pFetchQ, pMsg); break; case WRITE_QUEUE: - if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) { + if (!osDataSpaceAvailable()) { + terrno = TSDB_CODE_VND_NO_DISKSPACE; + code = terrno; + dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr()); + } else if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) { terrno = TSDB_CODE_VND_NO_WRITE_AUTH; code = terrno; dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr()); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index 119d521827..f430ff7983 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -49,8 +49,26 @@ static int32_t dmInitMonitor() { return 0; } +static bool dmCheckDiskSpace() { + osUpdate(); + if (osDataSpaceAvailable()) { + dError("free disk size: %f GB, too little, quit", tsDataSpace.size.avail); + return false; + } + if (osLogSpaceAvailable()) { + dError("free disk size: %f GB, too little, quit", tsLogSpace.size.avail); + return false; + } + if (osTempSpaceAvailable()) { + dError("free disk size: %f GB, too little, quit", tsTempSpace.size.avail); + return false; + } + return true; +} + int32_t dmInit(int8_t rtype) { dInfo("start to init dnode env"); + if (!dmCheckDiskSpace()) return -1; if (dmCheckRepeatInit(dmInstance()) != 0) return -1; if (dmInitSystem() != 0) return -1; if (dmInitMonitor() != 0) return -1; diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 6ae3d8a0c0..8f6800c7be 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -105,6 +105,10 @@ void osCleanup() {} bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; } +bool osDataSpaceAvailable() { return tsDataSpace.reserved <= tsDataSpace.size.avail; } + +bool osTempSpaceAvailable() { return tsTempSpace.reserved <= tsTempSpace.size.avail; } + void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); } void osSetSystemLocale(const char *inLocale, const char *inCharSet) { -- GitLab