enh: getsystemuuid
This commit is contained in:
parent
e81e999fc1
commit
47a6f3e6bc
|
@ -48,3 +48,6 @@ int64_t tGenIdPI64(void);
|
|||
* @return
|
||||
*/
|
||||
int64_t tGenQid64(int8_t dnodeId);
|
||||
|
||||
int32_t taosGetSystemUUID32(uint32_t *uuid);
|
||||
int32_t taosGetSystemUUID64(uint64_t *uuid);
|
||||
|
|
|
@ -1094,18 +1094,14 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
* @return
|
||||
*/
|
||||
uint64_t generateRequestId() {
|
||||
static uint64_t hashId = 0;
|
||||
static uint32_t requestSerialId = 0;
|
||||
static uint32_t hashId = 0;
|
||||
static int32_t requestSerialId = 0;
|
||||
|
||||
if (hashId == 0) {
|
||||
char uid[64] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, tListLen(uid));
|
||||
int32_t code = taosGetSystemUUID32(&hashId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead",
|
||||
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
|
||||
} else {
|
||||
hashId = MurmurHash3_32(uid, strlen(uid));
|
||||
tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1117,7 +1113,7 @@ uint64_t generateRequestId() {
|
|||
uint32_t val = atomic_add_fetch_32(&requestSerialId, 1);
|
||||
if (val >= 0xFFFF) atomic_store_32(&requestSerialId, 0);
|
||||
|
||||
id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||
id = (((uint64_t)(hashId & 0x0FFF)) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||
if (id) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ int32_t schedulerInit() {
|
|||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (taosGetSystemUUID((char *)&schMgmt.sId, sizeof(schMgmt.sId))) {
|
||||
if (taosGetSystemUUID64(&schMgmt.sId)) {
|
||||
qError("generate schedulerId failed, errno:%d", errno);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_SYS_ERROR);
|
||||
}
|
||||
|
|
|
@ -15,19 +15,42 @@
|
|||
|
||||
#include "tuuid.h"
|
||||
|
||||
static int64_t tUUIDHashId = 0;
|
||||
static uint32_t tUUIDHashId = 0;
|
||||
static int32_t tUUIDSerialNo = 0;
|
||||
|
||||
int32_t taosGetSystemUUID32(uint32_t *uuid) {
|
||||
if (uuid == NULL) return TSDB_CODE_APP_ERROR;
|
||||
char uid[65] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, sizeof(uid));
|
||||
uid[64] = 0;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
} else {
|
||||
*uuid = MurmurHash3_32(uid, strlen(uid));
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t taosGetSystemUUID64(uint64_t *uuid) {
|
||||
if (uuid == NULL) return TSDB_CODE_APP_ERROR;
|
||||
char uid[65] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, sizeof(uid));
|
||||
uid[64] = 0;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
} else {
|
||||
*uuid = MurmurHash3_64(uid, strlen(uid));
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tGenIdPI32(void) {
|
||||
if (tUUIDHashId == 0) {
|
||||
char uid[65] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, sizeof(uid));
|
||||
uid[64] = 0;
|
||||
|
||||
int32_t code = taosGetSystemUUID32(&tUUIDHashId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
tUUIDHashId = MurmurHash3_32(uid, strlen(uid));
|
||||
terrno = code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,12 +64,9 @@ int32_t tGenIdPI32(void) {
|
|||
|
||||
int64_t tGenIdPI64(void) {
|
||||
if (tUUIDHashId == 0) {
|
||||
char uid[65] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, 64);
|
||||
int32_t code = taosGetSystemUUID32(&tUUIDHashId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
tUUIDHashId = MurmurHash3_32(uid, strlen(uid));
|
||||
terrno = code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +77,7 @@ int64_t tGenIdPI64(void) {
|
|||
uint64_t pid = taosGetPId();
|
||||
int32_t val = atomic_add_fetch_32(&tUUIDSerialNo, 1);
|
||||
|
||||
id = ((tUUIDHashId & 0x07FF) << 52) | ((pid & 0x0F) << 48) | ((ts & 0x3FFFFFF) << 20) | (val & 0xFFFFF);
|
||||
id = (((uint64_t)(tUUIDHashId & 0x07FF)) << 52) | ((pid & 0x0F) << 48) | ((ts & 0x3FFFFFF) << 20) | (val & 0xFFFFF);
|
||||
if (id) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue