diff --git a/include/common/tgrant.h b/include/common/tgrant.h index 41e997e78d..4abb24aa95 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -61,7 +61,6 @@ typedef enum { typedef struct { int64_t grantedTime; - int64_t connGrantedTime; } SGrantedInfo; int32_t grantCheck(EGrantType grant); diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 0b733f7ce8..7889f2295c 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -37,8 +37,7 @@ static const SSysDbTableSchema dnodesSchema[] = { {.name = "reboot_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true}, {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, #ifdef TD_ENTERPRISE - {.name = "active_code", .bytes = TSDB_ACTIVE_KEY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, - {.name = "c_active_code", .bytes = TSDB_CONN_ACTIVE_KEY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "machine_id", .bytes = TSDB_MACHINE_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, #endif }; diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index b1b7cb3599..19f18d9a9d 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -28,6 +28,7 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len); int64_t mndGetClusterId(SMnode *pMnode); int64_t mndGetClusterCreateTime(SMnode *pMnode); int64_t mndGetClusterUpTime(SMnode *pMnode); +int32_t mndGetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo); int32_t mndGetClusterActive(SMnode *pMnode, char* active); int32_t mndGetClusterMachineIds(SMnode *pMnode, SArray *pIds); int32_t mndProcessClusterMachineIds(SMnode *pMnode, SMachineId *pIds, int32_t nIds); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 730d5902a3..17ca969e4a 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -196,8 +196,9 @@ typedef struct { int64_t createdTime; int64_t updateTime; int32_t upTime; - char active[TSDB_UNIQ_ACTIVE_KEY_LEN + 1]; + int64_t grantedTime; SArray* pMachineIds; + char active[TSDB_UNIQ_ACTIVE_KEY_LEN + 1]; } SClusterObj; typedef struct { @@ -220,6 +221,7 @@ typedef struct { char ep[TSDB_EP_LEN]; char active[TSDB_ACTIVE_KEY_LEN]; char connActive[TSDB_CONN_ACTIVE_KEY_LEN]; + char machineId[TSDB_MACHINE_ID_LEN + 1]; } SDnodeObj; typedef struct { diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 7c7a177a95..f93eb9a95b 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -100,6 +100,18 @@ int64_t mndGetClusterId(SMnode *pMnode) { return clusterId; } +int32_t mndGetClusterGrantedInfo(SMnode *pMnode, SGrantedInfo *pInfo) { + void *pIter = NULL; + SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter); + if (pCluster != NULL) { + pInfo->grantedTime = pCluster->grantedTime; + mndReleaseCluster(pMnode, pCluster, pIter); + return 0; + } + + return -1; +} + int32_t mndGetClusterActive(SMnode *pMnode, char *active) { void *pIter = NULL; SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 81cdb8de1d..f1ed05183b 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -30,7 +30,7 @@ #include "tunit.h" #define TSDB_DNODE_VER_NUMBER 2 -#define TSDB_DNODE_RESERVE_SIZE 64 +#define TSDB_DNODE_RESERVE_SIZE 40 static const char *offlineReason[] = { "", @@ -136,6 +136,10 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { tstrncpy(dnodeObj.fqdn, tsLocalFqdn, TSDB_FQDN_LEN); dnodeObj.fqdn[TSDB_FQDN_LEN - 1] = 0; snprintf(dnodeObj.ep, TSDB_EP_LEN - 1, "%s:%u", tsLocalFqdn, tsServerPort); + char *machineId = grantGetMachineId(); + if (machineId) { + memcpy(dnodeObj.machineId, machineId, TSDB_MACHINE_ID_LEN); + } pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, NULL, "create-dnode"); if (pTrans == NULL) goto _OVER; @@ -168,6 +172,7 @@ static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, _OVER) SDB_SET_INT16(pRaw, dataPos, pDnode->port, _OVER) SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER) SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER) SDB_SET_INT16(pRaw, dataPos, TSDB_ACTIVE_KEY_LEN, _OVER) SDB_SET_BINARY(pRaw, dataPos, pDnode->active, TSDB_ACTIVE_KEY_LEN, _OVER) @@ -212,6 +217,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, _OVER) SDB_GET_INT16(pRaw, dataPos, &pDnode->port, _OVER) SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER) SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER) if (sver > 1) { int16_t keyLen = 0; @@ -740,6 +746,10 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC dnodeObj.port = pCreate->port; tstrncpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN); snprintf(dnodeObj.ep, TSDB_EP_LEN - 1, "%s:%u", pCreate->fqdn, pCreate->port); + char *machineId = grantGetMachineId(); + if (machineId) { + memcpy(dnodeObj.machineId, machineId, TSDB_MACHINE_ID_LEN); + } pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq, "create-dnode"); if (pTrans == NULL) goto _OVER;