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

taosdata / TDengine / #3620

21 Feb 2025 09:00AM UTC coverage: 63.573% (+0.2%) from 63.423%
#3620

push

travis-ci

web-flow
ci: taosBenchmark add coverage cases branch 3.0 (#29788)

* fix: add unit test for taos-tools

* fix: only .cpp include

* fix: remove no use function

* fix: restore toolsSys.c

* fix: add toolsSys case

* fix: rebuild error fixed

* fix: fix build error

* fix: support get vgroups with core and memory limit

* fix: build error for strcasecmp

* fix: add insertBasic.py case

* fix: add command line set vgroups=3

* fix: change with ns database

* toolscJson read with int replace float and add insertPrecison.py

* fix: add insertBindVGroup.json case

* fix: remove public fun removeQuotation

* fix: vgroups change method

* fix: memory leak for runInsertLimitThread slot

* insertPrecision.py word write wrong

* fix: check isFloat number

* fix: vgroups change logic error

* fix: insertBasic.py real and expect error

* fix: adjust default vgroups

* fix: adjust default vgroups modify comment

148962 of 300203 branches covered (49.62%)

Branch coverage included in aggregate %.

15 of 16 new or added lines in 1 file covered. (93.75%)

2018 existing lines in 133 files now uncovered.

233201 of 300933 relevant lines covered (77.49%)

18174406.98 hits per line

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

57.45
/source/common/src/tmisce.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
#define _DEFAULT_SOURCE
17
#include "tdatablock.h"
18
#include "tglobal.h"
19
#include "tjson.h"
20
#include "tmisce.h"
21

22
int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) {
46,768✔
23
  pEp->port = 0;
46,768✔
24
  memset(pEp->fqdn, 0, TSDB_FQDN_LEN);
46,768✔
25
  tstrncpy(pEp->fqdn, ep, TSDB_FQDN_LEN);
46,768✔
26

27
  char* temp = strchr(pEp->fqdn, ':');
46,768✔
28
  if (temp) {
46,768✔
29
    *temp = 0;
34,588✔
30
    pEp->port = taosStr2UInt16(temp + 1, NULL, 10);
34,588✔
31
    if (pEp->port < 0) {
32
      return TSDB_CODE_INVALID_PARA;
33
    }
34
  }
35

36
  if (pEp->port == 0) {
46,769✔
37
    pEp->port = tsServerPort;
12,183✔
38
  }
39

40
  if (pEp->port <= 0) {
46,769!
41
    return TSDB_CODE_INVALID_PARA;
×
42
  }
43

44
  return 0;
46,769✔
45
}
46

47
int32_t addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port) {
1,132,829✔
48
  if (pEpSet == NULL || fqdn == NULL || strlen(fqdn) == 0) {
1,132,829!
49
    return TSDB_CODE_INVALID_PARA;
×
50
  }
51

52
  int32_t index = pEpSet->numOfEps;
1,132,867✔
53
  if (index >= sizeof(pEpSet->eps) / sizeof(pEpSet->eps[0])) {
1,132,867!
54
    return TSDB_CODE_OUT_OF_RANGE;
×
55
  }
56
  tstrncpy(pEpSet->eps[index].fqdn, fqdn, tListLen(pEpSet->eps[index].fqdn));
1,132,867✔
57
  pEpSet->eps[index].port = port;
1,132,867✔
58
  pEpSet->numOfEps += 1;
1,132,867✔
59
  return 0;
1,132,867✔
60
}
61

62
bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2) {
110,709✔
63
  if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) {
110,709✔
64
    return false;
1,620✔
65
  }
66

67
  for (int32_t i = 0; i < s1->numOfEps; i++) {
223,988✔
68
    if (s1->eps[i].port != s2->eps[i].port || strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0)
115,044✔
69
      return false;
145✔
70
  }
71
  return true;
108,944✔
72
}
73

74
void epsetAssign(SEpSet* pDst, const SEpSet* pSrc) {
123,849✔
75
  if (pSrc == NULL || pDst == NULL) {
123,849!
76
    return;
10✔
77
  }
78

79
  pDst->inUse = pSrc->inUse;
123,839✔
80
  pDst->numOfEps = pSrc->numOfEps;
123,839✔
81
  for (int32_t i = 0; i < pSrc->numOfEps; ++i) {
249,391✔
82
    pDst->eps[i].port = pSrc->eps[i].port;
125,552✔
83
    tstrncpy(pDst->eps[i].fqdn, pSrc->eps[i].fqdn, tListLen(pSrc->eps[i].fqdn));
125,552✔
84
  }
85
}
86

