Merge pull request #23730 from taosdata/enh/TD-26976-3.0
enh: grant and active codes
This commit is contained in:
commit
415d162358
|
@ -31,6 +31,8 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GRANT_HEART_BEAT_MIN 2
|
#define GRANT_HEART_BEAT_MIN 2
|
||||||
|
#define GRANT_ACTIVE_CODE "activeCode"
|
||||||
|
#define GRANT_C_ACTIVE_CODE "cActiveCode"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_GRANT_ALL,
|
TSDB_GRANT_ALL,
|
||||||
|
@ -50,6 +52,11 @@ typedef enum {
|
||||||
TSDB_GRANT_TABLE,
|
TSDB_GRANT_TABLE,
|
||||||
} EGrantType;
|
} EGrantType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t grantedTime;
|
||||||
|
int64_t connGrantedTime;
|
||||||
|
} SGrantedInfo;
|
||||||
|
|
||||||
int32_t grantCheck(EGrantType grant);
|
int32_t grantCheck(EGrantType grant);
|
||||||
int32_t grantAlterActiveCode(int32_t did, const char* old, const char* newer, char* out, int8_t type);
|
int32_t grantAlterActiveCode(int32_t did, const char* old, const char* newer, char* out, int8_t type);
|
||||||
|
|
||||||
|
|
|
@ -557,6 +557,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_GRANT_GEN_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x0812)
|
#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_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0813)
|
||||||
#define TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0814)
|
#define TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0814)
|
||||||
|
#define TSDB_CODE_GRANT_PAR_IVLD_DIST TAOS_DEF_ERROR_CODE(0, 0x0815)
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
// #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x
|
// #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x
|
||||||
|
|
|
@ -27,6 +27,8 @@ void mndCleanupCluster(SMnode *pMnode);
|
||||||
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len);
|
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len);
|
||||||
int64_t mndGetClusterId(SMnode *pMnode);
|
int64_t mndGetClusterId(SMnode *pMnode);
|
||||||
int64_t mndGetClusterCreateTime(SMnode *pMnode);
|
int64_t mndGetClusterCreateTime(SMnode *pMnode);
|
||||||
|
int32_t mndGetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo);
|
||||||
|
int32_t mndSetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo);
|
||||||
int64_t mndGetClusterUpTime(SMnode *pMnode);
|
int64_t mndGetClusterUpTime(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -192,6 +192,8 @@ typedef struct {
|
||||||
int64_t createdTime;
|
int64_t createdTime;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
int32_t upTime;
|
int32_t upTime;
|
||||||
|
int64_t grantedTime;
|
||||||
|
int64_t connGrantedTime;
|
||||||
} SClusterObj;
|
} SClusterObj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
#define CLUSTER_VER_NUMBE 1
|
#define CLUSTER_VER_NUMBE 1
|
||||||
#define CLUSTER_RESERVE_SIZE 60
|
#define CLUSTER_RESERVE_SIZE 44
|
||||||
int64_t tsExpireTime = 0;
|
int64_t tsExpireTime = 0;
|
||||||
|
|
||||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
||||||
|
@ -112,6 +112,19 @@ int64_t mndGetClusterCreateTime(SMnode *pMnode) {
|
||||||
return createTime;
|
return createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndGetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo) {
|
||||||
|
void *pIter = NULL;
|
||||||
|
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||||
|
if (pCluster != NULL) {
|
||||||
|
pInfo->grantedTime = pCluster->grantedTime;
|
||||||
|
pInfo->connGrantedTime = pCluster->connGrantedTime;
|
||||||
|
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
|
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
|
||||||
#if 0
|
#if 0
|
||||||
int32_t upTime = taosGetTimestampSec() - pCluster->updateTime / 1000;
|
int32_t upTime = taosGetTimestampSec() - pCluster->updateTime / 1000;
|
||||||
|
@ -146,6 +159,8 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
||||||
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, _OVER)
|
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, _OVER)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pCluster->upTime, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pCluster->upTime, _OVER)
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pCluster->grantedTime, _OVER)
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pCluster->connGrantedTime, _OVER)
|
||||||
SDB_SET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
SDB_SET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -186,6 +201,8 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
||||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, _OVER)
|
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, _OVER)
|
||||||
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pCluster->upTime, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pCluster->upTime, _OVER)
|
||||||
|
SDB_GET_INT64(pRaw, dataPos, &pCluster->grantedTime, _OVER);
|
||||||
|
SDB_GET_INT64(pRaw, dataPos, &pCluster->connGrantedTime, _OVER);
|
||||||
SDB_GET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
SDB_GET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -218,6 +235,8 @@ static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj
|
||||||
mTrace("cluster:%" PRId64 ", perform update action, old row:%p new row:%p, uptime from %d to %d", pOld->id, pOld,
|
mTrace("cluster:%" PRId64 ", perform update action, old row:%p new row:%p, uptime from %d to %d", pOld->id, pOld,
|
||||||
pNew, pOld->upTime, pNew->upTime);
|
pNew, pOld->upTime, pNew->upTime);
|
||||||
pOld->upTime = pNew->upTime;
|
pOld->upTime = pNew->upTime;
|
||||||
|
pOld->grantedTime = pNew->grantedTime;
|
||||||
|
pOld->connGrantedTime = pNew->connGrantedTime;
|
||||||
pOld->updateTime = taosGetTimestampMs();
|
pOld->updateTime = taosGetTimestampMs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -359,3 +378,44 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndSetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo) {
|
||||||
|
SClusterObj clusterObj = {0};
|
||||||
|
void *pIter = NULL;
|
||||||
|
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||||
|
if (pCluster != NULL) {
|
||||||
|
if (pCluster->grantedTime >= pInfo->grantedTime && pCluster->connGrantedTime >= pInfo->connGrantedTime) {
|
||||||
|
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
|
||||||
|
if (pCluster->grantedTime < pInfo->grantedTime) clusterObj.grantedTime = pInfo->grantedTime;
|
||||||
|
if (pCluster->connGrantedTime < pInfo->connGrantedTime) clusterObj.connGrantedTime = pInfo->connGrantedTime;
|
||||||
|
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clusterObj.id <= 0) {
|
||||||
|
mError("can't get cluster info while update granted info");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "granted-info");
|
||||||
|
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);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -790,7 +790,9 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
|
||||||
if (cfgAll) { // alter all dnodes:
|
if (cfgAll) { // alter all dnodes:
|
||||||
if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t));
|
if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t));
|
||||||
if (failRecord) taosArrayPush(failRecord, &pDnode->id);
|
if (failRecord) taosArrayPush(failRecord, &pDnode->id);
|
||||||
if (0 == cfgAllErr) cfgAllErr = terrno; // output 1st terrno.
|
if (0 == cfgAllErr || cfgAllErr == TSDB_CODE_GRANT_PAR_IVLD_ACTIVE) {
|
||||||
|
cfgAllErr = terrno; // output 1st or more specific error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
terrno = 0; // no action for dup active code
|
terrno = 0; // no action for dup active code
|
||||||
|
@ -806,7 +808,9 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
|
||||||
if (cfgAll) {
|
if (cfgAll) {
|
||||||
if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t));
|
if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t));
|
||||||
if (failRecord) taosArrayPush(failRecord, &pDnode->id);
|
if (failRecord) taosArrayPush(failRecord, &pDnode->id);
|
||||||
if (0 == cfgAllErr) cfgAllErr = terrno;
|
if (0 == cfgAllErr || cfgAllErr == TSDB_CODE_GRANT_PAR_IVLD_ACTIVE) {
|
||||||
|
cfgAllErr = terrno; // output 1st or more specific error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -1283,7 +1287,12 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
strcpy(dcfgReq.config, "supportvnodes");
|
strcpy(dcfgReq.config, "supportvnodes");
|
||||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||||
} else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0 || strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) {
|
} else if (strncasecmp(cfgReq.config, GRANT_ACTIVE_CODE, 10) == 0 ||
|
||||||
|
strncasecmp(cfgReq.config, GRANT_C_ACTIVE_CODE, 11) == 0) {
|
||||||
|
if (cfgReq.dnodeId != -1) {
|
||||||
|
terrno = TSDB_CODE_INVALID_CFG;
|
||||||
|
goto _err_out;
|
||||||
|
}
|
||||||
int8_t opt = strncasecmp(cfgReq.config, "a", 1) == 0 ? DND_ACTIVE_CODE : DND_CONN_ACTIVE_CODE;
|
int8_t opt = strncasecmp(cfgReq.config, "a", 1) == 0 ? DND_ACTIVE_CODE : DND_CONN_ACTIVE_CODE;
|
||||||
int8_t index = opt == DND_ACTIVE_CODE ? 10 : 11;
|
int8_t index = opt == DND_ACTIVE_CODE ? 10 : 11;
|
||||||
if (' ' != cfgReq.config[index] && 0 != cfgReq.config[index]) {
|
if (' ' != cfgReq.config[index] && 0 != cfgReq.config[index]) {
|
||||||
|
@ -1301,12 +1310,11 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
||||||
goto _err_out;
|
goto _err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(dcfgReq.config, opt == DND_ACTIVE_CODE ? "activeCode" : "cActiveCode");
|
strcpy(dcfgReq.config, opt == DND_ACTIVE_CODE ? GRANT_ACTIVE_CODE : GRANT_C_ACTIVE_CODE);
|
||||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value);
|
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value);
|
||||||
|
|
||||||
if (mndConfigDnode(pMnode, pReq, &cfgReq, opt) != 0) {
|
if ((terrno = 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", cfgReq.dnodeId, terrstr());
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
|
||||||
goto _err_out;
|
goto _err_out;
|
||||||
}
|
}
|
||||||
tFreeSMCfgDnodeReq(&cfgReq);
|
tFreeSMCfgDnodeReq(&cfgReq);
|
||||||
|
|
|
@ -444,6 +444,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_DEC_IVLD_KLEN, "Invalid klen to decod
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_IVLD_KEY, "Invalid key to gen 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_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")
|
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN, "Invalid klen to encode active code")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_DIST, "Invalid dist to parse active code")
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")
|
||||||
|
|
|
@ -247,7 +247,10 @@ class TDTestCase:
|
||||||
tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"')
|
tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"')
|
||||||
tdSql.query(f'select * from information_schema.ins_dnodes')
|
tdSql.query(f'select * from information_schema.ins_dnodes')
|
||||||
tdSql.checkEqual(tdSql.queryResult[0][8],"")
|
tdSql.checkEqual(tdSql.queryResult[0][8],"")
|
||||||
tdSql.execute('alter dnode 1 "activeCode" ""')
|
tdSql.error('alter dnode 1 "activeCode" ""')
|
||||||
|
tdSql.error('alter dnode 1 "activeCode"')
|
||||||
|
tdSql.execute('alter all dnodes "activeCode" ""')
|
||||||
|
tdSql.execute('alter all dnodes "activeCode"')
|
||||||
tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes')
|
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][0],"")
|
||||||
tdSql.checkEqual(tdSql.queryResult[0][1],'')
|
tdSql.checkEqual(tdSql.queryResult[0][1],'')
|
||||||
|
@ -259,6 +262,10 @@ class TDTestCase:
|
||||||
tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"')
|
tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"')
|
||||||
tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"')
|
tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"')
|
||||||
tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"')
|
tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"')
|
||||||
|
tdSql.error('alter dnode 1 "cActiveCode" ""')
|
||||||
|
tdSql.error('alter dnode 1 "cActiveCode"')
|
||||||
|
tdSql.execute('alter all dnodes "cActiveCode" ""')
|
||||||
|
tdSql.execute('alter all dnodes "cActiveCode"')
|
||||||
tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes')
|
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][0],"")
|
||||||
tdSql.checkEqual(tdSql.queryResult[0][1],"")
|
tdSql.checkEqual(tdSql.queryResult[0][1],"")
|
||||||
|
|
Loading…
Reference in New Issue