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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

53.38
/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
#include "tcompare.h"
22

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

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

37
  if (pEp->port == 0) {
52✔
38
    pEp->port = tsServerPort;
36✔
39
  }
40

41
  if (pEp->port <= 0) {
52!
42
    return TSDB_CODE_INVALID_PARA;
×
43
  }
44

45
  return 0;
52✔
46
}
47

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

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

63
bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2) {
46✔
64
  if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) {
46!
UNCOV
65
    return false;
×
66
  }
67

68
  for (int32_t i = 0; i < s1->numOfEps; i++) {
81✔
69
    if (s1->eps[i].port != s2->eps[i].port || strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0)
46!
70
      return false;
11✔
71
  }
72
  return true;
35✔
73
}
74

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

80
  pDst->inUse = pSrc->inUse;
1✔
81
  pDst->numOfEps = pSrc->numOfEps;
1✔
82
  for (int32_t i = 0; i < pSrc->numOfEps; ++i) {
1!
UNCOV
83
    pDst->eps[i].port = pSrc->eps[i].port;
×
UNCOV
84
    tstrncpy(pDst->eps[i].fqdn, pSrc->eps[i].fqdn, tListLen(pSrc->eps[i].fqdn));
×
85
  }
86
}
87

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

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

108
  for (int i = 0; i < pDst->numOfEps - 1; i++) {
8✔
109
    for (int j = 0; j < pDst->numOfEps - 1 - i; j++) {
18✔
110
      SEp* f = &pDst->eps[j];
12✔
111
      SEp* s = &pDst->eps[j + 1];
12✔
112
      int  cmp = strncmp(f->fqdn, s->fqdn, sizeof(f->fqdn));
12✔
113
      if (cmp > 0 || (cmp == 0 && f->port > s->port)) {
12!
114
        SEp ep1 = {0};
11✔
115
        epAssign(&ep1, f);
11✔
116
        epAssign(f, s);
11✔
117
        epAssign(s, &ep1);
11✔
118
      }
119
    }
120
  }
121
  if (validIdx == true)
2!
122
    for (int i = 0; i < pDst->numOfEps; i++) {
8!
123
      int cmp = strncmp(ep.fqdn, pDst->eps[i].fqdn, sizeof(ep.fqdn));
8✔
124
      if (cmp == 0 && ep.port == pDst->eps[i].port) {
8✔
125
        pDst->inUse = i;
2✔
126
        break;
2✔
127
      }
128
    }
129
}
130

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

137
SEpSet getEpSet_s(SCorEpSet* pEpSet) {
834✔
138
  SEpSet ep = {0};
834✔
139
  taosCorBeginRead(&pEpSet->version);
834!
140
  ep = pEpSet->epSet;
834✔
141
  taosCorEndRead(&pEpSet->version);
834!
142

143
  return ep;
834✔
144
}
145

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

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

156
  for (int _i = 0; (_i < pEpSet->numOfEps) && (cap > 0); _i++) {
4!
157
    if (_i == pEpSet->numOfEps - 1) {
2!
158
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
2✔
159
    } else {
UNCOV
160
      ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d, ", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
×
161
    }
162

163
    if (ret <= 0 || ret >= cap) {
2!
UNCOV
164
      return TSDB_CODE_OUT_OF_BUFFER;
×
165
    }
166

167
    nwrite += ret;
2✔
168
    cap -= ret;
2✔
169
  }
170

171
  if (cap <= 0) {
2!
172
    return TSDB_CODE_OUT_OF_BUFFER;
×
173
  }
174

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

268
  int32_t      numOfRows = 0;
9✔
269
  int32_t      col = startCol;
9✔
270
  SConfigItem* pItem = NULL;
9✔
271
  SConfigIter* pIter = NULL;
9✔
272

273
  int8_t locked = 0;
9✔
274

275
  size_t       exSize = 0;
9✔
276
  size_t       index = 0;
9✔
277
  SConfigItem* pDataDirItem = cfgGetItem(pConf, "dataDir");
9✔
278
  if (pDataDirItem) {
9!
UNCOV
279
    exSize = TMAX(taosArrayGetSize(pDataDirItem->array), 1) - 1;
×
280
  }
281

282
  TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf) + exSize), NULL, _exit);
9!
283

284
  TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit);
9!
285

286
  cfgLock(pConf);
9✔
287
  locked = 1;
9✔
288

289
  while ((pItem = cfgNextIter(pIter)) != NULL) {
792✔
290
  _start:
783✔
291
    col = startCol;
783✔
292

293
    // GRANT_CFG_SKIP;
294
    char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
783✔
295
    if (likePattern && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
783!
296
      continue;
×
297
    }
298
    STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
783✔
299

300
    SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
783✔
301
    if (pColInfo == NULL) {
783!
302
      code = terrno;
×
303
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
304
    }
305

306
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, name, false), NULL, _exit);
783!
307

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

322
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
783✔
323
    if (pColInfo == NULL) {
783!
324
      code = terrno;
×
325
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
326
    }
327

328
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, value, false), NULL, _exit);
783!
329

330
    char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0};
783✔
331
    TAOS_CHECK_GOTO(cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen), NULL, _exit);
783!
332
    varDataSetLen(scope, valueLen);
783✔
333

334
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
783✔
335
    if (pColInfo == NULL) {
783!
336
      code = terrno;
×
337
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
338
    }
339
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, scope, false), NULL, _exit);
783!
340

341
    char category[TSDB_CONFIG_CATEGORY_LEN + VARSTR_HEADER_SIZE] = {0};
783✔
342
    TAOS_CHECK_GOTO(cfgDumpItemCategory(pItem, &category[VARSTR_HEADER_SIZE], TSDB_CONFIG_CATEGORY_LEN, &valueLen),
783!
343
                    NULL, _exit);
344
    varDataSetLen(category, valueLen);
783✔
345

346
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
783✔
347
    if (pColInfo == NULL) {
783!
348
      code = terrno;
×
349
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
350
    }
351
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, category, false), NULL, _exit);
783!
352

353
    char info[TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE] = {0};
783✔
354
    if (strcasecmp(pItem->name, "dataDir") == 0 && pDiskCfg) {
783!
355
      char* buf = &info[VARSTR_HEADER_SIZE];
×
356
      valueLen = tsnprintf(buf, TSDB_CONFIG_INFO_LEN, "level %d primary %d disabled %" PRIi8, pDiskCfg->level,
×
357
                           pDiskCfg->primary, pDiskCfg->disable);
×
358
    } else {
359
      valueLen = 0;
783✔
360
    }
361
    varDataSetLen(info, valueLen);
783✔
362

363
    pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
783✔
364
    if (pColInfo == NULL) {
783!
365
      code = terrno;
×
366
      TAOS_CHECK_GOTO(code, NULL, _exit);
×
367
    }
368
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, info, false), NULL, _exit);
783!
369

370
    numOfRows++;
783✔
371
    if (index > 0 && index <= exSize) {
783!
372
      goto _start;
×
373
    }
374
  }
375
  pBlock->info.rows = numOfRows;
9✔
376
_exit:
9✔
377
  if (locked) cfgUnLock(pConf);
9!
378
  cfgDestroyIter(pIter);
9✔
379
  TAOS_RETURN(code);
9✔
380
}
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