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

taosdata / TDengine / #4965

09 Feb 2026 01:16AM UTC coverage: 66.884% (-0.02%) from 66.908%
#4965

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205798 of 307696 relevant lines covered (66.88%)

126382200.96 hits per line

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

81.31
/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
#include "osMemPool.h"
18
#include "osMemory.h"
19
#include "tencode.h"
20
#include "tmsg.h"
21

22
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
1,010,339,362✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
30,862,756✔
26
    }
27
  }
28
  return false;
981,619,690✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
182,449,905✔
32
  if (pME->pExtSchemas) {
182,449,905✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
12,281,626✔
34
    bool                  hasTypeMods = false;
12,281,626✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
12,281,626✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
12,175,079✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
110,432✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
110,432✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,284,093✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,281,412,633✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
182,490,046✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
1,263,408✔
52
  const SColRefWrapper *pw = &pME->colRef;
1,263,408✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
2,526,816✔
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
2,526,816✔
55
  uTrace("encode cols:%d", pw->nCols);
1,263,408✔
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
416,396,334✔
58
    SColRef *p = &pw->pColRef[i];
415,132,926✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
830,265,852✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
830,265,852✔
61
    if (p->hasRef) {
415,132,926✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
550,638,188✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
550,638,188✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
550,638,188✔
65
    }
66
  }
67
  return 0;
1,263,408✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
954,791,623✔
71
  bool hasExtSchema = false;
954,791,623✔
72
  SSchemaWrapper* pSchWrapper = NULL;
954,791,623✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
954,791,623✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
720,416,514✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
234,483,635✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
234,570,927✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
954,957,744✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
954,942,835✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
43,125,901✔
84
    if (pME->pExtSchemas == NULL) {
21,566,772✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
1,554,108,298✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
933,374,432✔
93
  }
94

95
  return 0;
954,895,454✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
43,344,603✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
43,344,603✔
100
  bool                  hasTypeMods = false;
43,344,603✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
43,344,603✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
31,771,829✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,593,970✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,606,440✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
43,376,538✔
109

110
  if (hasTypeMods) {
43,326,120✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,180✔
112
    if (ret != NULL) {
39,180✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,180✔
114
    }
115
    return ret;
39,180✔
116
  }
117
  return NULL;
43,286,940✔
118
}
119

120
int32_t metaGetRsmaSchema(const SMetaEntry *pME, SSchemaRsma **rsmaSchema) {
26,100✔
121
  if (!rsmaSchema) return 0;
26,100✔
122
  if ((pME->type != TSDB_SUPER_TABLE) || !TABLE_IS_ROLLUP(pME->flags)) {  // only support super table
26,100✔
123
    *rsmaSchema = NULL;
×
124
    return 0;
×
125
  }
126

127
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
26,100✔
128
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
26,100✔
129
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
26,100✔
130

131
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
26,100✔
132
  if (*rsmaSchema == NULL) {
26,100✔
133
    return terrno;
×
134
  }
135

136
  (*rsmaSchema)->funcIds = taosMemoryMalloc(sizeof(func_id_t) * nCols);
26,100✔
137
  if ((*rsmaSchema)->funcIds == NULL) {
26,100✔
138
    taosMemoryFree(*rsmaSchema);
×
139
    *rsmaSchema = NULL;
×
140
    return terrno;
×
141
  }
142

143
  (void)snprintf((*rsmaSchema)->tbName, TSDB_TABLE_NAME_LEN, "%s", pME->name);
26,100✔
144
  (*rsmaSchema)->tbUid = pME->uid;
26,100✔
145
  (*rsmaSchema)->tbType = pME->type;
26,100✔
146
  (*rsmaSchema)->interval[0] = pParam->interval[0];
26,100✔
147
  (*rsmaSchema)->interval[1] = pParam->interval[1];
26,100✔
148
  (*rsmaSchema)->nFuncs = nCols;
26,100✔
149

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
26,100✔
151
  int32_t    i = 0, j = 0;
26,100✔
152
  for (i = 0; i < nCols; ++i) {
200,825✔
153
    while (j < pParam->nFuncs) {
317,550✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
305,225✔
155
        pFuncIds[i] = pParam->funcIds[j];
142,825✔
156
        break;
142,825✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
162,400✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,900✔
160
        break;
31,900✔
161
      }
162
      ++j;
130,500✔
163
    }
164
    if (j >= pParam->nFuncs) {
187,050✔
165
      for (; i < nCols; ++i) {
24,650✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,325✔
167
      }
168
      break;
12,325✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
26,100✔
172

173
  return 0;
26,100✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
32,513,764✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
32,513,764✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
65,026,385✔
179
  if (pWrapper->nCols == 0) {
32,511,168✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
65,021,667✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
32,511,063✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
65,024,278✔
186
  if (pWrapper->pColRef == NULL) {
32,514,668✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
746,839,343✔
191
    SColRef *p = &pWrapper->pColRef[i];
714,305,403✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,428,664,598✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,428,707,955✔
194
    if (p->hasRef) {
714,372,647✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
394,967,270✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
394,961,887✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
394,962,530✔
198
    }
199
  }
200
  return 0;
32,519,003✔
201
}
202

203
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
204
                                                            SSchemaWrapper *pSchema) {
205
  pRef->nCols = pSchema->nCols;
×
206
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
207
    return terrno;
×
208
  }
209

210
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
211
    SColRef  *pColRef = &pRef->pColRef[i];
×
212
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
213
    pColRef->id = pColSchema->colId;
×
214
    pColRef->hasRef = false;
×
215
  }