87
void epAssign(SEp* pDst, SEp* pSrc) {
199,999✔
88
  if (pSrc == NULL || pDst == NULL) {
199,999!
89
    return;
×
90
  }
91
  memset(pDst->fqdn, 0, tListLen(pSrc->fqdn));
199,999✔
92
  tstrncpy(pDst->fqdn, pSrc->fqdn, tListLen(pSrc->fqdn));
199,999✔
93
  pDst->port = pSrc->port;
199,999✔
94
}
95

96
void epsetSort(SEpSet* pDst) {
1,111,691✔
97
  if (pDst->numOfEps <= 1) {
1,111,691✔
98
    return;
1,006,715✔
99
  }
100
  int validIdx = false;
104,976✔
101
  SEp ep = {0};
104,976✔
102
  if (pDst->inUse >= 0 && pDst->inUse < pDst->numOfEps) {
104,976!
103
    validIdx = true;
104,980✔
104
    epAssign(&ep, &pDst->eps[pDst->inUse]);
104,980✔
105
  }
106

107
  for (int i = 0; i < pDst->numOfEps - 1; i++) {
279,785✔
108
    for (int j = 0; j < pDst->numOfEps - 1 - i; j++) {
425,440✔
109
      SEp* f = &pDst->eps[j];
250,635✔
110
      SEp* s = &pDst->eps[j + 1];
250,635✔
111
      int  cmp = strncmp(f->fqdn, s->fqdn, sizeof(f->fqdn));
250,635✔
112
      if (cmp > 0 || (cmp == 0 && f->port > s->port)) {
250,635!
113
        SEp ep1 = {0};
31,672✔
114
        epAssign(&ep1, f);
31,672✔
115
        epAssign(f, s);
31,673✔
116
        epAssign(s, &ep1);
31,673✔
117
      }
118
    }
119
  }
120
  if (validIdx == true)
104,981✔
121
    for (int i = 0; i < pDst->numOfEps; i++) {
144,908!
122
      int cmp = strncmp(ep.fqdn, pDst->eps[i].fqdn, sizeof(ep.fqdn));
144,908✔
123
      if (cmp == 0 && ep.port == pDst->eps[i].port) {
144,908!
124
        pDst->inUse = i;
104,980✔
125
        break;
104,980✔
126
      }
127
    }
128
}
129

130
void updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet) {
1,701✔
131
  taosCorBeginWrite(&pEpSet->version);
1,701!
132
  pEpSet->epSet = *pNewEpSet;
1,701✔
133
  taosCorEndWrite(&pEpSet->version);
1,701✔
134
}
1,701✔
135

136
SEpSet getEpSet_s(SCorEpSet* pEpSet) {
31,741,831✔
137
  SEpSet ep = {0};
31,741,831✔
138
  taosCorBeginRead(&pEpSet->version);
31,734,367!
139
  ep = pEpSet->epSet;
32,213,909✔
140
  taosCorEndRead(&pEpSet->version);
32,213,909!
141

142
  return ep;
32,204,189✔
143
}
144

145
int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) {
411,431✔
146
  int32_t ret = 0;
411,431✔
147
  int32_t nwrite = 0;
411,431✔
148

149
  nwrite = snprintf(pBuf + nwrite, cap, "epset:{");
411,431✔
150
  if (nwrite <= 0 || nwrite >= cap) {
411,431!
151
    return TSDB_CODE_OUT_OF_BUFFER;
×
152
  }
153
  cap -= nwrite;
411,431✔
154

155
  for (int _i = 0; (_i < pEpSet->numOfEps) && (cap > 0); _i++) {
985,466!
156
    if (_i == pEpSet->numOfEps - 1) {
574,034✔
157
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
411,414✔
158
    } else {
159
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d, ", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
162,620✔
160
    }
161

162
    if (ret <= 0 || ret >= cap) {
574,034!
UNCOV
163
      return TSDB_CODE_OUT_OF_BUFFER;
×
164
    }
165

166
    nwrite += ret;
574,035✔
167
    cap -= ret;
574,035✔
168
  }
169

170
  if (cap <= 0) {
411,432!
171
    return TSDB_CODE_OUT_OF_BUFFER;
×
172
  }
173

174
  ret = snprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse);
