From 53ed71959b49fc493db90a0bc55fb9f04e2b2d7b Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 13 Sep 2023 11:30:04 +0800 Subject: [PATCH] enh: fetch cluster info for grant periodically --- include/common/tglobal.h | 1 + include/common/tmsgdef.h | 1 + source/common/src/tglobal.c | 1 + source/dnode/mnode/impl/src/mndGrant.c | 2 ++ source/dnode/mnode/impl/src/mndMain.c | 15 +++++++++++++++ 5 files changed, 20 insertions(+) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 1c5510ba0d..1b37c8c855 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -198,6 +198,7 @@ extern int32_t tsTtlPushIntervalSec; extern int32_t tsTtlBatchDropNum; extern int32_t tsTrimVDbIntervalSec; extern int32_t tsGrantHBInterval; +extern int32_t tsGrantFetchInterval; extern int32_t tsUptimeInterval; extern int32_t tsRpcRetryLimit; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index fb2c780724..13811fae83 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -177,6 +177,7 @@ enum { // WARN: new msg should be appended to segment tail TD_DEF_MSG_TYPE(TDMT_MND_UPTIME_TIMER, "uptime-timer", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, "lost-consumer-clear", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_STREAM_HEARTBEAT, "stream-heartbeat", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_GRANT_FETCH_TIMER, "grant-fetch-tmr", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_BALANCE_VGROUP_LEADER, "balance-vgroup-leader", NULL, NULL) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 90812a66b2..a9c712c3d0 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -247,6 +247,7 @@ int32_t tsTtlUnit = 86400; int32_t tsTtlPushIntervalSec = 10; int32_t tsTrimVDbIntervalSec = 60 * 60; // interval of trimming db in all vgroups int32_t tsGrantHBInterval = 60; +int32_t tsGrantFetchInterval = 2; int32_t tsUptimeInterval = 300; // seconds char tsUdfdResFuncs[512] = ""; // udfd resident funcs that teardown when udfd exits char tsUdfdLdLibPath[512] = ""; diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c index 1b46e16961..fbe987975a 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -117,10 +117,12 @@ static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } static int32_t mndProcessGrantHB(SRpcMsg *pReq) { return TSDB_CODE_SUCCESS; } +static int32_t mndProcessGrantFetch(SRpcMsg *pReq) { return TSDB_CODE_SUCCESS; } int32_t mndInitGrant(SMnode *pMnode) { mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_GRANTS, mndRetrieveGrant); mndSetMsgHandle(pMnode, TDMT_MND_GRANT_HB_TIMER, mndProcessGrantHB); + mndSetMsgHandle(pMnode, TDMT_MND_GRANT_FETCH_TIMER, mndProcessGrantFetch); return 0; } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 1c87cde78a..fb97d688d6 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -175,6 +175,17 @@ static void mndPullupGrant(SMnode *pMnode) { } } +static void mndFetchGrant(SMnode *pMnode) { + mTrace("fetch grant msg"); + int32_t contLen = 0; + void *pReq = mndBuildTimerMsg(&contLen); + if (pReq != NULL) { + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_GRANT_FETCH_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9529}; + tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); + } +} + static void mndIncreaseUpTime(SMnode *pMnode) { mTrace("increate uptime"); int32_t contLen = 0; @@ -293,6 +304,10 @@ static void *mndThreadFp(void *param) { mndPullupTelem(pMnode); } + if (sec % tsGrantFetchInterval == 0) { + mndFetchGrant(pMnode); + } + if (sec % tsGrantHBInterval == 0) { mndPullupGrant(pMnode); }