diff --git a/include/common/tgrant.h b/include/common/tgrant.h index 31d34add24..4d33889336 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -51,6 +51,9 @@ typedef enum { } EGrantType; int32_t grantCheck(EGrantType grant); +#ifdef TD_ENTERPRISE +int32_t grantAlterActiveCode(const char* old, const char* new, char* out, int8_t type); +#endif #ifndef GRANTS_CFG #ifdef TD_ENTERPRISE diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 39bf2b5681..227e8520e3 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -541,6 +541,13 @@ int32_t* taosGetErrno(); #define TSDB_CODE_GRANT_CPU_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080B) #define TSDB_CODE_GRANT_STABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080C) #define TSDB_CODE_GRANT_TABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080D) +#define TSDB_CODE_GRANT_PAR_IVLD_ACTIVE TAOS_DEF_ERROR_CODE(0, 0x080E) +#define TSDB_CODE_GRANT_PAR_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x080F) +#define TSDB_CODE_GRANT_PAR_DEC_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x0810) +#define TSDB_CODE_GRANT_PAR_DEC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0811) +#define TSDB_CODE_GRANT_GEN_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x0812) +#define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0813) +#define TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0814) // sync // #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index f2a8c82192..ea7ded1879 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -763,7 +763,9 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg SSdbRaw *pRaw = NULL; STrans *pTrans = NULL; SDnodeObj *pDnode = NULL; + SArray *failRecord = NULL; bool cfgAll = pCfgReq->dnodeId == -1; + int32_t cfgAllErr = 0; int32_t iter = 0; SSdb *pSdb = pMnode->pSdb; @@ -777,28 +779,64 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg goto _OVER; } + SDnodeObj tmpDnode = *pDnode; + if (action == DND_ACTIVE_CODE) { +#ifndef TD_CHECK_ACTIVE + strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); +#else + if (grantAlterActiveCode(pDnode->active, pCfgReq->value, tmpDnode.active, 0) != 0) { + if (TSDB_CODE_DUP_KEY != terrno) { + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, + pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + if (cfgAll) { // alter all dnodes: + if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t)); + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (0 == cfgAllErr) cfgAllErr = terrno; // output 1st terrno. + } + } else { + terrno = 0; // no action for dup active code + } + if (cfgAll) continue; + goto _OVER; + } +#endif + } else if (action == DND_CONN_ACTIVE_CODE) { +#ifndef TD_CHECK_ACTIVE + strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); +#else + if (grantAlterActiveCode(pDnode->connActive, pCfgReq->value, tmpDnode.connActive, 1) != 0) { + if (TSDB_CODE_DUP_KEY != terrno) { + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, + pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + if (cfgAll) { + if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t)); + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (0 == cfgAllErr) cfgAllErr = terrno; + } + } else { + terrno = 0; + } + if (cfgAll) continue; + goto _OVER; + } +#endif + } else { + terrno = TSDB_CODE_INVALID_CFG; + goto _OVER; + } + if (!pTrans) { pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "config-dnode"); if (!pTrans) goto _OVER; if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER; } - SDnodeObj tmpDnode = *pDnode; - if (action == DND_ACTIVE_CODE) { - strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); - } else if (action == DND_CONN_ACTIVE_CODE) { - strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); - } else { - terrno = TSDB_CODE_INVALID_CFG; - goto _OVER; - } - pRaw = mndDnodeActionEncode(&tmpDnode); if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); pRaw = NULL; - mInfo("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, + mInfo("dnode:%d, config dnode:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value); if (cfgAll) { @@ -816,12 +854,19 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg _OVER: if (cfgAll) { sdbRelease(pSdb, pDnode); + if (cfgAllErr != 0) terrno = cfgAllErr; + int32_t nFail = taosArrayGetSize(failRecord); + if (nFail > 0) { + mError("config dnode, cfg:%d, app:%p config:%s value:%s. total:%d, fail:%d", pCfgReq->dnodeId, pReq->info.ahandle, + pCfgReq->config, pCfgReq->value, iter, nFail); + } } else { mndReleaseDnode(pMnode, pDnode); } sdbCancelFetch(pSdb, pIter); mndTransDrop(pTrans); sdbFreeRaw(pRaw); + taosArrayDestroy(failRecord); return terrno; } @@ -1262,7 +1307,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); if (mndConfigDnode(pMnode, pReq, &cfgReq, opt) != 0) { - mError("dnode:%d, failed to config activeCode since %s", cfgReq.dnodeId, terrstr()); + mError("dnode:%d, failed to config activeCode since %s. conf:%s, val:%s", cfgReq.dnodeId, terrstr(), + cfgReq.config, cfgReq.value); return -1; } return 0; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9832720994..b4a1a2eae2 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -430,6 +430,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, "Query time limited by TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, "CPU cores limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STABLE_LIMITED, "STable creation limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TABLE_LIMITED, "Table creation limited by license") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_ACTIVE, "Invalid active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_KEY, "Invalid key to parse active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_DEC_IVLD_KEY, "Invalid key to decode active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_DEC_IVLD_KLEN, "Invalid klen to decode active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_IVLD_KEY, "Invalid key to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_APP_LIMIT, "Limited app num to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN, "Invalid klen to encode active code") // sync TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout") diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 77bfb5dca8..7f4b291776 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -242,11 +242,11 @@ class TDTestCase: self.str510 = self.str255 + self.str255 tdSql.error('alter dnode 1 "activeCode" "a"') tdSql.error('alter dnode 1 "activeCode" "' + self.str107 + '"') - tdSql.execute('alter all dnodes "activeCode" "' + self.str108 + '"') + # tdSql.error('alter all dnodes "activeCode" "' + self.str108 + '"') tdSql.error('alter dnode 1 "activeCode" "' + self.str109 + '"') tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"') tdSql.query(f'select * from information_schema.ins_dnodes') - tdSql.checkEqual(tdSql.queryResult[0][8],self.str108) + tdSql.checkEqual(tdSql.queryResult[0][8],"") tdSql.execute('alter dnode 1 "activeCode" ""') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") @@ -257,14 +257,14 @@ class TDTestCase: tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str256 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"') - tdSql.execute('alter all dnodes "cActiveCode" "' + self.str254 + '"') + # tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") - tdSql.checkEqual(tdSql.queryResult[0][1],self.str254) - tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str109 + '"') + tdSql.checkEqual(tdSql.queryResult[0][1],"") + # tdSql.error('alter dnode 1 "cActiveCode" "' + self.str109 + '"') tdSql.query(f'show dnodes') - tdSql.checkEqual(tdSql.queryResult[0][9],self.str109) + tdSql.checkEqual(tdSql.queryResult[0][9],"") tdSql.execute('alter all dnodes "cActiveCode" ""') tdSql.query(f'select c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],'')