411,432✔
175
  if (ret <= 0 || ret >= cap) {
411,432!
176
    return TSDB_CODE_OUT_OF_BUFFER;
1✔
177
  } else {
178
    return TSDB_CODE_SUCCESS;
411,431✔
179
  }
180
}
181

182
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime) {
×
183
  int32_t code = 0;
×
184
  SJson*  pJson = tjsonCreateObject();
×
185
  if (pJson == NULL) return terrno;
×
186

187
  char tmp[4096] = {0};
×
188

189
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "reportVersion", 1), NULL, _exit);
×
190

191
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "clusterId", clusterId), NULL, _exit);
×
192
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "startTime", startTime), NULL, _exit);
×
193

194
  // Do NOT invoke the taosGetFqdn here.
195
  // this function may be invoked when memory exception occurs,so we should assume that it is running in a memory locked
196
  // environment. The lock operation by taosGetFqdn may cause this program deadlock.
197
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "fqdn", tsLocalFqdn), NULL, _exit);
×
198

199
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "pid", taosGetPId()), NULL, _exit);
×
200

201
  code = taosGetAppName(tmp, NULL);
×
202
  if (code != 0) {
×
203
    TAOS_CHECK_GOTO(code, NULL, _exit);
×
204
  }
205
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "appName", tmp), NULL, _exit);
×
206

207
  if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) {
×
208
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "os", tmp), NULL, _exit);
×
209
  } else {
210
    // do nothing
211
  }
212

213
  float numOfCores = 0;
×
214
  if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
×
215
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "cpuModel", tmp), NULL, _exit);
×
216
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores), NULL, _exit);
×
217
  } else {
218
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores), NULL, _exit);
×
219
  }
220

221
  int32_t nBytes = snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
×
222
  if (nBytes <= 9 || nBytes >= sizeof(tmp)) {
×
223
    TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_RANGE, NULL, _exit);
×
224
  }
225
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), NULL, _exit);
×
226

227
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), NULL, _exit);
×
228
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), NULL, _exit);
×
229
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), NULL, _exit);
×
230

231
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashSig", signum), NULL, _exit);
×
232
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs()), NULL, _exit);
×
233

234
#if 0
235
#ifdef _TD_DARWIN_64
236
  taosLogTraceToBuf(tmp, sizeof(tmp), 4);
237
#elif !defined(WINDOWS)
238
  taosLogTraceToBuf(tmp, sizeof(tmp), 3);
239
#else
240
  taosLogTraceToBuf(tmp, sizeof(tmp), 8);
241
#endif
242

243
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "stackInfo", tmp), NULL, _exit);
244
#endif
245
  char* pCont = tjsonToString(pJson);
×
246
  if (pCont == NULL) {
×
247
    code = terrno;
×
248
    TAOS_CHECK_GOTO(code, NULL, _exit);
×
249
    goto _exit;
×
250
  }
251

252
  tjsonDelete(pJson);
×
253
  *pMsg = pCont;
×
254
  pJson = NULL;
×
255
_exit:
×
256
  tjsonDelete(pJson);
×
257
  TAOS_RETURN(code);
×
258
}
259

260
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
5,888✔
261
  int32_t  code = 0;
5,888✔
262
  SConfig* pConf = taosGetCfg();
5,888✔
263
  if (pConf == NULL) {
5,888!
264
    return TSDB_CODE_INVALID_CFG;
×
265
  }
266

267
  int32_t      numOfRows = 0;
5,888✔
268
  int32_t      col = startCol;
5,888✔
269
  SConfigItem* pItem = NULL;
5,888✔
270
  SConfigIter* pIter = NULL;
5,888✔
271

272
  int8_t locked = 0;
5,888✔
273

274
  size_t       exSize = 0;
5,888✔
275
  size_t       index = 0;
5,888✔
276
  SConfigItem* pDataDirItem = cfgGetItem(pConf, "dataDir");
5,888✔
277
  if (pDataDirItem) {
5,888✔
278
    exSize = TMAX(taosArrayGetSize(pDataDirItem->array), 1) - 1;
5,288✔
279
  }
