提交 8a68dd6e 编写于 作者: S Shengliang Guan

[TD-1033] change clusterId to string

上级 b536877f
...@@ -490,7 +490,6 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { ...@@ -490,7 +490,6 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes); pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
pCfg->moduleStatus = htonl(pCfg->moduleStatus); pCfg->moduleStatus = htonl(pCfg->moduleStatus);
pCfg->dnodeId = htonl(pCfg->dnodeId); pCfg->dnodeId = htonl(pCfg->dnodeId);
pCfg->clusterId = htonl(pCfg->clusterId);
for (int32_t i = 0; i < pMnodes->nodeNum; ++i) { for (int32_t i = 0; i < pMnodes->nodeNum; ++i) {
SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i]; SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i];
...@@ -696,12 +695,12 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { ...@@ -696,12 +695,12 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
//strcpy(pStatus->dnodeName, tsDnodeName); //strcpy(pStatus->dnodeName, tsDnodeName);
pStatus->version = htonl(tsVersion); pStatus->version = htonl(tsVersion);
pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId); pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId);
pStatus->clusterId = htonl(tsDnodeCfg.clusterId);
strcpy(pStatus->dnodeEp, tsLocalEp);
pStatus->lastReboot = htonl(tsRebootTime); pStatus->lastReboot = htonl(tsRebootTime);
pStatus->numOfCores = htons((uint16_t) tsNumOfCores); pStatus->numOfCores = htons((uint16_t) tsNumOfCores);
pStatus->diskAvailable = tsAvailDataDirGB; pStatus->diskAvailable = tsAvailDataDirGB;
pStatus->alternativeRole = (uint8_t) tsAlternativeRole; pStatus->alternativeRole = (uint8_t) tsAlternativeRole;
tstrncpy(pStatus->clusterId, tsDnodeCfg.clusterId, TSDB_CLUSTER_ID_LEN);
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
// fill cluster cfg parameters // fill cluster cfg parameters
pStatus->clusterCfg.numOfMnodes = htonl(tsNumOfMnodes); pStatus->clusterCfg.numOfMnodes = htonl(tsNumOfMnodes);
...@@ -768,11 +767,11 @@ static bool dnodeReadDnodeCfg() { ...@@ -768,11 +767,11 @@ static bool dnodeReadDnodeCfg() {
tsDnodeCfg.dnodeId = dnodeId->valueint; tsDnodeCfg.dnodeId = dnodeId->valueint;
cJSON* clusterId = cJSON_GetObjectItem(root, "clusterId"); cJSON* clusterId = cJSON_GetObjectItem(root, "clusterId");
if (!clusterId || clusterId->type != cJSON_Number) { if (!clusterId || clusterId->type != cJSON_String) {
dError("failed to read dnodeCfg.json, clusterId not found"); dError("failed to read dnodeCfg.json, clusterId not found");
goto PARSE_CFG_OVER; goto PARSE_CFG_OVER;
} }
tsDnodeCfg.clusterId = clusterId->valueint; tstrncpy(tsDnodeCfg.clusterId, clusterId->valuestring, TSDB_CLUSTER_ID_LEN);
ret = true; ret = true;
...@@ -793,12 +792,12 @@ static void dnodeSaveDnodeCfg() { ...@@ -793,12 +792,12 @@ static void dnodeSaveDnodeCfg() {
if (!fp) return; if (!fp) return;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 100; int32_t maxLen = 200;
char * content = calloc(1, maxLen + 1); char * content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsDnodeCfg.dnodeId); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsDnodeCfg.dnodeId);
len += snprintf(content + len, maxLen - len, " \"clusterId\": %d\n", tsDnodeCfg.clusterId); len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%s\"\n", tsDnodeCfg.clusterId);
len += snprintf(content + len, maxLen - len, "}\n"); len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp); fwrite(content, 1, len, fp);
...@@ -811,9 +810,9 @@ static void dnodeSaveDnodeCfg() { ...@@ -811,9 +810,9 @@ static void dnodeSaveDnodeCfg() {
void dnodeUpdateDnodeCfg(SDMDnodeCfg *pCfg) { void dnodeUpdateDnodeCfg(SDMDnodeCfg *pCfg) {
if (tsDnodeCfg.dnodeId == 0) { if (tsDnodeCfg.dnodeId == 0) {
dInfo("dnodeId is set to %d, clusterId is set to %d", pCfg->dnodeId, pCfg->clusterId); dInfo("dnodeId is set to %d, clusterId is set to %s", pCfg->dnodeId, pCfg->clusterId);
tsDnodeCfg.dnodeId = pCfg->dnodeId; tsDnodeCfg.dnodeId = pCfg->dnodeId;
tsDnodeCfg.clusterId = pCfg->clusterId; tstrncpy(tsDnodeCfg.clusterId, pCfg->clusterId, TSDB_CLUSTER_ID_LEN);
dnodeSaveDnodeCfg(); dnodeSaveDnodeCfg();
} }
} }
......
...@@ -174,7 +174,7 @@ static void addVersionInfo(SBufferWriter* bw) { ...@@ -174,7 +174,7 @@ static void addVersionInfo(SBufferWriter* bw) {
} }
static void addRuntimeInfo(SBufferWriter* bw) { static void addRuntimeInfo(SBufferWriter* bw) {
addIntField(bw, "clusterId", mnodeGetClusterId()); addStringField(bw, "clusterId", mnodeGetClusterId());
// addIntField(&bw, "numOfDnode", 1); // addIntField(&bw, "numOfDnode", 1);
// addIntField(&bw, "numOfVnode", 1); // addIntField(&bw, "numOfVnode", 1);
// addIntField(&bw, "numOfStable", 1); // addIntField(&bw, "numOfStable", 1);
......
...@@ -254,6 +254,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -254,6 +254,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_TIMEZONE_LEN 96 #define TSDB_TIMEZONE_LEN 96
#define TSDB_LABEL_LEN 8 #define TSDB_LABEL_LEN 8
#define TSDB_CLUSTER_ID_LEN 40
#define TSDB_FQDN_LEN 128 #define TSDB_FQDN_LEN 128
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6) #define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
#define TSDB_IPv4ADDR_LEN 16 #define TSDB_IPv4ADDR_LEN 16
......
...@@ -548,10 +548,10 @@ typedef struct { ...@@ -548,10 +548,10 @@ typedef struct {
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
int32_t clusterId;
uint32_t moduleStatus; uint32_t moduleStatus;
uint32_t numOfVnodes; uint32_t numOfVnodes;
uint32_t reserved; char clusterId[TSDB_CLUSTER_ID_LEN];
char reserved[16];
} SDMDnodeCfg; } SDMDnodeCfg;
typedef struct { typedef struct {
...@@ -589,7 +589,7 @@ typedef struct { ...@@ -589,7 +589,7 @@ typedef struct {
uint16_t openVnodes; uint16_t openVnodes;
uint16_t numOfCores; uint16_t numOfCores;
float diskAvailable; // GB float diskAvailable; // GB
int32_t clusterId; char clusterId[TSDB_CLUSTER_ID_LEN];
uint8_t alternativeRole; uint8_t alternativeRole;
uint8_t reserve2[15]; uint8_t reserve2[15];
SClusterCfg clusterCfg; SClusterCfg clusterCfg;
......
...@@ -20,16 +20,10 @@ ...@@ -20,16 +20,10 @@
extern "C" { extern "C" {
#endif #endif
struct SClusterObj;
int32_t mnodeInitCluster(); int32_t mnodeInitCluster();
void mnodeCleanupCluster(); void mnodeCleanupCluster();
int32_t mnodeGetClusterId();
void mnodeUpdateClusterId(); void mnodeUpdateClusterId();
void * mnodeGetCluster(int32_t clusterId); const char* mnodeGetClusterId();
void * mnodeGetNextCluster(void *pIter, struct SClusterObj **pCluster);
void mnodeIncClusterRef(struct SClusterObj *pCluster);
void mnodeDecClusterRef(struct SClusterObj *pCluster);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -37,9 +37,9 @@ struct define notes: ...@@ -37,9 +37,9 @@ struct define notes:
*/ */
typedef struct SClusterObj { typedef struct SClusterObj {
int32_t clusterId; char uid[TSDB_CLUSTER_ID_LEN];
int64_t createdTime; int64_t createdTime;
int8_t reserved[36]; int8_t reserved[12];
int8_t updateEnd[4]; int8_t updateEnd[4];
int32_t refCount; int32_t refCount;
} SClusterObj; } SClusterObj;
...@@ -90,7 +90,7 @@ typedef struct STableObj { ...@@ -90,7 +90,7 @@ typedef struct STableObj {
typedef struct SSuperTableObj { typedef struct SSuperTableObj {
STableObj info; STableObj info;
int8_t reserved0[1]; // for fill struct STableObj to 4byte align int8_t reserved0[9]; // for fill struct STableObj to 4byte align
int16_t nextColId; int16_t nextColId;
int32_t sversion; int32_t sversion;
uint64_t uid; uint64_t uid;
...@@ -103,12 +103,11 @@ typedef struct SSuperTableObj { ...@@ -103,12 +103,11 @@ typedef struct SSuperTableObj {
int32_t numOfTables; int32_t numOfTables;
SSchema * schema; SSchema * schema;
void * vgHash; void * vgHash;
int8_t reserved2[6];
} SSuperTableObj; } SSuperTableObj;
typedef struct { typedef struct {
STableObj info; STableObj info;
int8_t reserved0[1]; // for fill struct STableObj to 4byte align int8_t reserved0[9]; // for fill struct STableObj to 4byte align
int16_t nextColId; //used by normal table int16_t nextColId; //used by normal table
int32_t sversion; //used by normal table int32_t sversion; //used by normal table
uint64_t uid; uint64_t uid;
...@@ -144,7 +143,7 @@ typedef struct SVgObj { ...@@ -144,7 +143,7 @@ typedef struct SVgObj {
int8_t status; int8_t status;
int8_t reserved0[4]; int8_t reserved0[4];
SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
int8_t reserved1[4]; int8_t reserved1[12];
int8_t updateEnd[4]; int8_t updateEnd[4];
int32_t refCount; int32_t refCount;
int32_t numOfTables; int32_t numOfTables;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
static void * tsClusterSdb = NULL; static void * tsClusterSdb = NULL;
static int32_t tsClusterUpdateSize; static int32_t tsClusterUpdateSize;
static int32_t tsClusterId; static char tsClusterId[TSDB_CLUSTER_ID_LEN];
static int32_t mnodeCreateCluster(); static int32_t mnodeCreateCluster();
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
...@@ -90,7 +90,7 @@ int32_t mnodeInitCluster() { ...@@ -90,7 +90,7 @@ int32_t mnodeInitCluster() {
.hashSessions = TSDB_DEFAULT_CLUSTER_HASH_SIZE, .hashSessions = TSDB_DEFAULT_CLUSTER_HASH_SIZE,
.maxRowSize = tsClusterUpdateSize, .maxRowSize = tsClusterUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_INT, .keyType = SDB_KEY_STRING,
.insertFp = mnodeClusterActionInsert, .insertFp = mnodeClusterActionInsert,
.deleteFp = mnodeClusterActionDelete, .deleteFp = mnodeClusterActionDelete,
.updateFp = mnodeClusterActionUpdate, .updateFp = mnodeClusterActionUpdate,
...@@ -118,10 +118,6 @@ void mnodeCleanupCluster() { ...@@ -118,10 +118,6 @@ void mnodeCleanupCluster() {
tsClusterSdb = NULL; tsClusterSdb = NULL;
} }
void *mnodeGetCluster(int32_t clusterId) {
return sdbGetRow(tsClusterSdb, &clusterId);
}
void *mnodeGetNextCluster(void *pIter, SClusterObj **pCluster) { void *mnodeGetNextCluster(void *pIter, SClusterObj **pCluster) {
return sdbFetchRow(tsClusterSdb, pIter, (void **)pCluster); return sdbFetchRow(tsClusterSdb, pIter, (void **)pCluster);
} }
...@@ -141,7 +137,13 @@ static int32_t mnodeCreateCluster() { ...@@ -141,7 +137,13 @@ static int32_t mnodeCreateCluster() {
SClusterObj *pCluster = malloc(sizeof(SClusterObj)); SClusterObj *pCluster = malloc(sizeof(SClusterObj));
memset(pCluster, 0, sizeof(SClusterObj)); memset(pCluster, 0, sizeof(SClusterObj));
pCluster->createdTime = taosGetTimestampMs(); pCluster->createdTime = taosGetTimestampMs();
pCluster->clusterId = labs((pCluster->createdTime >> 32) & (pCluster->createdTime)) | (*(int32_t*)tsFirst); bool getuid = taosGetSystemUid(pCluster->uid);
if (!getuid) {
strcpy(pCluster->uid, "tdengine2.0");
mError("failed to get uid from system, set to default val %s", pCluster->uid);
} else {
mDebug("uid is %s", pCluster->uid);
}
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -152,7 +154,7 @@ static int32_t mnodeCreateCluster() { ...@@ -152,7 +154,7 @@ static int32_t mnodeCreateCluster() {
return sdbInsertRow(&oper); return sdbInsertRow(&oper);
} }
int32_t mnodeGetClusterId() { const char* mnodeGetClusterId() {
return tsClusterId; return tsClusterId;
} }
...@@ -160,8 +162,8 @@ void mnodeUpdateClusterId() { ...@@ -160,8 +162,8 @@ void mnodeUpdateClusterId() {
SClusterObj *pCluster = NULL; SClusterObj *pCluster = NULL;
void *pIter = mnodeGetNextCluster(NULL, &pCluster); void *pIter = mnodeGetNextCluster(NULL, &pCluster);
if (pCluster != NULL) { if (pCluster != NULL) {
tsClusterId = pCluster->clusterId; tstrncpy(tsClusterId, pCluster->uid, TSDB_CLUSTER_ID_LEN);
mInfo("cluster id is %d", tsClusterId); mInfo("cluster id is set to %s", tsClusterId);
} }
mnodeDecClusterRef(pCluster); mnodeDecClusterRef(pCluster);
...@@ -172,8 +174,8 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void * ...@@ -172,8 +174,8 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
pShow->bytes[cols] = 4; pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "clusterId"); strcpy(pSchema[cols].name, "clusterId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -212,7 +214,7 @@ static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, ...@@ -212,7 +214,7 @@ static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows,
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *) pWrite = pCluster->clusterId; STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pCluster->uid, TSDB_CLUSTER_ID_LEN);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
......
...@@ -353,7 +353,6 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { ...@@ -353,7 +353,6 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
pStatus->moduleStatus = htonl(pStatus->moduleStatus); pStatus->moduleStatus = htonl(pStatus->moduleStatus);
pStatus->lastReboot = htonl(pStatus->lastReboot); pStatus->lastReboot = htonl(pStatus->lastReboot);
pStatus->numOfCores = htons(pStatus->numOfCores); pStatus->numOfCores = htons(pStatus->numOfCores);
pStatus->clusterId = htonl(pStatus->clusterId);
uint32_t version = htonl(pStatus->version); uint32_t version = htonl(pStatus->version);
if (version != tsVersion) { if (version != tsVersion) {
...@@ -383,10 +382,10 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { ...@@ -383,10 +382,10 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
pDnode->moduleStatus = pStatus->moduleStatus; pDnode->moduleStatus = pStatus->moduleStatus;
if (pStatus->dnodeId == 0) { if (pStatus->dnodeId == 0) {
mDebug("dnode:%d %s, first access, set clusterId %d", pDnode->dnodeId, pDnode->dnodeEp, mnodeGetClusterId()); mDebug("dnode:%d %s, first access, set clusterId %s", pDnode->dnodeId, pDnode->dnodeEp, mnodeGetClusterId());
} else { } else {
if (pStatus->clusterId != mnodeGetClusterId()) { if (strncmp(pStatus->clusterId, mnodeGetClusterId(), TSDB_CLUSTER_ID_LEN - 1) != 0) {
mError("dnode:%d, input clusterId %d not match with exist %d", pDnode->dnodeId, pStatus->clusterId, mError("dnode:%d, input clusterId %s not match with exist %s", pDnode->dnodeId, pStatus->clusterId,
mnodeGetClusterId()); mnodeGetClusterId());
return TSDB_CODE_MND_INVALID_CLUSTER_ID; return TSDB_CODE_MND_INVALID_CLUSTER_ID;
} else { } else {
...@@ -405,7 +404,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { ...@@ -405,7 +404,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId); pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt); pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes); pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes);
pRsp->dnodeCfg.clusterId = htonl(mnodeGetClusterId()); tstrncpy(pRsp->dnodeCfg.clusterId, mnodeGetClusterId(), TSDB_CLUSTER_ID_LEN);
SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp)); SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp));
for (int32_t j = 0; j < openVnodes; ++j) { for (int32_t j = 0; j < openVnodes; ++j) {
......
...@@ -31,6 +31,7 @@ bool taosGetSysMemory(float *memoryUsedMB); ...@@ -31,6 +31,7 @@ bool taosGetSysMemory(float *memoryUsedMB);
void taosPrintOsInfo(); void taosPrintOsInfo();
int taosSystem(const char * cmd) ; int taosSystem(const char * cmd) ;
void taosKillSystem(); void taosKillSystem();
bool taosGetSystemUid(char *uid);
// TAOS_OS_FUNC_SYSINFO_CORE // TAOS_OS_FUNC_SYSINFO_CORE
void taosSetCoreDump(); void taosSetCoreDump();
......
...@@ -639,4 +639,19 @@ void taosSetCoreDump() { ...@@ -639,4 +639,19 @@ void taosSetCoreDump() {
} }
bool taosGetSystemUid(char *uid) {
int fd;
int len = 0;
fd = open("/proc/sys/kernel/random/uuid", 0);
if (fd < 0) {
return false;
} else {
len = read(fd, uid, TSDB_CLUSTER_ID_LEN);
close(fd);
}
return len > 0;
}
#endif #endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册