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

taosdata / TDengine / #3528

13 Nov 2024 02:14AM UTC coverage: 60.905% (+0.09%) from 60.819%
#3528

push

travis-ci

web-flow
Merge pull request #28748 from taosdata/test/chr-3.0-TD14758

test:add docs ci in jenkinsfile2

118800 of 249004 branches covered (47.71%)

Branch coverage included in aggregate %.

199361 of 273386 relevant lines covered (72.92%)

14738389.65 hits per line

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

55.56
/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 "tmisce.h"
18
#include "tdatablock.h"
19
#include "tglobal.h"
20
#include "tjson.h"
21

22
int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) {
40,469✔
23
  pEp->port = 0;
40,469✔
24
  memset(pEp->fqdn, 0, TSDB_FQDN_LEN);
40,469✔
25
  strncpy(pEp->fqdn, ep, TSDB_FQDN_LEN - 1);
40,469✔
26

27
  char* temp = strchr(pEp->fqdn, ':');
40,469✔
28
  if (temp) {
40,469✔
29
    *temp = 0;
32,170✔
30
    pEp->port = atoi(temp + 1);
32,170✔
31
  }
32

33
  if (pEp->port == 0) {
40,469✔
34
    pEp->port = tsServerPort;
8,304✔
35
  }
36

37
  if (pEp->port <= 0) {
40,469!
38
    return TSDB_CODE_INVALID_PARA;
×
39
  }
40

41
  return 0;
40,469✔
42
}
43

44
int32_t addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port) {
1,098,109✔
45
  if (pEpSet == NULL || fqdn == NULL || strlen(fqdn) == 0) {
1,098,109!
46
    return TSDB_CODE_INVALID_PARA;
×
47
  }
48

49
  int32_t index = pEpSet->numOfEps;
1,098,131✔
50
  if (index >= sizeof(pEpSet->eps) / sizeof(pEpSet->eps[0])) {
1,098,131!
51
    return TSDB_CODE_OUT_OF_RANGE;
×
52
  }
53
  tstrncpy(pEpSet->eps[index].fqdn, fqdn, tListLen(pEpSet->eps[index].fqdn));
1,098,131✔
54
  pEpSet->eps[index].port = port;
1,098,131✔
55
  pEpSet->numOfEps += 1;
1,098,131✔
56
  return 0;
1,098,131✔
57
}
58

59
bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2) {
48,051✔
60
  if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) {
48,051✔
61
    return false;
2,578✔
62
  }
63

64
  for (int32_t i = 0; i < s1->numOfEps; i++) {
94,784✔
65
    if (s1->eps[i].port != s2->eps[i].port || strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0)
49,533✔
66
      return false;
222✔
67
  }
68
  return true;
45,251✔
69
}
70

71
void epsetAssign(SEpSet* pDst, const SEpSet* pSrc) {
60,326✔
72
  if (pSrc == NULL || pDst == NULL) {
60,326!
73
    return;
×
74
  }
75

76
  pDst->inUse = pSrc->inUse;
60,326✔
77
  pDst->numOfEps = pSrc->numOfEps;
60,326✔
78
  for (int32_t i = 0; i < pSrc->numOfEps; ++i) {
121,974✔
79
    pDst->eps[i].port = pSrc->eps[i].port;
61,648✔
80
    tstrncpy(pDst->eps[i].fqdn, pSrc->eps[i].fqdn, tListLen(pSrc->eps[i].fqdn));
61,648✔
81
  }
82
}
83

84
void epAssign(SEp* pDst, SEp* pSrc) {
187,085✔
85
  if (pSrc == NULL || pDst == NULL) {
187,085!
86
    return;
×
87
  }
88
  memset(pDst->fqdn, 0, tListLen(pSrc->fqdn));
187,085✔
89
  tstrncpy(pDst->fqdn, pSrc->fqdn, tListLen(pSrc->fqdn));
187,085✔
90
  pDst->port = pSrc->port;
187,085✔
91
}
92

