From f68d7fa46d40a01e5f5d873ae3d3ad2fdcef99dc Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 19 Dec 2023 20:19:12 +0800 Subject: [PATCH] feat: support uniq grant --- source/dnode/mnode/impl/src/mndCluster.c | 37 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 9e18063ee3..ab49e308f4 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -423,6 +423,17 @@ static int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) { goto _exit; } + SClusterObj clusterObj = {0}; + void *pIter = NULL; + SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter); + if (!pCluster || pCluster->id <= 0) { + code = TSDB_CODE_APP_IS_STARTING; + if (pCluster) mndReleaseCluster(pMnode, pCluster, pIter); + goto _exit; + } + memcpy(&clusterObj, pCluster, sizeof(SClusterObj)); + mndReleaseCluster(pMnode, pCluster, pIter); + if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, 11) == 0) { #ifdef TD_ENTERPRISE if (strlen(cfgReq.config) >= TSDB_DNODE_CONFIG_LEN) { @@ -433,14 +444,36 @@ static int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) { code = TSDB_CODE_INVALID_CFG_VALUE; goto _exit; } - // code = xxx; - code = grantAlterActiveCode(cfgReq.value); + if ((code = grantAlterActiveCode(cfgReq.value)) != 0) { + goto _exit; + } #else code = TSDB_CODE_OPS_NOT_SUPPORT; goto _exit; #endif } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-cluster"); + if (pTrans == NULL) return -1; + + SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj); + if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { + mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + code = terrno; + goto _exit; + } + (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + code = terrno; + goto _exit; + } + + mndTransDrop(pTrans); + { // audit auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, cfgReq.sqlLen); }