• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #5034

24 Apr 2026 11:25AM UTC coverage: 73.058%. Remained the same
#5034

push

travis-ci

web-flow
merge: from main to 3.0 branch #35224

merge: from main to 3.0 branch[manual-only]

1336 of 1975 new or added lines in 48 files covered. (67.65%)

14149 existing lines in 164 files now uncovered.

275896 of 377640 relevant lines covered (73.06%)

132944440.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.67
/source/util/src/tuuid.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "tuuid.h"
17

18
static uint32_t tUUIDHashId = 0;
19
static int32_t tUUIDSerialNo = 0;
20

21
int32_t taosGetSystemUUIDU32(uint32_t *uuid) {
3,778,653✔
22
  if (uuid == NULL) return TSDB_CODE_APP_ERROR;
3,778,653✔
23
  char    uid[37] = {0};
3,778,653✔
24
  int32_t code = taosGetSystemUUIDLimit36(uid, sizeof(uid));
3,778,653✔
25
  uid[36] = 0;
3,779,406✔
26

27
  if (code != TSDB_CODE_SUCCESS) {
3,779,406✔
28
    return code;
×
29
  } else {
30
    *uuid = MurmurHash3_32(uid, strlen(uid));
3,779,406✔
31
  }
32
  return TSDB_CODE_SUCCESS;
3,777,602✔
33
}
34

35
int32_t taosGetSystemUUIDU64(uint64_t *uuid) {
250,869,390✔
36
  if (uuid == NULL) return TSDB_CODE_APP_ERROR;
250,869,390✔
37
  char    uid[37] = {0};
250,869,390✔
38
  int32_t code = taosGetSystemUUIDLimit36(uid, sizeof(uid));
250,975,209✔
39
  uid[36] = 0;
250,311,528✔
40

41
  if (code != TSDB_CODE_SUCCESS) {
250,311,528✔
42
    return code;
×
43
  } else {
44
    *uuid = MurmurHash3_64(uid, strlen(uid));
250,311,528✔
45
  }
46
  return TSDB_CODE_SUCCESS;
250,409,893✔
47
}
48

49
int32_t tGenIdPI32(void) {
72,552✔
50
  if (tUUIDHashId == 0) {
72,552✔
51
    int32_t code = taosGetSystemUUIDU32(&tUUIDHashId);
×
52
    if (code != TSDB_CODE_SUCCESS) {
×
53
      terrno = code;
×
54
    }
55
  }
56

57
  int64_t  ts = taosGetTimestampMs();
72,552✔
58
  uint64_t pid = taosGetPId();
72,552✔
59
  int32_t  val = atomic_add_fetch_32(&tUUIDSerialNo, 1);
72,552✔
60

61
  int32_t id = ((tUUIDHashId & 0x1F) << 26) | ((pid & 0x3F) << 20) | ((ts & 0xFFF) << 8) | (val & 0xFF);
72,552✔
62
  return id;
72,552✔
63
}
64

65
int64_t tGenIdPI64(void) {
2,147,483,647✔
66
  if (tUUIDHashId == 0) {
2,147,483,647✔
67
    int32_t code = taosGetSystemUUIDU32(&tUUIDHashId);
2,225,628✔
68
    if (code != TSDB_CODE_SUCCESS) {
2,224,577✔
UNCOV
69
      terrno = code;
×
70
    }
71
  }
72

73
  int64_t id;
74

75
  while (true) {
×
76
    int64_t  ts = taosGetTimestampMs() >> 8;
2,147,483,647✔
77
    uint64_t pid = taosGetPId();
2,147,483,647✔
78
    int32_t  val = atomic_add_fetch_32(&tUUIDSerialNo, 1);
2,147,483,647✔
79

80
    id = (((uint64_t)(tUUIDHashId & 0x07FF)) << 52) | ((pid & 0x0F) << 48) | ((ts & 0x3FFFFFF) << 20) | (val & 0xFFFFF);
2,147,483,647✔
81
    if (id) {
2,147,483,647✔
82
      break;
2,147,483,647✔
83
    }
84
  }
85

86
  return id;
2,147,483,647✔
87
}
88

89
int64_t tGenQid64(int8_t dnodeId) {
1,910✔
90
  int64_t id = dnodeId;
1,910✔
91

92
  while (true) {
×
93
    int32_t val = atomic_add_fetch_32(&tUUIDSerialNo, 1);
1,910✔
94

95
    id = (id << 56) | (val & 0xFFFFF) << 8;
1,910✔
96
    if (id) {
1,910✔
97
      break;
1,910✔
98
    }
99
  }
100

101
  return id;
1,910✔
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc