fix: support check and merge activeCode
This commit is contained in:
parent
c3d80fd483
commit
e677e41573
|
@ -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
|
||||
|
|
|
@ -541,6 +541,11 @@ 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_INVALID_ACTIVE TAOS_DEF_ERROR_CODE(0, 0x080E)
|
||||
#define TSDB_CODE_GRANT_GEN_INVALID_KEY TAOS_DEF_ERROR_CODE(0, 0x080F)
|
||||
#define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0810)
|
||||
#define TSDB_CODE_GRANT_GEN_INVALID_KLEN TAOS_DEF_ERROR_CODE(0, 0x0811)
|
||||
|
||||
|
||||
// sync
|
||||
// #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x
|
||||
|
|
|
@ -763,9 +763,14 @@ 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 iter = 0;
|
||||
|
||||
if (cfgAll && !(failRecord = taosArrayInit(1, sizeof(int32_t)))) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -774,6 +779,39 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
|
|||
if (pIter == NULL) break;
|
||||
++iter;
|
||||
} else if (!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DNODE_ID;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SDnodeObj tmpDnode = *pDnode;
|
||||
if (action == DND_ACTIVE_CODE) {
|
||||
#ifndef MND_MERGE_ACTIVE_CODE
|
||||
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, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id,
|
||||
pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr());
|
||||
taosArrayPush(failRecord, pDnode->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else if (action == DND_CONN_ACTIVE_CODE) {
|
||||
#ifndef MND_MERGE_ACTIVE_CODE
|
||||
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, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id,
|
||||
pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr());
|
||||
taosArrayPush(failRecord, pDnode->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -783,16 +821,6 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
|
|||
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);
|
||||
|
@ -816,12 +844,18 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
|
|||
_OVER:
|
||||
if (cfgAll) {
|
||||
sdbRelease(pSdb, pDnode);
|
||||
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 +1296,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;
|
||||
|
|
|
@ -430,6 +430,10 @@ 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_INVALID_ACTIVE, "Invalid active code")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KEY, "Invalid key to gen active code")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_APP_LIMIT, "Gen active code limited by app num")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KLEN, "Invalid klen to gen active code")
|
||||
|
||||
// sync
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")
|
||||
|
|
Loading…
Reference in New Issue