93
void epsetSort(SEpSet* pDst) {
1,077,751✔
94
  if (pDst->numOfEps <= 1) {
1,077,751✔
95
    return;
978,355✔
96
  }
97
  int validIdx = false;
99,396✔
98
  SEp ep = {0};
99,396✔
99
  if (pDst->inUse >= 0 && pDst->inUse < pDst->numOfEps) {
99,396!
100
    validIdx = true;
99,398✔
101
    epAssign(&ep, &pDst->eps[pDst->inUse]);
99,398✔
102
  }
103

104
  for (int i = 0; i < pDst->numOfEps - 1; i++) {
266,374✔
105
    for (int j = 0; j < pDst->numOfEps - 1 - i; j++) {
407,651✔
106
      SEp* f = &pDst->eps[j];
240,675✔
107
      SEp* s = &pDst->eps[j + 1];
240,675✔
108
      int  cmp = strncmp(f->fqdn, s->fqdn, sizeof(f->fqdn));
240,675✔
109
      if (cmp > 0 || (cmp == 0 && f->port > s->port)) {
240,675!
110
        SEp ep1 = {0};
29,229✔
111
        epAssign(&ep1, f);
29,229✔
112
        epAssign(f, s);
29,229✔
113
        epAssign(s, &ep1);
29,229✔
114
      }
115
    }
116
  }
117
  if (validIdx == true)
99,398!
118
    for (int i = 0; i < pDst->numOfEps; i++) {
145,653!
119
      int cmp = strncmp(ep.fqdn, pDst->eps[i].fqdn, sizeof(ep.fqdn));
145,653✔
120
      if (cmp == 0 && ep.port == pDst->eps[i].port) {
145,653!
121
        pDst->inUse = i;
99,398✔
122
        break;
99,398✔
123
      }
124
    }
125
}
126

127
void updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet) {
2,659✔
128
  taosCorBeginWrite(&pEpSet->version);
2,660!
129
  pEpSet->epSet = *pNewEpSet;
2,659✔
130
  taosCorEndWrite(&pEpSet->version);
2,659✔
131
}
2,659✔
132

133
SEpSet getEpSet_s(SCorEpSet* pEpSet) {
8,274,725✔
134
  SEpSet ep = {0};
8,274,725✔
135
  taosCorBeginRead(&pEpSet->version);
8,274,713!
136
  ep = pEpSet->epSet;
8,274,900✔
137
  taosCorEndRead(&pEpSet->version);
8,274,900!
138

139
  return ep;
8,274,895✔
140
}
141

142
int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) {
383,982✔
143
  int32_t ret = 0;
383,982✔
144
  int32_t nwrite = 0;
383,982✔
145

146
  nwrite = snprintf(pBuf + nwrite, cap, "epset:{");
383,982✔
147
  if (nwrite <= 0 || nwrite >= cap) {
383,982!
148
    return TSDB_CODE_OUT_OF_BUFFER;
×
149
  }
150
  cap -= nwrite;
383,982✔
151

152
  for (int _i = 0; (_i < pEpSet->numOfEps) && (cap > 0); _i++) {
925,036✔
153
    if (_i == pEpSet->numOfEps - 1) {
541,053✔
154
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
383,960✔
155
    } else {
156
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d, ", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
157,093✔
157
    }
158

159
    if (ret <= 0 || ret >= cap) {
541,053!
160
      return TSDB_CODE_OUT_OF_BUFFER;
×
161
    }
162

163
    nwrite += ret;
541,054✔
164
    cap -= ret;
541,054✔
165
  }
166

167
  if (cap <= 0) {
383,983!
168
    return TSDB_CODE_OUT_OF_BUFFER;
×
169
  }
170

171
  ret = snprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse);
383,983✔
172
  if (ret <= 0 || ret >= cap) {
383,983!
173
    return TSDB_CODE_OUT_OF_BUFFER;
×
174
  } else {
175
    return TSDB_CODE_SUCCESS;
383,983✔
176
  }
