未验证 提交 add82007 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #16672 from taosdata/fix/genRequestId

fix(query): avoid gen-requestId serial number overflow
......@@ -488,7 +488,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
*/
uint64_t generateRequestId() {
static uint64_t hashId = 0;
static int32_t requestSerialId = 0;
static uint32_t requestSerialId = 0;
if (hashId == 0) {
char uid[64] = {0};
......@@ -507,7 +507,8 @@ uint64_t generateRequestId() {
while (true) {
int64_t ts = taosGetTimestampMs();
uint64_t pid = taosGetPId();
int32_t val = atomic_add_fetch_32(&requestSerialId, 1);
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);
if (id) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册