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

taosdata / TDengine / #3632

08 Mar 2025 06:17AM UTC coverage: 60.719% (+0.05%) from 60.671%
#3632

push

travis-ci

web-flow
Merge pull request #29999 from taosdata/enh/TS-5089

feat: taosBenchmark supports exporting to CSV files

141890 of 300701 branches covered (47.19%)

Branch coverage included in aggregate %.

599 of 766 new or added lines in 3 files covered. (78.2%)

1025 existing lines in 124 files now uncovered.

223757 of 301490 relevant lines covered (74.22%)

17284906.68 hits per line

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

68.57
/source/dnode/vnode/src/meta/metaEntry.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 "meta.h"
17

18
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
364,778✔
19
  const SColCmprWrapper *pw = &pME->colCmpr;
364,778✔
20
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
729,556!
21
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
729,556!
22
  uDebug("encode cols:%d", pw->nCols);
364,778✔
23

24
  for (int32_t i = 0; i < pw->nCols; i++) {
5,754,050✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,389,338✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,778,676!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,778,676!
28
  }
29
  return 0;
364,712✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,480,079✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,480,079✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
42,850,044!
34
  if (pWrapper->nCols == 0) {
21,369,965!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
42,719,991!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
21,350,026✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,350,121✔
41
  if (pWrapper->pColCmpr == NULL) {
21,515,159!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
443,614,340✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
423,705,986✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
843,208,502!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
841,601,697!
49
  }
50
  return 0;
19,908,354✔
51
}
52
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
53
                                                            SSchemaWrapper *pSchema) {
54
  pCmpr->nCols = pSchema->nCols;
×
55
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
22!
56
    return terrno;
×
57
  }
58

59
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
195!
60
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
173✔
61
    SSchema  *pColSchema = &pSchema->pSchema[i];
173✔
62
    pColCmpr->id = pColSchema->colId;
173✔
63
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
173✔
64
  }
65
  return 0;
22✔
66
}
67

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
169,891✔
69
  if (pSrc->nCols > 0) {
169,891✔
70
    pDst->nCols = pSrc->nCols;
159,953✔
71
    pDst->version = pSrc->version;
159,953✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
159,953!
73
    if (NULL == pDst->pColCmpr) {
160,031!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
160,031✔
77
  }
78
  return 0;
169,969✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
169,941✔
82
  if (pCmpr) {
169,941!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
169,945!
84
  }
85
}
169,972✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
372,633✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
372,633✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
746,442!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
746,442!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
746,442!
92

93
  if (pME->type > 0) {
373,221✔
94
    if (pME->name == NULL) {
364,973!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
729,946!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
364,973✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
143,272!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
143,272!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
143,272!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
71,636✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
293,337✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
529,820!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
529,820!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
529,820!
111
      if (pME->ctbEntry.commentLen > 0) {
264,910✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
84!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
529,820!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
264,910!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
28,427✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
56,624!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
56,624!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
56,624!
120
      if (pME->ntbEntry.commentLen > 0) {
28,312✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
124!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
56,624!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
56,624!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
115✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
52!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
63!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
364,906!
132
  }
133

134
  tEndEncode(pCoder);
373,004✔
135
  return 0;
372,943✔
136
}
137

138
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
30,891,256✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
30,891,256!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
61,578,553!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
60,953,154!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
60,654,349!
143

144
  if (headerOnly) {
30,315,035✔
145
    tEndDecode(pCoder);
11,890✔
146
    return 0;
11,890✔
147
  }
148

149
  if (pME->type > 0) {
30,303,145!
150
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
61,255,685!
151

152
    if (pME->type == TSDB_SUPER_TABLE) {
30,870,761✔
153
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
38,451,087!
154
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
37,880,627!
155
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
38,963,424!
156
      if (TABLE_IS_ROLLUP(pME->flags)) {
20,239,704✔
157
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
260!
158
      }
159
    } else if (pME->type == TSDB_CHILD_TABLE) {
11,576,581✔
160
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
18,818,520!
161
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
18,752,586!
162
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
18,749,938!
163
      if (pME->ctbEntry.commentLen > 0) {
9,385,983✔
164
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
174!
165
      }
166
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
18,761,767!
167
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
9,375,784!
168
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,146,692!
169
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,398,623!
170
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,394,917!
171
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,395,101!
172
      if (pME->ntbEntry.commentLen > 0) {
2,198,062✔
173
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
266!
174
      }
175
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,395,862!
176
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,339,792!
177
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
178
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
2✔
179
      if (!pME->smaEntry.tsma) {
2!
180
        return terrno;
×
181
      }
182
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
2!
183
    } else {
184
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
185
      return TSDB_CODE_INVALID_PARA;
×
186
    }
187
    if (pME->type == TSDB_SUPER_TABLE) {
30,911,565✔
188
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,284,560!
189
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,291,396!
190

191
        if (pME->colCmpr.nCols == 0) {
19,170,210!
192
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
193
        }
194
      } else {
UNCOV
195
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
196
        TABLE_SET_COL_COMPRESSED(pME->flags);
22✔
197
      }
198
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,627,005✔
199
      if (!tDecodeIsEnd(pCoder)) {
2,201,693!
200
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,201,787✔
201
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,201,794✔
202
        if (pME->colCmpr.nCols == 0) {
2,198,449!
203
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
204
        }
205
      } else {
206
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
207
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
208
      }
209
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,198,449✔
210
    }
211
  }
212

213
  tEndDecode(pCoder);
30,712,214✔
214
  return 0;
30,633,842✔
215
}
216

