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

taosdata / TDengine / #4956

09 Feb 2026 01:16AM UTC coverage: 66.85% (-0.03%) from 66.884%
#4956

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

205696 of 307696 relevant lines covered (66.85%)

127754527.22 hits per line

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

80.9
/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,030,036,027✔
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;
27,317,348✔
26
    }
27
  }
28
  return false;
1,001,738,624✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
187,388,562✔
32
  if (pME->pExtSchemas) {
187,388,562✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,885,574✔
34
    bool                  hasTypeMods = false;
11,885,574✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,885,574✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,800,308✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
89,900✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
89,900✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,878,663✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,297,348,153✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
187,411,301✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
430,458,964✔
58
    SColRef *p = &pw->pColRef[i];
429,206,422✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
858,412,844✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
858,412,844✔
61
    if (p->hasRef) {
429,206,422✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
569,422,612✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
569,422,612✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
569,422,612✔
65
    }
66
  }
67
  return 0;
1,252,542✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
975,044,441✔
71
  bool hasExtSchema = false;
975,044,441✔
72
  SSchemaWrapper* pSchWrapper = NULL;
975,044,441✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
975,044,441✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
738,282,441✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
236,799,086✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
236,891,850✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
975,132,533✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
975,080,501✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
36,820,083✔
84
    if (pME->pExtSchemas == NULL) {
18,415,317✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
1,539,540,334✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
956,670,183✔
93
  }
94

95
  return 0;
975,099,888✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
43,143,349✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
43,143,349✔
100
  bool                  hasTypeMods = false;
43,143,349✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
43,143,349✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
31,634,096✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,521,077✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,528,277✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
43,161,302✔
109

110
  if (hasTypeMods) {
43,135,545✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,316✔
112
    if (ret != NULL) {
39,316✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,316✔
114
    }
115
    return ret;
39,316✔
116
  }
117
  return NULL;
