feat: support uniq active code

This commit is contained in:
kailixu 2023-12-19 18:02:53 +08:00
parent 70006bb711
commit 1f5384ad40
9 changed files with 165 additions and 118 deletions

View File

@ -62,6 +62,7 @@ typedef struct {
} SGrantedInfo;
int32_t grantCheck(EGrantType grant);
int32_t grantAlterActiveCode(const char* active);
char* grantGetMachineId();
#ifndef GRANTS_CFG

View File

@ -1600,6 +1600,7 @@ typedef struct {
SEp ep;
char active[TSDB_ACTIVE_KEY_LEN];
char connActive[TSDB_CONN_ACTIVE_KEY_LEN];
char machineId[TSDB_MACHINE_ID_LEN + 1];
} SDnodeInfo;
typedef struct {

View File

@ -74,111 +74,111 @@
#define TK_NK_IPTOKEN 55
#define TK_FORCE 56
#define TK_UNSAFE 57
#define TK_LOCAL 58
#define TK_QNODE 59
#define TK_BNODE 60
#define TK_SNODE 61
#define TK_MNODE 62
#define TK_VNODE 63
#define TK_DATABASE 64
#define TK_USE 65
#define TK_FLUSH 66
#define TK_TRIM 67
#define TK_COMPACT 68
#define TK_IF 69
#define TK_NOT 70
#define TK_EXISTS 71
#define TK_BUFFER 72
#define TK_CACHEMODEL 73
#define TK_CACHESIZE 74
#define TK_COMP 75
#define TK_DURATION 76
#define TK_NK_VARIABLE 77
#define TK_MAXROWS 78
#define TK_MINROWS 79
#define TK_KEEP 80
#define TK_PAGES 81
#define TK_PAGESIZE 82
#define TK_TSDB_PAGESIZE 83
#define TK_PRECISION 84
#define TK_REPLICA 85
#define TK_VGROUPS 86
#define TK_SINGLE_STABLE 87
#define TK_RETENTIONS 88
#define TK_SCHEMALESS 89
#define TK_WAL_LEVEL 90
#define TK_WAL_FSYNC_PERIOD 91
#define TK_WAL_RETENTION_PERIOD 92
#define TK_WAL_RETENTION_SIZE 93
#define TK_WAL_ROLL_PERIOD 94
#define TK_WAL_SEGMENT_SIZE 95
#define TK_STT_TRIGGER 96
#define TK_TABLE_PREFIX 97
#define TK_TABLE_SUFFIX 98
#define TK_KEEP_TIME_OFFSET 99
#define TK_NK_COLON 100
#define TK_BWLIMIT 101
#define TK_START 102
#define TK_TIMESTAMP 103
#define TK_END 104
#define TK_TABLE 105
#define TK_NK_LP 106
#define TK_NK_RP 107
#define TK_STABLE 108
#define TK_COLUMN 109
#define TK_MODIFY 110
#define TK_RENAME 111
#define TK_TAG 112
#define TK_SET 113
#define TK_NK_EQ 114
#define TK_USING 115
#define TK_TAGS 116
#define TK_BOOL 117
#define TK_TINYINT 118
#define TK_SMALLINT 119
#define TK_INT 120
#define TK_INTEGER 121
#define TK_BIGINT 122
#define TK_FLOAT 123
#define TK_DOUBLE 124
#define TK_BINARY 125
#define TK_NCHAR 126
#define TK_UNSIGNED 127
#define TK_JSON 128
#define TK_VARCHAR 129
#define TK_MEDIUMBLOB 130
#define TK_BLOB 131
#define TK_VARBINARY 132
#define TK_GEOMETRY 133
#define TK_DECIMAL 134
#define TK_COMMENT 135
#define TK_MAX_DELAY 136
#define TK_WATERMARK 137
#define TK_ROLLUP 138
#define TK_TTL 139
#define TK_SMA 140
#define TK_DELETE_MARK 141
#define TK_FIRST 142
#define TK_LAST 143
#define TK_SHOW 144
#define TK_PRIVILEGES 145
#define TK_DATABASES 146
#define TK_TABLES 147
#define TK_STABLES 148
#define TK_MNODES 149
#define TK_QNODES 150
#define TK_FUNCTIONS 151
#define TK_INDEXES 152
#define TK_ACCOUNTS 153
#define TK_APPS 154
#define TK_CONNECTIONS 155
#define TK_LICENCES 156
#define TK_GRANTS 157
#define TK_QUERIES 158
#define TK_SCORES 159
#define TK_TOPICS 160
#define TK_VARIABLES 161
#define TK_CLUSTER 162
#define TK_CLUSTER 58
#define TK_LOCAL 59
#define TK_QNODE 60
#define TK_BNODE 61
#define TK_SNODE 62
#define TK_MNODE 63
#define TK_VNODE 64
#define TK_DATABASE 65
#define TK_USE 66
#define TK_FLUSH 67
#define TK_TRIM 68
#define TK_COMPACT 69
#define TK_IF 70
#define TK_NOT 71
#define TK_EXISTS 72
#define TK_BUFFER 73
#define TK_CACHEMODEL 74
#define TK_CACHESIZE 75
#define TK_COMP 76
#define TK_DURATION 77
#define TK_NK_VARIABLE 78
#define TK_MAXROWS 79
#define TK_MINROWS 80
#define TK_KEEP 81
#define TK_PAGES 82
#define TK_PAGESIZE 83
#define TK_TSDB_PAGESIZE 84
#define TK_PRECISION 85
#define TK_REPLICA 86
#define TK_VGROUPS 87
#define TK_SINGLE_STABLE 88
#define TK_RETENTIONS 89
#define TK_SCHEMALESS 90
#define TK_WAL_LEVEL 91
#define TK_WAL_FSYNC_PERIOD 92
#define TK_WAL_RETENTION_PERIOD 93
#define TK_WAL_RETENTION_SIZE 94
#define TK_WAL_ROLL_PERIOD 95
#define TK_WAL_SEGMENT_SIZE 96
#define TK_STT_TRIGGER 97
#define TK_TABLE_PREFIX 98
#define TK_TABLE_SUFFIX 99
#define TK_KEEP_TIME_OFFSET 100
#define TK_NK_COLON 101
#define TK_BWLIMIT 102
#define TK_START 103
#define TK_TIMESTAMP 104
#define TK_END 105
#define TK_TABLE 106
#define TK_NK_LP 107
#define TK_NK_RP 108
#define TK_STABLE 109
#define TK_COLUMN 110
#define TK_MODIFY 111
#define TK_RENAME 112
#define TK_TAG 113
#define TK_SET 114
#define TK_NK_EQ 115
#define TK_USING 116
#define TK_TAGS 117
#define TK_BOOL 118
#define TK_TINYINT 119
#define TK_SMALLINT 120
#define TK_INT 121
#define TK_INTEGER 122
#define TK_BIGINT 123
#define TK_FLOAT 124
#define TK_DOUBLE 125
#define TK_BINARY 126
#define TK_NCHAR 127
#define TK_UNSIGNED 128
#define TK_JSON 129
#define TK_VARCHAR 130
#define TK_MEDIUMBLOB 131
#define TK_BLOB 132
#define TK_VARBINARY 133
#define TK_GEOMETRY 134
#define TK_DECIMAL 135
#define TK_COMMENT 136
#define TK_MAX_DELAY 137
#define TK_WATERMARK 138
#define TK_ROLLUP 139
#define TK_TTL 140
#define TK_SMA 141
#define TK_DELETE_MARK 142
#define TK_FIRST 143
#define TK_LAST 144
#define TK_SHOW 145
#define TK_PRIVILEGES 146
#define TK_DATABASES 147
#define TK_TABLES 148
#define TK_STABLES 149
#define TK_MNODES 150
#define TK_QNODES 151
#define TK_FUNCTIONS 152
#define TK_INDEXES 153
#define TK_ACCOUNTS 154
#define TK_APPS 155
#define TK_CONNECTIONS 156
#define TK_LICENCES 157
#define TK_GRANTS 158
#define TK_QUERIES 159
#define TK_SCORES 160
#define TK_TOPICS 161
#define TK_VARIABLES 162
#define TK_BNODES 163
#define TK_SNODES 164
#define TK_TRANSACTIONS 165

View File

@ -562,6 +562,7 @@ int32_t* taosGetErrno();
#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_PAR_IVLD_DIST TAOS_DEF_ERROR_CODE(0, 0x0815)
#define TSDB_CODE_GRANT_INVALID_HW TAOS_DEF_ERROR_CODE(0, 0x0816)
// sync
// #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x

View File

@ -25,6 +25,7 @@
#include "tglobal.h"
#include "tgrant.h"
#include "tqueue.h"
#include "tref.h"
#include "ttime.h"
#include "version.h"
#include "wal.h"
@ -106,6 +107,7 @@ typedef struct {
typedef struct SMnode {
int32_t selfDnodeId;
int32_t refMgmt;
int64_t clusterId;
TdThread thread;
TdThreadRwlock lock;
@ -133,6 +135,10 @@ typedef struct SMnode {
int64_t ipWhiteVer;
} SMnode;
typedef struct {
RefFp freeFp;
} SMnodeRefInfo;
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
int64_t mndGenerateUid(const char *name, int32_t len);

View File

@ -434,6 +434,7 @@ static int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
goto _exit;
}
// code = xxx;
code = grantAlterActiveCode(cfgReq.value);
#else
code = TSDB_CODE_OPS_NOT_SUPPORT;
goto _exit;
@ -447,11 +448,11 @@ _exit:
tFreeSMCfgClusterReq(&cfgReq);
if (code != 0) {
terrno = code;
mError("cluster: failed to config:%s, %s since %s", cfgReq.config, cfgReq.value, terrstr());
mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, terrstr());
} else {
mError("cluster: success to config:%s, %s", cfgReq.config, cfgReq.value);
mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
}
return -1;
return code;
}
static int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {

View File

@ -59,8 +59,10 @@ enum {
};
typedef struct {
char machineId[TSDB_MACHINE_ID_LEN + 1];
tsem_t sem;
SMnodeRefInfo refInfo;
int64_t refId;
tsem_t sem;
char machineId[TSDB_MACHINE_ID_LEN + 1];
} SMachineInfo;
static int32_t mndCreateDefaultDnode(SMnode *pMnode);
@ -416,6 +418,7 @@ void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
tstrncpy(dInfo.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
tstrncpy(dInfo.active, pDnode->active, TSDB_ACTIVE_KEY_LEN);
tstrncpy(dInfo.connActive, pDnode->connActive, TSDB_CONN_ACTIVE_KEY_LEN);
tstrncpy(dInfo.machineId, pDnode->machineId, TSDB_MACHINE_ID_LEN + 1);
sdbRelease(pSdb, pDnode);
if (mndIsMnode(pMnode, pDnode->id)) {
dInfo.isMnode = 1;
@ -743,13 +746,19 @@ _OVER:
}
static int32_t mndSendGetMachineToDnode(SMnode *pMnode, SDnodeObj *pObj, SMachineInfo *pInfo) {
SRpcMsg rpcMsg = {.pCont = NULL, .contLen = 0, .msgType = TDMT_MND_GET_MACHINE, .info.ahandle = pInfo};
SRpcMsg rpcMsg = {.pCont = NULL, .contLen = 0, .msgType = TDMT_MND_GET_MACHINE, .info.ahandle = (void*)pInfo->refId};
SEpSet epSet = {.numOfEps = 1};
strncpy(epSet.eps[0].fqdn, pObj->fqdn, TSDB_FQDN_LEN);
epSet.eps[0].port = pObj->port;
return tmsgSendReq(&epSet, &rpcMsg);
}
static void mndDestroyMachineInfo(void *pInfo) {
if (pInfo) {
tsem_destroy(&((SMachineInfo *)pInfo)->sem);
}
}
static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pCreate) {
int32_t code = -1;
SSdbRaw *pRaw = NULL;
@ -767,7 +776,11 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
pInfo->refInfo.freeFp = mndDestroyMachineInfo;
tsem_init(&pInfo->sem, 0, 0);
if((pInfo->refId = taosAddRef(pMnode->refMgmt, pInfo)) < 0) {
goto _OVER;
}
if ((terrno = mndSendGetMachineToDnode(pMnode, &dnodeObj, pInfo)) != 0) {
goto _OVER;
}
@ -798,8 +811,7 @@ _OVER:
mndTransDrop(pTrans);
sdbFreeRaw(pRaw);
if (pInfo) {
tsem_destroy(&pInfo->sem);
taosMemoryFree(pInfo);
taosRemoveRef(pMnode->refMgmt, pInfo->refId);
}
return code;
}
@ -1280,10 +1292,16 @@ static int32_t mndProcessGetMachineRsp(SRpcMsg *pRsp) {
return -1;
}
SMachineInfo *pInfo = pRsp->info.ahandle;
if (pInfo) {
memcpy(pInfo->machineId, pRsp->pCont, TSDB_MACHINE_ID_LEN);
tsem_post(&pInfo->sem);
SMnode *pMnode = pRsp->info.node;
int64_t refId = (int64_t)pRsp->info.ahandle;
if (pMnode) {
SMachineInfo *pInfo = taosAcquireRef(pMnode->refMgmt, refId);
if (pInfo) {
memcpy(pInfo->machineId, pRsp->pCont, TSDB_MACHINE_ID_LEN);
tsem_post(&pInfo->sem);
taosReleaseRef(pMnode->refMgmt, refId);
}
}
return 0;

View File

@ -543,6 +543,14 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
memcpy(pMnode->syncMgmt.nodeRoles, pOption->nodeRoles, sizeof(pOption->nodeRoles));
}
static void mndDestroyRefInfo(void *pInfo) {
SMnodeRefInfo *pRefInfo = pInfo;
if (pRefInfo && pRefInfo->freeFp) {
(*pRefInfo->freeFp)(pInfo);
}
taosMemoryFree(pInfo);
}
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
mInfo("start to open mnode in %s", path);
@ -567,7 +575,16 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
return NULL;
}
int32_t code = mndCreateDir(pMnode, path);
int32_t code = 0;
if ((pMnode->refMgmt = taosOpenRef(200, mndDestroyRefInfo)) < 0) {
code = terrno;
mError("failed to open mnode since %s", terrstr());
mndClose(pMnode);
terrno = code;
return NULL;
}
code = mndCreateDir(pMnode, path);
if (code != 0) {
code = terrno;
mError("failed to open mnode since %s", terrstr());
@ -610,6 +627,7 @@ void mndClose(SMnode *pMnode) {
if (pMnode != NULL) {
mInfo("start to close mnode");
mndCleanupSteps(pMnode, -1);
taosCloseRef(pMnode->refMgmt);
taosMemoryFreeClear(pMnode->path);
taosMemoryFreeClear(pMnode);
mInfo("mnode is closed");

View File

@ -449,6 +449,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_IVLD_KEY, "Invalid key to gen ac
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_PAR_IVLD_DIST, "Invalid dist to parse active code")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_INVALID_HW, "Invalid hardware")
// sync
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")