177
}
178

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

184
  char tmp[4096] = {0};
×
185

186
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "reportVersion", 1), NULL, _exit);
×
187

188
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "clusterId", clusterId), NULL, _exit);
×
189
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "startTime", startTime), NULL, _exit);
×
190

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

196
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "pid", taosGetPId()), NULL, _exit);
×
197

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

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

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

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

224
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), NULL, _exit);
×
225
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), NULL, _exit);
×
226
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), NULL, _exit);
×
227

228
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashSig", signum), NULL, _exit);
×
229
  TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs()), NULL, _exit);
×
230

231
#ifdef _TD_DARWIN_64
232
  taosLogTraceToBuf(tmp, sizeof(tmp), 4);
233
#elif !defined(WINDOWS)
234
  taosLogTraceToBuf(tmp, sizeof(tmp), 3);
×
235
#else
236
  taosLogTraceToBuf(tmp, sizeof(tmp), 8);
237
#endif
238

239
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "stackInfo", tmp), NULL, _exit);
×
240

241
  char* pCont = tjsonToString(pJson);
×
242
  if (pCont == NULL) {
×
243
    code = terrno;
×
244
    TAOS_CHECK_GOTO(code, NULL, _exit);
×
245
    goto _exit;
×
246
  }
247

248
  tjsonDelete(pJson);
×
249
  *pMsg = pCont;
×
250
  pJson = NULL;
×
251
_exit:
×
252
  tjsonDelete(pJson);
×
253
  TAOS_RETURN(code);
×
254
}
255

256
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
541✔
257
  int32_t  code = 0;
541✔
258
  SConfig* pConf = taosGetCfg();
541✔
259
  if (pConf == NULL) {
541!
260
    return TSDB_CODE_INVALID_CFG;
×
261
  }
262

263
  int32_t      numOfRows = 0;
541✔
264
  int32_t      col = startCol;
541✔
265
  SConfigItem* pItem = NULL;
541✔
266
  SConfigIter* pIter = NULL;
541✔
267

268
  int8_t locked = 0;
541✔
269

270
  TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf)), NULL, _exit);
541!
271

272
  TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit);
541!
273

274
  cfgLock(pConf);
541✔
275
  locked = 1;
541✔
276

277
  while ((pItem = cfgNextIter(pIter)) != NULL) {
56,369✔
278
    col = startCol;
55,828✔
279

280
    // GRANT_CFG_SKIP;
281
    char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
55,828✔
282
    STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
55,828✔
283

284
    SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
55,828✔
285
    if (pColInfo == NULL) {
55,828!
286
      code = terrno;
×
287
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
288
    }
289

290
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, name, false), NULL, _exit);
55,828!
291

292
    char    value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
55,828✔
293
    int32_t valueLen = 0;
55,828✔
294
    TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen), NULL, _exit);
55,828!
295
    varDataSetLen(value, valueLen);
55,828✔
296

297
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
55,828✔
298
    if (pColInfo == NULL) {
55,828!
299
      code = terrno;
×
300
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
301
    }
302

303
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, value, false), NULL, _exit);
55,828!
304

305
    char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0};
55,828✔
306
    TAOS_CHECK_GOTO(cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen), NULL, _exit);
55,828!
307
    varDataSetLen(scope, valueLen);
55,828✔
308

309
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
55,828✔
310
    if (pColInfo == NULL) {
55,828!
311
      code = terrno;
×
312
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
313
    }
314
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, scope, false), NULL, _exit);
55,828!
315

316
    numOfRows++;
55,828✔
317
  }
318
  pBlock->info.rows = numOfRows;
541✔
319
_exit:
541✔
320
  if (locked) cfgUnLock(pConf);
541!
321
  cfgDestroyIter(pIter);
541✔
322
  TAOS_RETURN(code);
541✔
323
}
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