216
  return 0;
×
217
}
218

219
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
650,570✔
220
  if (pSrc->nCols > 0) {
650,570✔
221
    pDst->nCols = pSrc->nCols;
650,570✔
222
    pDst->version = pSrc->version;
650,570✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
650,570✔
224
    if (NULL == pDst->pColRef) {
650,570✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
650,570✔
228
  }
229
  return 0;
650,570✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
39,768,102✔
233
  int32_t code = 0;
39,768,102✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
79,514,882✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
79,513,263✔
236
  uTrace("encode cols:%d", pw->nCols);
39,766,483✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
239
    SColCmpr *p = &pw->pColCmpr[i];
2,119,683,038✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
242
  }
243
  return code;
39,841,552✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
39,569,712✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
39,569,712✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
39,631,421✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
954,807,471✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
954,807,471✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,909,844,819✔
252
  if (pWrapper->nCols == 0) {
954,716,436✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,909,824,961✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
955,111,925✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,910,049,654✔
259
  if (pWrapper->pColCmpr == NULL) {
954,951,322✔
260
    return terrno;
×
261
  }
262

263
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
264
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
265
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
266
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647✔
267
  }
268
  return 0;
955,396,194✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
227,146✔
273

274
  if (pDecoder == NULL) {
227,146✔
275
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
227,146✔
276
  } else {
277
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
278
  }
279

280
  if (pCmpr->pColCmpr == NULL) {
227,146✔
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,142,386✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
915,240✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
915,240✔
287
    pColCmpr->id = pColSchema->colId;
915,240✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
915,240✔
289
  }
290
  return 0;
227,146✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
170,784,955✔
294
  if (pSrc->nCols > 0) {
170,784,955✔
295
    pDst->nCols = pSrc->nCols;
154,363,012✔
296
    pDst->version = pSrc->version;
154,365,904✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
154,363,777✔
298
    if (NULL == pDst->pColCmpr) {
154,339,105✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
154,333,243✔
302
  }
303
  return 0;
170,798,029✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
171,423,847✔
307
  if (pColRef) {
171,423,847✔
308
    taosMemoryFreeClear(pColRef->pColRef);
171,433,923✔
309
  }
310
}
171,439,859✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
171,413,531✔
313
  if (pCmpr) {
171,413,531✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
171,414,429✔
315
  }
316
}
171,408,897✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
186,969,098✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
186,969,098✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
373,995,704✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
373,924,707✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
373,862,868✔
323

