From 7a76837c4629146092376d518fe1da0d6e917f87 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 13 Jul 2023 17:50:27 +0800 Subject: [PATCH 01/19] enh: expire time optimize --- source/dnode/mnode/impl/src/mndCluster.c | 2 +- source/dnode/mnode/impl/src/mndMain.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 4d05637a2b..848363144e 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -133,7 +133,7 @@ float mndGetClusterUpTime(SMnode *pMnode) { mndReleaseCluster(pMnode, pCluster, pIter); } - return upTime / 86400.0f; + return (float)upTime; } static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 381b1e64ed..f0c53c7473 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -804,7 +804,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr if (pObj->id == pMnode->selfDnodeId) { pClusterInfo->first_ep_dnode_id = pObj->id; tstrncpy(pClusterInfo->first_ep, pObj->pDnode->ep, sizeof(pClusterInfo->first_ep)); - pClusterInfo->master_uptime = mndGetClusterUpTime(pMnode); + pClusterInfo->master_uptime = mndGetClusterUpTime(pMnode) / 86400.0f; // pClusterInfo->master_uptime = (ms - pObj->stateStartTime) / (86400000.0f); tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); } else { From a04ba6581713e78664673e20e0a50cc6c1723418 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Jul 2023 15:30:14 +0800 Subject: [PATCH 02/19] chore: more code --- include/common/tglobal.h | 4 ++++ source/common/src/tglobal.c | 4 ++++ source/dnode/mgmt/exe/dmMain.c | 1 + source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 4 ++++ source/dnode/mnode/impl/src/mndMain.c | 4 +++- source/libs/catalog/src/ctgCache.c | 6 ------ source/libs/catalog/src/ctgUtil.c | 6 ++++++ 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index d6c552b3f6..a2ec4d2c03 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -87,6 +87,10 @@ extern int64_t tsMndLogRetention; extern int8_t tsGrant; extern bool tsMndSkipGrant; +// dnode +extern int64_t tsDndStart; +extern int64_t tsDndUpTime; + // monitor extern bool tsEnableMonitor; extern int32_t tsMonitorInterval; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 611a273353..3547ecca01 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -79,6 +79,10 @@ int64_t tsMndLogRetention = 2000; int8_t tsGrant = 1; bool tsMndSkipGrant = false; +// dnode +int64_t tsDndStart = 0; +int64_t tsDndUpTime = 0; + // monitor bool tsEnableMonitor = true; int32_t tsMonitorInterval = 30; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index e1b8a57684..242dd8a706 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -373,6 +373,7 @@ int mainWindows(int argc, char **argv) { dInfo("start to init service"); dmSetSignalHandle(); + tsDndStart = taosGetTimestampMs(); int32_t code = dmRun(); dInfo("shutting down the service"); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 89c394fdd0..3fe943267c 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -29,6 +29,7 @@ static void *dmStatusThreadFp(void *param) { if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; int64_t curTime = taosGetTimestampMs(); + int64_t cost = 0; float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsStatusInterval) { dmSendStatusReq(pMgmt); @@ -38,7 +39,10 @@ static void *dmStatusThreadFp(void *param) { if (trimCount == 0) { taosMemoryTrim(0); } + cost = taosGetTimestampMs() - curTime; } + tsDndUpTime += 200; + if (cost > 0) tsDndUpTime += cost; } return NULL; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index f0c53c7473..6a7bdd6df2 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -156,6 +156,7 @@ static void mndPullupTelem(SMnode *pMnode) { static void mndPullupGrant(SMnode *pMnode) { mTrace("pullup grant msg"); + printf("%s:%d @@@@@@@@@@@ mndPullupGrant @@@@@@@@@@@ %d \n", __func__, __LINE__, taosGetTimestampSec()); int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { @@ -248,8 +249,9 @@ static void *mndThreadFp(void *param) { setThreadName("mnode-timer"); while (1) { + printf("%s:%d =========== mndThreadFp =========== %d\n", __func__, __LINE__, taosGetTimestampSec()); lastTime++; - taosMsleep(100); + taosMsleep(300); if (mndGetStop(pMnode)) break; if (lastTime % 10 != 0) continue; diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 605f5efeb4..44de83b7ef 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -773,12 +773,6 @@ int32_t ctgGetCachedStbNameFromSuid(SCatalog* pCtg, char* dbFName, uint64_t suid int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache, SCtgAuthRsp *pRes) { int32_t code = 0; - if (IS_SYS_DBNAME(pReq->tbName.dbname)) { - *inCache = true; - pRes->pRawRes->pass = true; - ctgDebug("sysdb %s, pass", pReq->tbName.dbname); - return TSDB_CODE_SUCCESS; - } SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, pReq->user, strlen(pReq->user)); if (NULL == pUser) { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 86f6a51d9b..dab007aa47 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -1589,6 +1589,12 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) { return TSDB_CODE_SUCCESS; } + if (IS_SYS_DBNAME(pReq->tbName.dbname)) { + pRes->pass = true; + ctgDebug("sysdb %s, pass", pReq->tbName.dbname); + return TSDB_CODE_SUCCESS; + } + char dbFName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(&pReq->tbName, dbFName); From 7ff25d68953a7ac6b92e060a8dadf4fbbcdd9306 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 20 Jul 2023 10:56:08 +0800 Subject: [PATCH 03/19] chore: more code --- source/common/src/tglobal.c | 1 + source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 2 +- source/dnode/mnode/impl/inc/mndCluster.h | 2 +- source/dnode/mnode/impl/src/mndCluster.c | 4 ++-- source/dnode/mnode/impl/src/mndMain.c | 5 ++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 3547ecca01..ba05b2b2f4 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -81,6 +81,7 @@ bool tsMndSkipGrant = false; // dnode int64_t tsDndStart = 0; +int64_t tsDndStartOsUptime = 0; int64_t tsDndUpTime = 0; // monitor diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 3fe943267c..55fdd0f46a 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -42,7 +42,7 @@ static void *dmStatusThreadFp(void *param) { cost = taosGetTimestampMs() - curTime; } tsDndUpTime += 200; - if (cost > 0) tsDndUpTime += cost; + if (cost > 0) tsDndUpTime += cost; // TODO: use /proc/uptime to replace the upTime calculation for linux } return NULL; diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index 2cb41edd7c..e33ffdb372 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -27,7 +27,7 @@ void mndCleanupCluster(SMnode *pMnode); int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len); int64_t mndGetClusterId(SMnode *pMnode); int64_t mndGetClusterCreateTime(SMnode *pMnode); -float mndGetClusterUpTime(SMnode *pMnode); +int64_t mndGetClusterUpTime(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index c5cac21d00..d20350b094 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -123,7 +123,7 @@ static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) { #endif } -float mndGetClusterUpTime(SMnode *pMnode) { +int64_t mndGetClusterUpTime(SMnode *pMnode) { int64_t upTime = 0; void *pIter = NULL; SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter); @@ -132,7 +132,7 @@ float mndGetClusterUpTime(SMnode *pMnode) { mndReleaseCluster(pMnode, pCluster, pIter); } - return (float)upTime; + return upTime; } static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 6a7bdd6df2..5db9384f5a 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -249,9 +249,8 @@ static void *mndThreadFp(void *param) { setThreadName("mnode-timer"); while (1) { - printf("%s:%d =========== mndThreadFp =========== %d\n", __func__, __LINE__, taosGetTimestampSec()); lastTime++; - taosMsleep(300); + taosMsleep(100); if (mndGetStop(pMnode)) break; if (lastTime % 10 != 0) continue; @@ -806,7 +805,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr if (pObj->id == pMnode->selfDnodeId) { pClusterInfo->first_ep_dnode_id = pObj->id; tstrncpy(pClusterInfo->first_ep, pObj->pDnode->ep, sizeof(pClusterInfo->first_ep)); - pClusterInfo->master_uptime = mndGetClusterUpTime(pMnode) / 86400.0f; + pClusterInfo->master_uptime = (float)mndGetClusterUpTime(pMnode) / 86400.0f; // pClusterInfo->master_uptime = (ms - pObj->stateStartTime) / (86400000.0f); tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); } else { From ef2b66b280ef2ed29b6c75912d2d157af825dfae Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 21 Jul 2023 06:56:24 +0800 Subject: [PATCH 04/19] chore: more code --- include/common/tglobal.h | 1 + source/common/src/tglobal.c | 3 +++ source/dnode/mnode/impl/src/mndDnode.c | 11 ++++++++++- source/dnode/mnode/impl/src/mndMain.c | 1 - 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index a2ec4d2c03..b0a1aa6117 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -85,6 +85,7 @@ extern int64_t tsVndCommitMaxIntervalMs; extern int64_t tsMndSdbWriteDelta; extern int64_t tsMndLogRetention; extern int8_t tsGrant; +extern int32_t tsMndGrantMode; extern bool tsMndSkipGrant; // dnode diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index ba05b2b2f4..d3fbedbd7b 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -77,6 +77,7 @@ int64_t tsVndCommitMaxIntervalMs = 600 * 1000; int64_t tsMndSdbWriteDelta = 200; int64_t tsMndLogRetention = 2000; int8_t tsGrant = 1; +int32_t tsMndGrantMode = 0; bool tsMndSkipGrant = false; // dnode @@ -512,6 +513,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt64(pCfg, "mndSdbWriteDelta", tsMndSdbWriteDelta, 20, 10000, 0) != 0) return -1; if (cfgAddInt64(pCfg, "mndLogRetention", tsMndLogRetention, 500, 10000, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "grantMode", tsMndGrantMode, 0, 10000, 0) != 0) return -1; if (cfgAddBool(pCfg, "skipGrant", tsMndSkipGrant, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; @@ -921,6 +923,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64; tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64; tsMndSkipGrant = cfgGetItem(pCfg, "skipGrant")->bval; + tsMndGrantMode = cfgGetItem(pCfg, "grantMode")->i32; tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs)); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 100513b932..d8ee18e3ca 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -655,6 +655,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg STrans *pTrans = NULL; SDnodeObj *pDnode = NULL; bool cfgAll = pCfgReq->dnodeId == -1; + int32_t iter = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; @@ -662,7 +663,8 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg if (cfgAll) { pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); if (pIter == NULL) break; - } else if(!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) { + ++iter; + } else if (!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) { goto _OVER; } @@ -708,6 +710,13 @@ _OVER: } else { mndReleaseDnode(pMnode, pDnode); } + + if (iter > 15) { + tsGrantHBInterval = 10; + } else { + tsGrantHBInterval = 5; + } + mndTransDrop(pTrans); sdbFreeRaw(pRaw); return terrno; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 5db9384f5a..79abc57a39 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -156,7 +156,6 @@ static void mndPullupTelem(SMnode *pMnode) { static void mndPullupGrant(SMnode *pMnode) { mTrace("pullup grant msg"); - printf("%s:%d @@@@@@@@@@@ mndPullupGrant @@@@@@@@@@@ %d \n", __func__, __LINE__, taosGetTimestampSec()); int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { From d89f4da561e3f6b6d1296a83e5a2b1a7beecad27 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 21 Jul 2023 15:45:50 +0800 Subject: [PATCH 05/19] chore: more code --- source/dnode/mnode/impl/src/mndDnode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d8ee18e3ca..5623d17ce8 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1044,7 +1044,11 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { } mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); - if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0) { + if (strncmp(cfgReq.config, "activeCode_m", 12) == 0) { + cfgReq.config[10] = 0; + } else if (strncmp(cfgReq.config, "cActiveCode_m", 13) == 0) { + cfgReq.config[11] = 0; + } else if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0) { return -1; } From 586618807d054a437ddf60abf5e044c214c2b37b Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 21 Jul 2023 16:28:48 +0800 Subject: [PATCH 06/19] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 48cdff4cb5..ae15d4de04 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -711,11 +711,7 @@ _OVER: mndReleaseDnode(pMnode, pDnode); } - if (iter > 15) { - tsGrantHBInterval = 10; - } else { - tsGrantHBInterval = 5; - } + tsGrantHBInterval = MIN(MAX(3, iter / 2), 15); mndTransDrop(pTrans); sdbFreeRaw(pRaw); @@ -1048,11 +1044,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { } mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); - if (strncmp(cfgReq.config, "activeCode_m", 12) == 0) { - cfgReq.config[10] = 0; - } else if (strncmp(cfgReq.config, "cActiveCode_m", 13) == 0) { - cfgReq.config[11] = 0; - } else if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0) { + if ((pReq->info.ahandle != (void *)0x818611) && + (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0)) { return -1; } From a6f2e871571b8f1935593bba5ab8462c538ec46f Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 22 Jul 2023 22:18:50 +0800 Subject: [PATCH 07/19] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index ae15d4de04..5740746162 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -701,7 +701,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg } if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; - + tsGrantHBInterval = TMIN(TMAX(3, iter / 2), 30); terrno = 0; _OVER: @@ -710,9 +710,6 @@ _OVER: } else { mndReleaseDnode(pMnode, pDnode); } - - tsGrantHBInterval = MIN(MAX(3, iter / 2), 15); - mndTransDrop(pTrans); sdbFreeRaw(pRaw); return terrno; From b6bfdf2b9ebd55033041a5ddd33f1f6fcb35a88b Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 23 Jul 2022 12:11:49 +0800 Subject: [PATCH 08/19] chore: grant hb interval optimize --- source/dnode/mnode/impl/src/mndDnode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 5740746162..c35ccb17c8 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -701,7 +701,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg } if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; - tsGrantHBInterval = TMIN(TMAX(3, iter / 2), 30); + tsGrantHBInterval = TMIN(TMAX(5, iter / 2), 30); terrno = 0; _OVER: @@ -865,7 +865,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { code = mndCreateDnode(pMnode, pReq, &createReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; - + tsGrantHBInterval = 5; _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr()); From 3cfa49066ac061c7bbc978afada8c35f91133ee9 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Jul 2023 23:25:58 +0800 Subject: [PATCH 09/19] chore: uptime logic optimize --- include/common/tglobal.h | 1 + include/os/os.h | 1 + include/os/osSysinfo.h | 5 +++++ source/dnode/mgmt/exe/dmMain.c | 1 + source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 18 +++++++++++++++--- source/os/src/osSysinfo.c | 14 ++++++++++++++ 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index b0a1aa6117..4f2ed2b065 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -90,6 +90,7 @@ extern bool tsMndSkipGrant; // dnode extern int64_t tsDndStart; +extern int64_t tsDndStartOsUptime; extern int64_t tsDndUpTime; // monitor diff --git a/include/os/os.h b/include/os/os.h index 309a977ff6..31f546e032 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -41,6 +41,7 @@ extern "C" { #include #include #include +#include #include #include #include diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index b5309178ae..a8110ee06a 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -18,6 +18,10 @@ #include "os.h" +// #include /* for _syscallX macros/related stuff */ +// #include /* for struct sysinfo */ + + #ifdef __cplusplus extern "C" { #endif @@ -35,6 +39,7 @@ typedef struct { bool taosCheckSystemIsLittleEnd(); void taosGetSystemInfo(); +int64_t taosGetOsUptime(); int32_t taosGetEmail(char *email, int32_t maxLen); int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen); int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores); diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 242dd8a706..3c08714218 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -374,6 +374,7 @@ int mainWindows(int argc, char **argv) { dInfo("start to init service"); dmSetSignalHandle(); tsDndStart = taosGetTimestampMs(); + tsDndStartOsUptime = taosGetOsUptime(); int32_t code = dmRun(); dInfo("shutting down the service"); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 55fdd0f46a..5854450fc7 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -24,6 +24,10 @@ static void *dmStatusThreadFp(void *param) { const static int16_t TRIM_FREQ = 30; int32_t trimCount = 0; + int32_t upTimeCount = 0; + int64_t upTime = 0; + int64_t thrdTime = 0; + while (1) { taosMsleep(200); if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; @@ -39,10 +43,18 @@ static void *dmStatusThreadFp(void *param) { if (trimCount == 0) { taosMemoryTrim(0); } - cost = taosGetTimestampMs() - curTime; + + if ((upTimeCount = (++upTimeCount & 7)) == 0) { + upTime = (taosGetOsUptime() - tsDndStartOsUptime) * 1000; + } } - tsDndUpTime += 200; - if (cost > 0) tsDndUpTime += cost; // TODO: use /proc/uptime to replace the upTime calculation for linux + + thrdTime += 200; + cost = taosGetTimestampMs() - curTime; + if (cost > 0) thrdTime += cost; + tsDndUpTime = upTime > thrdTime ? upTime : thrdTime; + printf("upTime:%" PRIi64 " thrdTime:%" PRIi64 " tsDndUpTime:%" PRIi64 " delta:%" PRIi64 "\n", upTime, thrdTime, + tsDndUpTime, upTime - thrdTime); } return NULL; diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 6f87f6b75b..1f631c7388 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -961,6 +961,20 @@ char *taosGetCmdlineByPID(int pid) { #endif } +int64_t taosGetOsUptime() { +#ifdef WINDOWS + return 0; +// #else +// #elif defined(_TD_DARWIN_64) +// return 0; +#else + struct sysinfo info; + if (0 == sysinfo(&info)) { + return info.uptime; + }; +#endif +} + void taosSetCoreDump(bool enable) { if (!enable) return; #ifdef WINDOWS From d597ba8e71dca425146a6ccd18a0974dda209f97 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 06:35:54 +0800 Subject: [PATCH 10/19] chore: code optimize --- include/os/osSysinfo.h | 3 +-- source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 11 ++--------- source/os/src/osSysinfo.c | 6 ++---- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index a8110ee06a..206dbecd21 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -18,8 +18,7 @@ #include "os.h" -// #include /* for _syscallX macros/related stuff */ -// #include /* for struct sysinfo */ + #ifdef __cplusplus diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 5854450fc7..783babcb66 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -26,7 +26,6 @@ static void *dmStatusThreadFp(void *param) { int32_t trimCount = 0; int32_t upTimeCount = 0; int64_t upTime = 0; - int64_t thrdTime = 0; while (1) { taosMsleep(200); @@ -44,17 +43,11 @@ static void *dmStatusThreadFp(void *param) { taosMemoryTrim(0); } - if ((upTimeCount = (++upTimeCount & 7)) == 0) { + if ((upTimeCount = (++upTimeCount & 63)) == 0) { upTime = (taosGetOsUptime() - tsDndStartOsUptime) * 1000; + tsDndUpTime = TMAX(tsDndUpTime, upTime); } } - - thrdTime += 200; - cost = taosGetTimestampMs() - curTime; - if (cost > 0) thrdTime += cost; - tsDndUpTime = upTime > thrdTime ? upTime : thrdTime; - printf("upTime:%" PRIi64 " thrdTime:%" PRIi64 " tsDndUpTime:%" PRIi64 " delta:%" PRIi64 "\n", upTime, thrdTime, - tsDndUpTime, upTime - thrdTime); } return NULL; diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 1f631c7388..a29b96dd6f 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -963,16 +963,14 @@ char *taosGetCmdlineByPID(int pid) { int64_t taosGetOsUptime() { #ifdef WINDOWS - return 0; -// #else -// #elif defined(_TD_DARWIN_64) -// return 0; +#elif defined(_TD_DARWIN_64) #else struct sysinfo info; if (0 == sysinfo(&info)) { return info.uptime; }; #endif + return 0; } void taosSetCoreDump(bool enable) { From e566c051f7abb65b8eac3e886a586145718417eb Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 09:03:19 +0800 Subject: [PATCH 11/19] chore: code optimization --- include/os/osSysinfo.h | 3 --- source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 1 - 2 files changed, 4 deletions(-) diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 206dbecd21..a6a3655a55 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -18,9 +18,6 @@ #include "os.h" - - - #ifdef __cplusplus extern "C" { #endif diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 783babcb66..a7f58b1cd0 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -32,7 +32,6 @@ static void *dmStatusThreadFp(void *param) { if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; int64_t curTime = taosGetTimestampMs(); - int64_t cost = 0; float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsStatusInterval) { dmSendStatusReq(pMgmt); From 9511af242e458a373396ba6285fc26a0413cd592 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 09:12:42 +0800 Subject: [PATCH 12/19] chore: time unit of os uptime --- source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 2 +- source/os/src/osSysinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index a7f58b1cd0..7cc896cb84 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -43,7 +43,7 @@ static void *dmStatusThreadFp(void *param) { } if ((upTimeCount = (++upTimeCount & 63)) == 0) { - upTime = (taosGetOsUptime() - tsDndStartOsUptime) * 1000; + upTime = taosGetOsUptime() - tsDndStartOsUptime; tsDndUpTime = TMAX(tsDndUpTime, upTime); } } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index a29b96dd6f..a5b8af3e6e 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -967,7 +967,7 @@ int64_t taosGetOsUptime() { #else struct sysinfo info; if (0 == sysinfo(&info)) { - return info.uptime; + return (int64_t)info.uptime * 1000; }; #endif return 0; From 3b11661c4057db4c05abfa9f1ae78423796be8c0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 09:14:49 +0800 Subject: [PATCH 13/19] chore: code optimization --- include/os/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/os/os.h b/include/os/os.h index 31f546e032..389e25f7c1 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -41,9 +41,9 @@ extern "C" { #include #include #include -#include #include #include +#include #include #include #include From 1d23b0215c2f32505cbc847856b65030b0ecfbdc Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 10:07:15 +0800 Subject: [PATCH 14/19] fix: exclude sys/sysinfo.h for mac --- include/os/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/os/os.h b/include/os/os.h index 389e25f7c1..ac1a750b78 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -43,7 +43,6 @@ extern "C" { #include #include #include -#include #include #include #include @@ -54,6 +53,7 @@ extern "C" { #else #include #include +#include #if defined(_TD_X86_) #include #endif From dffdbb53f69aadafaf52b633775ac6c152107a68 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 10:15:32 +0800 Subject: [PATCH 15/19] chore: code optimization --- source/os/src/osSysinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index a5b8af3e6e..5f73251e3b 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -968,7 +968,7 @@ int64_t taosGetOsUptime() { struct sysinfo info; if (0 == sysinfo(&info)) { return (int64_t)info.uptime * 1000; - }; + } #endif return 0; } From ec4b4923e8a8d679b5d67470d9dfbfcec97e0dac Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 10:33:38 +0800 Subject: [PATCH 16/19] fix: multiple unsequenced modifications --- source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 7cc896cb84..98bb4e3f9c 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -42,7 +42,7 @@ static void *dmStatusThreadFp(void *param) { taosMemoryTrim(0); } - if ((upTimeCount = (++upTimeCount & 63)) == 0) { + if ((upTimeCount = ((upTimeCount + 1) & 63)) == 0) { upTime = taosGetOsUptime() - tsDndStartOsUptime; tsDndUpTime = TMAX(tsDndUpTime, upTime); } From 8225c3fd9be962e001f3085d2f024d008d816f07 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 1 Oct 2022 00:03:43 +0800 Subject: [PATCH 17/19] chore: code optimization --- source/dnode/mgmt/mgmt_dnode/src/dmWorker.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 98bb4e3f9c..76cb65b53a 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -32,7 +32,8 @@ static void *dmStatusThreadFp(void *param) { if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; int64_t curTime = taosGetTimestampMs(); - float interval = (curTime - lastTime) / 1000.0f; + if (curTime < lastTime) lastTime = curTime; + float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsStatusInterval) { dmSendStatusReq(pMgmt); lastTime = curTime; @@ -62,7 +63,8 @@ static void *dmMonitorThreadFp(void *param) { if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; int64_t curTime = taosGetTimestampMs(); - float interval = (curTime - lastTime) / 1000.0f; + if (curTime < lastTime) lastTime = curTime; + float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsMonitorInterval) { (*pMgmt->sendMonitorReportFp)(); lastTime = curTime; From cf59a6cff0fd86d1f90a50d0a324b6b0d4de20da Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 14:24:47 +0800 Subject: [PATCH 18/19] chore: set user for dm transport --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 1 + source/dnode/mnode/impl/src/mndDnode.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 5d6d16ccf8..37c548c6ba 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -290,6 +290,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.cfp = (RpcCfp)dmProcessRpcMsg; rpcInit.sessions = 1024; rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.user = "root"; rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.rfp = rpcRfp; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index c35ccb17c8..cfd026634c 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1041,8 +1041,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { } mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); - if ((pReq->info.ahandle != (void *)0x818611) && - (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0)) { + if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0) { return -1; } From 7946ce499448168520c1a42acc6102a8f9a06436 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Jul 2023 14:46:59 +0800 Subject: [PATCH 19/19] chore: code optimization --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 37c548c6ba..df54f8abba 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -290,7 +290,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.cfp = (RpcCfp)dmProcessRpcMsg; rpcInit.sessions = 1024; rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.user = "root"; + rpcInit.user = TSDB_DEFAULT_USER; rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.rfp = rpcRfp;