217
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
30,871,404✔
218

219
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
317,700✔
220
  if (pSrc == NULL || pDst == NULL) {
317,700!
221
    return TSDB_CODE_INVALID_PARA;
×
222
  }
223

224
  pDst->nCols = pSrc->nCols;
317,735✔
225
  pDst->version = pSrc->version;
317,735✔
226
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
317,735!
227
  if (pDst->pSchema == NULL) {
317,725!
228
    return terrno;
×
229
  }
230
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
317,725✔
231
  return TSDB_CODE_SUCCESS;
317,725✔
232
}
233

234
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
317,732✔
235
  if (pSchema) {
317,732!
236
    taosMemoryFreeClear(pSchema->pSchema);
317,752!
237
  }
238
}
317,762✔
239

240
void metaCloneEntryFree(SMetaEntry **ppEntry) {
169,931✔
241
  if (ppEntry == NULL || *ppEntry == NULL) {
169,931!
242
    return;
×
243
  }
244

245
  taosMemoryFreeClear((*ppEntry)->name);
169,942!
246

247
  if ((*ppEntry)->type < 0) {
169,960!
248
    taosMemoryFreeClear(*ppEntry);
×
249
    return;
×
250
  }
251

252
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
169,960✔
253
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
157,834✔
254
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
157,839✔
255
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
12,126✔
256
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
9,954!
257
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
9,954!
258
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,172✔
259
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,165✔
260
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,165!
261
  } else {
262
    return;
7✔
263
  }
264
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
169,972✔
265

266
  taosMemoryFreeClear(*ppEntry);
169,968!
267
  return;
169,979✔
268
}
269

270
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
169,860✔
271
  int32_t code = TSDB_CODE_SUCCESS;
169,860✔
272

273
  if (NULL == pEntry || NULL == ppEntry) {
169,860!
274
    return TSDB_CODE_INVALID_PARA;
×
275
  }
276

277
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
169,886!
278
  if (NULL == *ppEntry) {
169,976!
279
    return terrno;
×
280
  }
281

282
  (*ppEntry)->version = pEntry->version;
169,976✔
283
  (*ppEntry)->type = pEntry->type;
169,976✔
284
  (*ppEntry)->uid = pEntry->uid;
169,976✔
285

286
  if (pEntry->type < 0) {
169,976!
287
    return TSDB_CODE_SUCCESS;
×
288
  }
289

290
  if (pEntry->name) {
169,976!
291
    (*ppEntry)->name = tstrdup(pEntry->name);
169,984✔
292
    if (NULL == (*ppEntry)->name) {
169,949!
293
      code = terrno;
×
294
      metaCloneEntryFree(ppEntry);
×
295
      return code;
×
296
    }
297
  }
298

299
  if (pEntry->type == TSDB_SUPER_TABLE) {
169,953✔
300
    (*ppEntry)->flags = pEntry->flags;
157,839✔
301

302
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
157,839✔
303
    if (code) {
157,791!
304
      metaCloneEntryFree(ppEntry);
×
305
      return code;
×
306
    }
307

308
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
157,791✔
309
    if (code) {
157,798!
310
      metaCloneEntryFree(ppEntry);
×
311
      return code;
×
312
    }
313
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
12,114✔
314
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
9,948✔
315
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
9,948✔
316
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
9,948✔
317

318
    // comment
319
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
9,948✔
320
    if (pEntry->ctbEntry.commentLen > 0) {
9,948✔
321
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
24!
322
      if (NULL == (*ppEntry)->ctbEntry.comment) {
24!
323
        code = terrno;
×
324
        metaCloneEntryFree(ppEntry);
×
325
        return code;
×
326
      }
327
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
24✔
328
    }
329

330
    // tags
331
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
9,948✔
332
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
9,948!
333
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
9,955!
334
      code = terrno;
×
335
      metaCloneEntryFree(ppEntry);
×
336
      return code;
×
337
    }
338
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
9,955✔
339
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
2,166✔
340
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,165✔
341
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,165✔
342
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,165✔
343

344
    // schema
345
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
2,165✔
346
    if (code) {
2,165!
347
      metaCloneEntryFree(ppEntry);
×
348
      return code;
×
349
    }
350

351
    // comment
352
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,165✔
353
    if (pEntry->ntbEntry.commentLen > 0) {
2,165✔
354
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
38!
355
      if (NULL == (*ppEntry)->ntbEntry.comment) {
38!
356
        code = terrno;
×
357
        metaCloneEntryFree(ppEntry);
×
358
        return code;
×
359
      }
360
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
38✔
361
    }
362
  } else {
363
    return TSDB_CODE_INVALID_PARA;
1✔
364
  }
365

366
  code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
169,918✔
367
  if (code) {
169,975✔
368
    metaCloneEntryFree(ppEntry);
15✔
369
    return code;
×
370
  }
371

372
  return code;
169,960✔
373
}
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