324
  if (pME->type > 0) {
186,924,013✔
325
    if (pME->name == NULL) {
182,498,078✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
364,902,916✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
182,432,430✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
50,124,105✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
50,228,516✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
50,190,805✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
25,054,761✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
74,675✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
157,370,705✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
283,945,067✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
283,938,180✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
283,942,987✔
342
      if (pME->ctbEntry.commentLen > 0) {
141,976,574✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
28,188✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
283,957,224✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
141,970,714✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
15,406,944✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
30,813,888✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
30,813,888✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
30,813,888✔
351
      if (pME->ntbEntry.commentLen > 0) {
15,406,944✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
38,988✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
30,813,673✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
30,813,673✔
356
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
357
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
358
    } else {
359
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
360
      return TSDB_CODE_INVALID_PARA;
×
361
    }
362
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
182,459,271✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,347,135✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
181,153,052✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
25,094,967✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
156,119,269✔
368
        if (pME->colCmpr.nCols != 0) {
14,730,654✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
14,503,508✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
227,146✔
372
          SColCmprWrapper colCmprs = {0};
227,146✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
227,146✔
374
          if (code != 0) {
227,146✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
227,146✔
379
          taosMemoryFree(colCmprs.pColCmpr);
227,146✔
380
          TAOS_CHECK_RETURN(code);
227,146✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
182,485,757✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
186,929,450✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
50,149,973✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
50,046,018✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
161,849,178✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
29,461,308✔
391
  }
392

393
  tEndEncode(pCoder);
186,899,519✔
394
  return 0;
186,966,061✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,713,609,035✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,713,609,035✔
399
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
400
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
401
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
402

403
  if (headerOnly) {
1,714,224,539✔
404
    tEndDecode(pCoder);
323,700✔
405
    return 0;
323,700✔
406
  }
407

408
  if (pME->type > 0) {
1,713,900,839✔
409
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
410

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,713,680,129✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,441,179,071✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,441,245,321✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,441,175,963✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
720,529,615✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
277,675✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
992,769,674✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,503,069,344✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,503,135,106✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,503,009,838✔
422
      if (pME->ctbEntry.commentLen > 0) {
751,447,972✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
48,804✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,502,979,758✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
751,578,065✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
241,483,407✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
483,182,451✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
483,303,427✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
483,206,246✔
431
      if (pME->ntbEntry.commentLen > 0) {
241,552,750✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
72,042✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
483,096,517✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
483,169,863✔
436
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
437
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
438
      if (!pME->smaEntry.tsma) {
×
439
        return terrno;
×
440
      }
441
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
442
    } else {
443
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
444
      return TSDB_CODE_INVALID_PARA;
×
445
    }
446
    if (pME->type == TSDB_SUPER_TABLE) {
1,713,479,619✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
720,619,174✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
720,575,965✔
449

450
        if (pME->colCmpr.nCols == 0) {
720,697,656✔
451
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        }
453
      } else {
454
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
455
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
456
      }
457
    } else if (pME->type == TSDB_NORMAL_TABLE) {
992,744,960✔
458
      if (!tDecodeIsEnd(pCoder)) {
234,656,685✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
234,658,606✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
234,658,814✔
461
        if (pME->colCmpr.nCols == 0) {
234,572,244✔
462
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
463
        }
464
      } else {
465
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
557✔
466
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
557✔
467
      }
468
      TABLE_SET_COL_COMPRESSED(pME->flags);
234,596,296✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
758,206,780✔
470
      if (!tDecodeIsEnd(pCoder)) {
32,514,939✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
32,515,195✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
32,515,403✔
473
      } else {
474
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
475
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
476
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
477
        }
478
      }
479
    }
480
    if (!tDecodeIsEnd(pCoder)) {
1,713,680,630✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
955,217,500✔
482
    } else {
483
      pME->pExtSchemas = NULL;
758,463,130✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,713,383,831✔
487
    if (!tDecodeIsEnd(pCoder)) {
720,322,739✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,441,007,112✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
720,427,641✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,440,963,635✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
992,740,970✔
494
    if (!tDecodeIsEnd(pCoder)) {
234,584,308✔
495
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
469,242,801✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,713,484,076✔
501
  return 0;
1,713,093,930✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,713,304,384✔
505

506
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
306,459,425✔
507
  if (pSrc == NULL || pDst == NULL) {
306,459,425✔
508
    return TSDB_CODE_INVALID_PARA;
×
509
  }
510

511
  pDst->nCols = pSrc->nCols;
306,492,109✔
512
  pDst->version = pSrc->version;
306,476,518✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
306,475,276✔
514
  if (pDst->pSchema == NULL) {
306,343,633✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
306,375,144✔
518
  return TSDB_CODE_SUCCESS;
306,492,949✔
519
}
520

521
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
42,775✔
522
  if (pSrc == NULL || pDst == NULL) {
42,775✔
523
    return TSDB_CODE_INVALID_PARA;
×
524
  }
525
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
42,775✔
526
  pDst->name = tstrdup(pSrc->name);
42,775✔
527
  if (pDst->name == NULL) {
42,775✔
528
    return terrno;
×
529
  }
530
  if (pSrc->nFuncs > 0) {
42,775✔
531
    pDst->nFuncs = pSrc->nFuncs;
42,775✔
532
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
42,775✔
533
    if (pDst->funcColIds == NULL) {
42,775✔
534
      return terrno;
×
535
    }
536
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
42,775✔
537

538
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
42,050✔
539
    if (pDst->funcIds == NULL) {
42,775✔
540
      return terrno;
×
541
    }
542
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
42,775✔
543
  } else {
544
    pDst->nFuncs = 0;
×
545
    pDst->funcColIds = NULL;
×
546
    pDst->funcIds = NULL;
×
547
  }
548

549
  return TSDB_CODE_SUCCESS;
42,775✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
306,448,198✔
553
  if (pSchema) {
306,448,198✔
554
    taosMemoryFreeClear(pSchema->pSchema);
306,462,605✔
555
  }
556
}
306,419,938✔
557

558
/**
559
 * @param type 0x01 free name
560
 */
561
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
64,525✔
562
  if (pParam) {
64,525✔
563
    if ((type & 0x01)) {
64,525✔
564
      taosMemoryFreeClear(pParam->name);
64,525✔
565
    }
566
    taosMemoryFreeClear(pParam->funcColIds);
64,525✔
567
    taosMemoryFreeClear(pParam->funcIds);
64,525✔
568
  }
569
}
64,525✔
570

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
171,491,740✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
171,491,740✔
573
    return;
72,969✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
171,433,029✔
577

578
  if ((*ppEntry)->type < 0) {
171,431,996✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
171,370,833✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
151,671,615✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
151,639,218✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
151,648,485✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
64,525✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
19,749,183✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,636,653✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,636,305✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
3,113,811✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
3,113,811✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
3,113,811✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
171,410,952✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
171,387,273✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
171,398,093✔
601

602
  taosMemoryFreeClear(*ppEntry);
171,370,233✔
603
  return;
171,409,645✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
171,392,198✔
607
  int32_t code = TSDB_CODE_SUCCESS;
171,392,198✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
171,392,198✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
171,431,410✔
614
  if (NULL == *ppEntry) {
171,352,791✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
171,385,638✔
619
  (*ppEntry)->type = pEntry->type;
171,393,220✔
620
  (*ppEntry)->uid = pEntry->uid;
171,404,347✔
621

622
  if (pEntry->type < 0) {
171,435,179✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
171,423,386✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
171,415,175✔
628
    if (NULL == (*ppEntry)->name) {
171,433,423✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
171,425,418✔
636
    (*ppEntry)->flags = pEntry->flags;
151,643,137✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
151,667,383✔
639
    if (code) {
151,687,747✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
151,687,747✔
645
    if (code) {
151,704,296✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
151,704,296✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,775✔
651
      if (code) {
42,775✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
151,705,111✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
151,698,753✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
19,749,573✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,637,580✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,636,953✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,636,953✔
662

663
    // comment
664
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
16,636,953✔
665
    if (pEntry->ctbEntry.commentLen > 0) {
16,636,953✔
666
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
8,325✔
667
      if (NULL == (*ppEntry)->ctbEntry.comment) {
8,325✔
668
        code = terrno;
×
669
        metaCloneEntryFree(ppEntry);
×
670
        return code;
×
671
      }
672
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
8,325✔
673
    }
674

675
    // tags
676
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
16,636,689✔
677
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
16,636,653✔
678
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
16,636,353✔
679
      code = terrno;
×
680
      metaCloneEntryFree(ppEntry);
×
681
      return code;
×
682
    }
683
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
16,636,389✔
684
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
3,113,184✔
685
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
3,113,811✔
686
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
3,113,184✔
687
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
3,113,811✔
688
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
3,113,811✔
689

690
    // schema
691
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
3,113,811✔
692
    if (code) {
3,113,811✔
693
      metaCloneEntryFree(ppEntry);
×
694
      return code;
×
695
    }
696

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
3,113,811✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
3,113,811✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
12,081✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
12,081✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
12,081✔
707
    }
708
  } else {
709
    return TSDB_CODE_INVALID_PARA;
×
710
  }
711

712
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
171,454,866✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
662,565✔
714
    if (code) {
650,570✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
170,758,452✔
720
    if (code) {
170,794,965✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
171,445,535✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,738,763✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,725,121✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,731,091✔
733
  }
734

735
  return code;
171,426,310✔
736
}
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