280

281
  TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf) + exSize), NULL, _exit);
5,888!
282

283
  TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit);
5,888!
284

285
  cfgLock(pConf);
5,888✔
286
  locked = 1;
5,888✔
287

288
  while ((pItem = cfgNextIter(pIter)) != NULL) {
1,162,080✔
289
  _start:
1,156,192✔
290
    col = startCol;
1,156,192✔
291

292
    // GRANT_CFG_SKIP;
293
    char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
1,156,192✔
294
    STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
1,156,192✔
295

296
    SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
1,156,192✔
297
    if (pColInfo == NULL) {
1,156,192!
298
      code = terrno;
×
299
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
300
    }
301

302
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, name, false), NULL, _exit);
1,156,192!
303

304
    char      value[TSDB_CONFIG_PATH_LEN + VARSTR_HEADER_SIZE] = {0};
1,156,192✔
305
    int32_t   valueLen = 0;
1,156,192✔
306
    SDiskCfg* pDiskCfg = NULL;
1,156,192✔
307
    if (strcasecmp(pItem->name, "dataDir") == 0 && exSize > 0) {
1,156,192!
308
      char* buf = &value[VARSTR_HEADER_SIZE];
×
309
      pDiskCfg = taosArrayGet(pItem->array, index);
×
310
      valueLen = tsnprintf(buf, TSDB_CONFIG_PATH_LEN, "%s", pDiskCfg->dir);
×
311
      index++;
×
312
    } else {
313
      TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_PATH_LEN, &valueLen), NULL,
1,156,192!
314
                      _exit);
315
    }
316
    varDataSetLen(value, valueLen);
1,156,192✔
317

318
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
1,156,192✔
319
    if (pColInfo == NULL) {
1,156,192!
320
      code = terrno;
×
321
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
322
    }
323

324
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, value, false), NULL, _exit);
1,156,192!
325

326
    char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0};
1,156,192✔
327
    TAOS_CHECK_GOTO(cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen), NULL, _exit);
1,156,192!
328
    varDataSetLen(scope, valueLen);
1,156,192✔
329

330
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
1,156,192✔
331
    if (pColInfo == NULL) {
1,156,192!
332
      code = terrno;
×
333
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
334
    }
335
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, scope, false), NULL, _exit);
1,156,192!
336

337
    char category[TSDB_CONFIG_CATEGORY_LEN + VARSTR_HEADER_SIZE] = {0};
1,156,192✔
338
    TAOS_CHECK_GOTO(cfgDumpItemCategory(pItem, &category[VARSTR_HEADER_SIZE], TSDB_CONFIG_CATEGORY_LEN, &valueLen),
1,156,192!
339
                    NULL, _exit);
340
    varDataSetLen(category, valueLen);
1,156,192✔
341

342
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
1,156,192✔
343
    if (pColInfo == NULL) {
1,156,192!
344
      code = terrno;
×
345
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
346
    }
347
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, category, false), NULL, _exit);
1,156,192!
348

349
    char info[TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE] = {0};
1,156,192✔
350
    if (strcasecmp(pItem->name, "dataDir") == 0 && pDiskCfg) {
1,156,192!
351
      char* buf = &info[VARSTR_HEADER_SIZE];
×
352
      valueLen = tsnprintf(buf, TSDB_CONFIG_INFO_LEN, "level %d primary %d disabled %" PRIi8, pDiskCfg->level,
×
353
                           pDiskCfg->primary, pDiskCfg->disable);
×
354
    } else {
355
      valueLen = 0;
1,156,192✔
356
    }
357
    varDataSetLen(info, valueLen);
1,156,192✔
358

359
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
1,156,192✔
360
    if (pColInfo == NULL) {
1,156,192!
361
      code = terrno;
×
362
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
363
    }
364
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, info, false), NULL, _exit);
1,156,192!
365

366
    numOfRows++;
1,156,192✔
367
    if (index > 0 && index <= exSize) {
1,156,192!
368
      goto _start;
×
369
    }
370
  }
371
  pBlock->info.rows = numOfRows;
5,888✔
372
_exit:
5,888✔
373
  if (locked) cfgUnLock(pConf);
5,888!
374
  cfgDestroyIter(pIter);
5,888✔
375
  TAOS_RETURN(code);
5,888✔
376
}
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