diff --git a/include/common/tgrant.h b/include/common/tgrant.h index 4ed7d7bd78..f9bf27ab13 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -62,7 +62,6 @@ typedef struct { } SGrantedInfo; int32_t grantCheck(EGrantType grant); -int32_t grantAlterActiveCode(const char* active, char** newActive); char* grantGetMachineId(); #ifndef GRANTS_CFG diff --git a/include/util/tdef.h b/include/util/tdef.h index 8bddc15e9c..1543b3716a 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -286,7 +286,7 @@ typedef enum ELogicConditionType { #define TSDB_DNODE_CONFIG_LEN 128 #define TSDB_DNODE_VALUE_LEN 256 -#define TSDB_CLUSTER_VALUE_LEN 1024 +#define TSDB_CLUSTER_VALUE_LEN 1000 #define TSDB_ACTIVE_KEY_LEN 109 #define TSDB_CONN_ACTIVE_KEY_LEN 255 diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 4a9b2d602d..45c21e06ac 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -827,11 +827,13 @@ typedef struct { typedef struct { int32_t id; + int8_t nStates; + int8_t nActives; int64_t createTime; int64_t updateTime; - SGrantState state[GRANT_STATE_NUM]; - SGrantActive active[GRANT_ACTIVE_NUM]; - char* pActive; + SGrantState stats[GRANT_STATE_NUM]; + SGrantActive actives[GRANT_ACTIVE_NUM]; + char* active; SArray* pMachines; // SGrantMachines SRWLatch lock; } SGrantObj; diff --git a/source/dnode/mnode/impl/inc/mndGrant.h b/source/dnode/mnode/impl/inc/mndGrant.h index aea680ad5f..ae9612d473 100644 --- a/source/dnode/mnode/impl/inc/mndGrant.h +++ b/source/dnode/mnode/impl/inc/mndGrant.h @@ -30,24 +30,17 @@ void grantRestore(EGrantType grant, uint64_t value); #ifdef TD_ENTERPRISE - - SGrantObj *mndAcquireGrant(SMnode * pMnode, int32_t id); - void mndReleaseGrant(SMnode * pMnode, SGrantObj * pGrant); - SSdbRaw *mndGrantActionEncode(SGrantObj * pGrant); SSdbRow *mndGrantActionDecode(SSdbRaw * pRaw); int32_t mndGrantActionInsert(SSdb * pSdb, SGrantObj * pGrant); int32_t mndGrantActionDelete(SSdb * pSdb, SGrantObj * pGrant); int32_t mndGrantActionUpdate(SSdb * pSdb, SGrantObj * pOldGrant, SGrantObj * pNewGrant); - int32_t mndProcessUpdMachineReqImpl(void *pMachine, SRpcMsg *pReq); - int32_t mndProcessUpdStateReqImpl(void *pState, SRpcMsg *pReq); - int32_t mndProcessUpdActiveReqImpl(void *pActive, SRpcMsg *pReq); - int32_t mndRetrieveGrantImpl(SRpcMsg * pReq, SShowObj * pShow, SSDataBlock * pBlock, int32_t rows); - - int32_t mndProcessConfigClusterReq(SRpcMsg * pReq); - int32_t mndProcessConfigClusterRsp(SRpcMsg * pReq); + int32_t grantAlterActiveCode(const char *active, char **newActive); + int32_t mndProcessConfigGrantReq(SRpcMsg * pReq, SMCfgClusterReq * pCfg); + int32_t mndProcessUpdMachineReq(SRpcMsg * pReq, SArray *pMachines); + int32_t mndProcessUpdStateReq(SRpcMsg * pReq, SGrantState *pState); #endif #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index a583b0e7bb..f63442802b 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "audit.h" #include "mndCluster.h" +#include "mndGrant.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndTrans.h" @@ -33,6 +34,8 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode); static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter); static int32_t mndProcessUptimeTimer(SRpcMsg *pReq); +static int32_t mndProcessConfigClusterReq(SRpcMsg *pReq); +static int32_t mndProcessConfigClusterRsp(SRpcMsg *pReq); int32_t mndInitCluster(SMnode *pMnode) { SSdbTable table = { @@ -47,6 +50,8 @@ int32_t mndInitCluster(SMnode *pMnode) { }; mndSetMsgHandle(pMnode, TDMT_MND_UPTIME_TIMER, mndProcessUptimeTimer); + mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq); + mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster); @@ -402,4 +407,63 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) { mndTransDrop(pTrans); return 0; +} + +int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) { + int32_t code = 0; + SMnode *pMnode = pReq->info.node; + SMCfgClusterReq cfgReq = {0}; + if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value); + if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER) != 0) { + code = terrno != 0 ? terrno : TSDB_CODE_MND_NO_RIGHTS; + 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, TSDB_DNODE_CONFIG_LEN) == 0) { +#ifdef TD_ENTERPRISE + if (0 != (code = mndProcessConfigGrantReq(pReq, &cfgReq))) { + goto _exit; + } +#else + code = TSDB_CODE_OPS_NOT_SUPPORT; + goto _exit; +#endif + } else { + code = TSDB_CODE_OPS_NOT_SUPPORT; + goto _exit; + } + + { // audit + auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, cfgReq.sqlLen); + } +_exit: + tFreeSMCfgClusterReq(&cfgReq); + if (code != 0) { + terrno = code; + mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, terrstr()); + } else { + mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value); + } + return code; +} + +int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) { + mInfo("config rsp from cluster"); + return 0; } \ No newline at end of file