43,096,229✔
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) {
33,398,464✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
33,398,464✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
66,801,136✔
179
  if (pWrapper->nCols == 0) {
33,399,647✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
66,795,280✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
33,397,271✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
66,792,916✔
186
  if (pWrapper->pColRef == NULL) {
33,397,076✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
772,366,251✔
191
    SColRef *p = &pWrapper->pColRef[i];
738,943,757✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,477,965,976✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,478,023,463✔
194
    if (p->hasRef) {
739,033,657✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
407,851,669✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
407,852,171✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
407,853,109✔
198
    }
199
  }
200
  return 0;
33,401,848✔
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) {
642,981✔
220
  if (pSrc->nCols > 0) {
642,981✔
221
    pDst->nCols = pSrc->nCols;
642,981✔
222
    pDst->version = pSrc->version;
642,981✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
642,981✔
224
    if (NULL == pDst->pColRef) {
642,981✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
642,981✔
228
  }
229
  return 0;
642,981✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
44,815,939✔
233
  int32_t code = 0;
44,815,939✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
89,604,322✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
89,603,654✔
236
  uTrace("encode cols:%d", pw->nCols);
44,815,271✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
239
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
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;
44,873,506✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
44,626,245✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
44,626,245✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
44,669,292✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
975,109,413✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
975,109,413✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,950,208,670✔
252
  if (pWrapper->nCols == 0) {
974,865,670✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,950,297,051✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
975,275,833✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,950,336,257✔
259
  if (pWrapper->pColCmpr == NULL) {
975,104,813✔
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;
975,533,657✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
223,976✔
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,129,656✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
905,680✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
905,680✔
287
    pColCmpr->id = pColSchema->colId;
905,680✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
905,680✔
289
  }
290
  return 0;
223,976✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
175,653,833✔
294
  if (pSrc->nCols > 0) {
175,653,833✔
295
    pDst->nCols = pSrc->nCols;
159,266,357✔
296
    pDst->version = pSrc->version;
159,268,606✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
159,269,530✔
298
    if (NULL == pDst->pColCmpr) {
159,252,585✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
159,253,409✔
302
  }
303
  return 0;
175,663,547✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
176,292,707✔
307
  if (pColRef) {
176,292,707✔
308
    taosMemoryFreeClear(pColRef->pColRef);
176,301,171✔
309
  }
310
}
176,300,322✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
176,289,257✔
313
  if (pCmpr) {
176,289,257✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
176,292,651✔
315
  }
316
}
176,279,914✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
191,847,847✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
191,847,847✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
383,721,949✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
383,682,180✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
383,627,578✔
323

324
  if (pME->type > 0) {
191,803,499✔
325
    if (pME->name == NULL) {
187,408,518✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
374,765,760✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
187,370,221✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
49,108,215✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
49,203,829✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
49,169,715✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
24,542,251✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
75,400✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
162,811,102✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
283,727,714✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
283,728,865✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
283,729,512✔
342
      if (pME->ctbEntry.commentLen > 0) {
141,865,370✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,948✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
283,724,249✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
141,861,978✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
20,951,410✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
41,902,623✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
41,902,229✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
41,902,426✔
351
      if (pME->ntbEntry.commentLen > 0) {
20,951,410✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
39,356✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
41,902,426✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
41,902,623✔
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) {
187,374,605✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,308,907✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
186,100,286✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,571,743✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
161,565,378✔
368
        if (pME->colCmpr.nCols != 0) {
20,281,353✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
20,057,574✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
223,976✔
372
          SColCmprWrapper colCmprs = {0};
223,976✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
223,976✔
374
          if (code != 0) {
223,976✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
223,976✔
379
          taosMemoryFree(colCmprs.pColCmpr);
223,976✔
380
          TAOS_CHECK_RETURN(code);
223,976✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
187,404,018✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
191,832,482✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
49,134,055✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
49,045,809✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
167,243,387✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
40,563,100✔
391
  }
392

393
  tEndEncode(pCoder);
191,766,446✔
394
  return 0;
191,831,119✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,750,183,453✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,750,183,453✔
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,750,691,701✔
404
    tEndDecode(pCoder);
359,774✔
405
    return 0;
359,774✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,750,123,442✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,476,837,575✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,476,894,992✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,476,835,078✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
738,352,483✔
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) {
1,011,465,678✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,535,322,797✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,535,386,876✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,535,268,048✔
422
      if (pME->ctbEntry.commentLen > 0) {
767,569,897✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
48,322✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,535,246,298✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
767,692,225✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
243,991,259✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
488,171,077✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
488,253,868✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
488,177,111✔
431
      if (pME->ntbEntry.commentLen > 0) {
244,052,291✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
72,496✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
488,095,052✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
488,139,674✔
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,749,973,127✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
738,458,014✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
738,442,341✔
449

450
        if (pME->colCmpr.nCols == 0) {
738,538,760✔
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) {
1,011,423,659✔
458
      if (!tDecodeIsEnd(pCoder)) {
236,946,802✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
236,953,088✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
236,953,088✔
461
        if (pME->colCmpr.nCols == 0) {
236,915,037✔
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);
×
466
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
467
      }
468
      TABLE_SET_COL_COMPRESSED(pME->flags);
236,921,563✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
774,543,861✔
470
      if (!tDecodeIsEnd(pCoder)) {
33,399,588✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
33,400,102✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
33,400,824✔
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,750,122,764✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
975,360,675✔
482
    } else {
483
      pME->pExtSchemas = NULL;
774,762,089✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,749,802,118✔
487
    if (!tDecodeIsEnd(pCoder)) {
738,219,067✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,476,693,958✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
738,244,594✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,476,576,621✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,011,441,018✔
494
    if (!tDecodeIsEnd(pCoder)) {
236,895,399✔
495
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
473,838,211✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,749,915,007✔
501
  return 0;
1,749,714,391✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,749,884,638✔
505

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

511
  pDst->nCols = pSrc->nCols;
310,861,054✔
512
  pDst->version = pSrc->version;
310,850,854✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
310,843,950✔
514
  if (pDst->pSchema == NULL) {
310,785,889✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
310,815,910✔
518
  return TSDB_CODE_SUCCESS;
310,869,243✔
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,775✔
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) {
310,837,135✔
553
  if (pSchema) {
310,837,135✔
554
    taosMemoryFreeClear(pSchema->pSchema);
310,849,764✔
555
  }
556
}
310,819,626✔
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);
63,800✔
567
    taosMemoryFreeClear(pParam->funcIds);
63,800✔
568
  }
569
}
65,250✔
570

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
176,361,047✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
176,361,047✔
573
    return;
72,067✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
176,296,662✔
577

578
  if ((*ppEntry)->type < 0) {
176,304,676✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
176,263,155✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
151,154,237✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
151,139,736✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
151,138,122✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,800✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
25,135,956✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,598,254✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,598,881✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,539,132✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,539,132✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,539,132✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
176,280,953✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
176,269,616✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
176,275,656✔
601

602
  taosMemoryFreeClear(*ppEntry);
176,259,105✔
603
  return;
176,291,510✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
176,276,958✔
607
  int32_t code = TSDB_CODE_SUCCESS;
176,276,958✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
176,276,958✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
176,303,635✔
614
  if (NULL == *ppEntry) {
176,253,539✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
176,263,536✔
619
  (*ppEntry)->type = pEntry->type;
176,282,794✔
620
  (*ppEntry)->uid = pEntry->uid;
176,284,187✔
621

622
  if (pEntry->type < 0) {
176,301,333✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
176,293,415✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
176,282,104✔
628
    if (NULL == (*ppEntry)->name) {
176,294,850✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
176,296,131✔
636
    (*ppEntry)->flags = pEntry->flags;
151,140,541✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
151,158,445✔
639
    if (code) {
151,165,732✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
151,165,732✔
645
    if (code) {
151,173,872✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
151,173,872✔
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,174,048✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
151,167,981✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
25,138,013✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,598,881✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,598,881✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,598,881✔
662

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

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

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,539,132✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,539,132✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
12,188✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
12,188✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
12,188✔
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) {
176,313,736✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
662,076✔
714
    if (code) {
642,981✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
175,634,224✔
720
    if (code) {
175,661,787✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
176,304,768✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,319,314✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,310,241✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,316,486✔
733
  }
734

735
  return code;
176,290,862✔
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