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

taosdata / TDengine / #4821

22 Oct 2025 06:02AM UTC coverage: 61.242% (-0.1%) from 61.353%
#4821

push

travis-ci

web-flow
Merge pull request #33334 from taosdata/3.0

fix(stream): reset tableScan operator (#33225)

156089 of 324573 branches covered (48.09%)

Branch coverage included in aggregate %.

184 of 244 new or added lines in 9 files covered. (75.41%)

789 existing lines in 124 files now uncovered.

207891 of 269759 relevant lines covered (77.07%)

244003752.29 hits per line

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

65.89
/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) {
2,147,483,647✔
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;
113,917,371✔
26
    }
27
  }
28
  return false;
2,147,483,647✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
557,553,344✔
32
  if (pME->pExtSchemas) {
557,553,344✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
28,193,731✔
34
    bool                  hasTypeMods = false;
28,193,731✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
28,193,731✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
27,892,133✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
306,874!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
306,874✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
28,200,749✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
2,147,483,647✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647!
46
    }
47
  }
48
  return 0;
557,713,957✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
3,081,132✔
52
  const SColRefWrapper *pw = &pME->colRef;
3,081,132✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
6,162,264!
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
6,162,264!
55
  uTrace("encode cols:%d", pw->nCols);
3,081,132!
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
29,649,632✔
58
    SColRef *p = &pw->pColRef[i];
26,568,500✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
53,137,000!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
53,137,000!
61
    if (p->hasRef) {
26,568,500!
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
30,209,900!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
30,209,900!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
30,209,900!
65
    }
66
  }
67
  return 0;
3,081,132✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
2,147,483,647✔
71
  bool hasExtSchema = false;
2,147,483,647✔
72
  SSchemaWrapper* pSchWrapper = NULL;
2,147,483,647✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
2,147,483,647✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
3,200,158!
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
3,200,158✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
2,147,483,647✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
2,147,483,647✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
179,357,775!
84
    if (pME->pExtSchemas == NULL) {
89,686,995!
85
      return terrno;
×
86
    }
87

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

95
  return 0;
2,147,483,647✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
119,838,310✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
119,838,310✔
100
  bool                  hasTypeMods = false;
119,838,310✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
119,838,310✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
86,253,009✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
33,682,175!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
33,710,837✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
119,951,334✔
109

110
  if (hasTypeMods) {
119,802,802✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
148,562!
112
    if (ret != NULL) {
148,562!
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
148,562!
114
    }
115
    return ret;
148,562✔
116
  }
117
  return NULL;
119,654,240✔
118
}
119

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

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

131
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
44,064!
132
  if (*rsmaSchema == NULL) {
44,064!
133
    return terrno;
×
134
  }
135

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
44,064✔
151
  int32_t    i = 0, j = 0;
44,064✔
152
  for (i = 0; i < nCols; ++i) {
340,848✔
153
    while (j < pParam->nFuncs) {
541,728✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
519,696✔
155
        pFuncIds[i] = pParam->funcIds[j];
242,352✔
156
        break;
242,352✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
277,344✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
54,432✔
160
        break;
54,432✔
161
      }
162
      ++j;
222,912✔
163
    }
164
    if (j >= pParam->nFuncs) {
318,816✔
165
      for (; i < nCols; ++i) {
44,064✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
22,032✔
167
      }
168
      break;
22,032✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
44,064✔
172

173
  return 0;
44,064✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,532,915✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
45,532,915✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,065,830!
179
  if (pWrapper->nCols == 0) {
45,532,915!
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,064,493!
184
  uDebug("decode cols:%d", pWrapper->nCols);
45,531,578✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,064,493!
186
  if (pWrapper->pColRef == NULL) {
45,532,915!
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
503,970,414✔
191
    SColRef *p = &pWrapper->pColRef[i];
458,414,158✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
916,910,151!
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
916,938,166!
194
    if (p->hasRef) {
458,480,713!
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
284,363,232!
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
284,367,005!
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
284,372,067!
198
    }
199
  }
200
  return 0;
45,532,915✔
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) {
1,676,348✔
220
  if (pSrc->nCols > 0) {
1,676,348!
221
    pDst->nCols = pSrc->nCols;
1,676,348✔
222
    pDst->version = pSrc->version;
1,676,348✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,676,348!
224
    if (NULL == pDst->pColRef) {
1,676,348!
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,676,348!
228
  }
229
  return 0;
1,676,348✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
122,960,486✔
233
  int32_t code = 0;
122,960,486✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
245,958,277!
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
246,007,600!
236
  uTrace("encode cols:%d", pw->nCols);
123,009,809✔
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;
123,077,716✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
122,340,566✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
122,340,566✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
122,500,831✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
2,147,483,647✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
2,147,483,647✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647!
252
  if (pWrapper->nCols == 0) {
2,147,483,647!
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
2,147,483,647!
257
  uDebug("dencode cols:%d", pWrapper->nCols);
2,147,483,647✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
2,147,483,647!
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;
2,147,483,647✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
625,888✔
273

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

280
  if (pCmpr->pColCmpr == NULL) {
625,888!
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
3,086,248!
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
2,460,360✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
2,460,360✔
287
    pColCmpr->id = pColSchema->colId;
2,460,360✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
2,460,360✔
289
  }
290
  return 0;
625,888✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
552,627,237✔
294
  if (pSrc->nCols > 0) {
552,627,237✔
295
    pDst->nCols = pSrc->nCols;
503,643,422✔
296
    pDst->version = pSrc->version;
503,640,847✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
503,617,639!
298
    if (NULL == pDst->pColCmpr) {
503,586,735!
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
503,595,272!
302
  }
303
  return 0;
552,608,914✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
554,286,332✔
307
  if (pColRef) {
554,286,332!
308
    taosMemoryFreeClear(pColRef->pColRef);
554,308,931!
309
  }
310
}
554,300,586✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
554,274,917✔
313
  if (pCmpr) {
554,274,917!
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
554,310,404!
315
  }
316
}
554,258,447✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
607,368,043✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
607,368,043!
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,214,828,731!
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,214,789,191!
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,214,779,205!
323

324
  if (pME->type > 0) {
607,378,685✔
325
    if (pME->name == NULL) {
557,669,153!
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,115,239,736!
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
557,583,879✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
165,849,370!
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
166,113,332!
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
165,965,829!
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
82,828,045✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
120,528!
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
474,679,182✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
866,116,175!
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
866,108,147!
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
866,093,017!
342
      if (pME->ctbEntry.commentLen > 0) {
433,052,132✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
100,360!
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
866,111,763!
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
433,061,175!
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
41,650,392!
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
83,300,784!
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
83,300,784!
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
83,300,784!
351
      if (pME->ntbEntry.commentLen > 0) {
41,650,392✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
123,160!
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
83,300,784!
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
83,300,784!
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) {
557,624,188✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
3,168,777!
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
554,495,898✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
82,976,331✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
471,674,143✔
368
        if (pME->colCmpr.nCols != 0) {
40,070,438✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
39,444,550!
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
625,888!
372
          SColCmprWrapper colCmprs = {0};
625,888✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
625,888!
374
          if (code != 0) {
625,888!
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
625,888✔
379
          taosMemoryFree(colCmprs.pColCmpr);
625,888!
380
          TAOS_CHECK_RETURN(code);
625,888!
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
557,685,953!
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
607,327,306✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
165,928,391!
388
  }
389

390
  tEndEncode(pCoder);
607,313,284✔
391
  return 0;
607,373,961✔
392
}
393

394
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,147,483,647✔
395
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,147,483,647!
396
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647!
397
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647!
398
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647!
399

400
  if (headerOnly) {
2,147,483,647✔
401
    tEndDecode(pCoder);
1,080,526✔
402
    return 0;
1,080,526✔
403
  }
404

405
  if (pME->type > 0) {
2,147,483,647✔
406
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647!
407

408
    if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
409
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
2,147,483,647!
410
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,147,483,647!
411
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,147,483,647!
412
      if (TABLE_IS_ROLLUP(pME->flags)) {
2,147,483,647✔
413
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
473,040!
414
      }
415
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,147,483,647✔
416
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
2,147,483,647!
417
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
2,147,483,647!
418
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
2,147,483,647!
419
      if (pME->ctbEntry.commentLen > 0) {
2,147,483,647✔
420
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
184,190!
421
      }
422
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
2,147,483,647!
423
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,147,483,647!
424
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
645,677,170!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,291,719,998!
426
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,291,893,318!
427
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,291,746,663!
428
      if (pME->ntbEntry.commentLen > 0) {
645,816,633✔
429
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
244,406!
430
      }
431
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,291,495,809!
432
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,291,595,828!
433
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
434
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
435
      if (!pME->smaEntry.tsma) {
×
436
        return terrno;
×
437
      }
438
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
439
    } else {
440
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
441
      return TSDB_CODE_INVALID_PARA;
×
442
    }
443
    if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
444
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
2,147,483,647!
445
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,147,483,647!
446

447
        if (pME->colCmpr.nCols == 0) {
2,147,483,647!
448
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
449
        }
450
      } else {
451
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
453
      }
454
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,147,483,647✔
455
      if (!tDecodeIsEnd(pCoder)) {
638,342,698✔
456
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
638,348,679✔
457
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
638,348,679!
458
        if (pME->colCmpr.nCols == 0) {
638,206,424!
459
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
460
        }
461
      } else {
462
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
1,055!
463
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
1,055!
464
      }
465
      TABLE_SET_COL_COMPRESSED(pME->flags);
638,236,529✔
466
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,147,483,647✔
467
      if (!tDecodeIsEnd(pCoder)) {
45,532,915!
468
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,532,915✔
469
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,534,180!
470
      } else {
UNCOV
471
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
472
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
473
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
474
        }
475
      }
476
    }
477
    if (!tDecodeIsEnd(pCoder)) {
2,147,483,647✔
478
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
2,147,483,647!
479
    } else {
480
      pME->pExtSchemas = NULL;
2,147,483,647✔
481
    }
482
  }
483
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
484
    if (!tDecodeIsEnd(pCoder)) {
2,147,483,647!
485
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,147,483,647!
486
    }
487
  }
488

489

490
  tEndDecode(pCoder);
2,147,483,647✔
491
  return 0;
2,147,483,647✔
492
}
493

494
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,147,483,647✔
495

496
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
988,043,586✔
497
  if (pSrc == NULL || pDst == NULL) {
988,043,586!
498
    return TSDB_CODE_INVALID_PARA;
×
499
  }
500

501
  pDst->nCols = pSrc->nCols;
988,087,447✔
502
  pDst->version = pSrc->version;
988,081,865✔
503
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
988,080,841!
504
  if (pDst->pSchema == NULL) {
987,898,205!
505
    return terrno;
×
506
  }
507
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
987,956,242!
508
  return TSDB_CODE_SUCCESS;
988,099,598✔
509
}
510

511
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
69,984✔
512
  if (pSrc == NULL || pDst == NULL) {
69,984!
513
    return TSDB_CODE_INVALID_PARA;
×
514
  }
515
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
69,984!
516
  pDst->name = tstrdup(pSrc->name);
69,984✔
517
  if (pDst->name == NULL) {
71,280!
518
    return terrno;
×
519
  }
520
  if (pSrc->nFuncs > 0) {
69,984!
521
    pDst->nFuncs = pSrc->nFuncs;
69,984✔
522
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
69,984!
523
    if (pDst->funcColIds == NULL) {
71,280!
524
      return terrno;
×
525
    }
526
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
69,984!
527

528
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
69,984!
529
    if (pDst->funcIds == NULL) {
69,984!
530
      return terrno;
×
531
    }
532
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
68,688!
533
  } else {
534
    pDst->nFuncs = 0;
×
535
    pDst->funcColIds = NULL;
×
536
    pDst->funcIds = NULL;
×
537
  }
538

539
  return TSDB_CODE_SUCCESS;
69,984✔
540
}
541

542
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
988,037,513✔
543
  if (pSchema) {
988,037,513!
544
    taosMemoryFreeClear(pSchema->pSchema);
988,074,247!
545
  }
546
}
988,017,929✔
547

548
/**
549
 * @param type 0x01 free name
550
 */
551
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
106,272✔
552
  if (pParam) {
106,272!
553
    if ((type & 0x01)) {
107,568!
554
      taosMemoryFreeClear(pParam->name);
107,568!
555
    }
556
    taosMemoryFreeClear(pParam->funcColIds);
103,680!
557
    taosMemoryFreeClear(pParam->funcIds);
106,272!
558
  }
559
}
102,384✔
560

561
void metaCloneEntryFree(SMetaEntry **ppEntry) {
554,468,679✔
562
  if (ppEntry == NULL || *ppEntry == NULL) {
554,468,679!
563
    return;
188,031✔
564
  }
565

566
  taosMemoryFreeClear((*ppEntry)->name);
554,301,004!
567

568
  if ((*ppEntry)->type < 0) {
554,313,995!
569
    taosMemoryFreeClear(*ppEntry);
×
570
    return;
×
571
  }
572

573
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
554,263,612✔
574
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
483,326,216✔
575
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
483,311,075✔
576
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
483,317,393✔
577
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
103,680✔
578
    }
579
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
70,962,807✔
580
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
49,565,178!
581
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
49,566,558!
582
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
21,398,431!
583
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
21,398,431✔
584
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
21,398,431!
585
  } else {
586
    return;
×
587
  }
588
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
554,284,946✔
589
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
554,263,603!
590
  metaCloneColRefFree(&(*ppEntry)->colRef);
554,283,791✔
591

592
  taosMemoryFreeClear(*ppEntry);
554,265,580!
593
  return;
554,278,792✔
594
}
595

596
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
554,253,352✔
597
  int32_t code = TSDB_CODE_SUCCESS;
554,253,352✔
598

599
  if (NULL == pEntry || NULL == ppEntry) {
554,253,352!
600
    return TSDB_CODE_INVALID_PARA;
×
601
  }
602

603
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
554,323,811!
604
  if (NULL == *ppEntry) {
554,201,384!
605
    return terrno;
×
606
  }
607

608
  (*ppEntry)->version = pEntry->version;
554,231,403✔
609
  (*ppEntry)->type = pEntry->type;
554,260,608✔
610
  (*ppEntry)->uid = pEntry->uid;
554,288,218✔
611

612
  if (pEntry->type < 0) {
554,299,102!
613
    return TSDB_CODE_SUCCESS;
×
614
  }
615

616
  if (pEntry->name) {
554,283,653✔
617
    (*ppEntry)->name = tstrdup(pEntry->name);
554,294,760✔
618
    if (NULL == (*ppEntry)->name) {
554,303,860!
619
      code = terrno;
×
620
      metaCloneEntryFree(ppEntry);
×
621
      return code;
×
622
    }
623
  }
624

625
  if (pEntry->type == TSDB_SUPER_TABLE) {
554,292,902✔
626
    (*ppEntry)->flags = pEntry->flags;
483,322,785✔
627

628
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
483,340,800✔
629
    if (code) {
483,344,314!
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633

634
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
483,344,314✔
635
    if (code) {
483,371,679!
636
      metaCloneEntryFree(ppEntry);
×
637
      return code;
×
638
    }
639
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
483,371,679✔
640
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
69,984✔
641
      if (code) {
69,984!
642
        metaCloneEntryFree(ppEntry);
×
643
        return code;
×
644
      }
645
    }
646
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
483,373,791✔
647
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
70,964,135✔
648
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
49,563,996✔
649
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
49,564,850✔
650
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
49,566,558✔
651

652
    // comment
653
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
49,565,704✔
654
    if (pEntry->ctbEntry.commentLen > 0) {
49,566,125✔
655
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
29,345!
656
      if (NULL == (*ppEntry)->ctbEntry.comment) {
29,345!
657
        code = terrno;
×
658
        metaCloneEntryFree(ppEntry);
×
659
        return code;
×
660
      }
661
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
29,345!
662
    }
663

664
    // tags
665
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
49,561,762✔
666
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
49,561,762!
667
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
49,564,850!
668
      code = terrno;
×
669
      metaCloneEntryFree(ppEntry);
×
670
      return code;
×
671
    }
672
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
49,564,850!
673
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
21,398,431!
674
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
21,398,431✔
675
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
21,398,431✔
676
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
21,398,431✔
677

678
    // schema
679
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
21,398,431✔
680
    if (code) {
21,398,431!
681
      metaCloneEntryFree(ppEntry);
×
682
      return code;
×
683
    }
684

685
    // comment
686
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
21,398,431✔
687
    if (pEntry->ntbEntry.commentLen > 0) {
21,398,431✔
688
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
38,337!
689
      if (NULL == (*ppEntry)->ntbEntry.comment) {
38,337!
690
        code = terrno;
×
691
        metaCloneEntryFree(ppEntry);
×
692
        return code;
×
693
      }
694
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
38,337!
695
    }
696
  } else {
697
    return TSDB_CODE_INVALID_PARA;
×
698
  }
699

700
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
554,309,616✔
701
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,736,766✔
702
    if (code) {
1,676,348!
703
      metaCloneEntryFree(ppEntry);
×
704
      return code;
×
705
    }
706
  } else {
707
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
552,593,672✔
708
    if (code) {
552,599,257!
709
      metaCloneEntryFree(ppEntry);
×
710
      return code;
×
711
    }
712
  }
713
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
554,275,605✔
714
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
26,843,608!
715
    if (!(*ppEntry)->pExtSchemas) {
26,844,275!
716
      code = terrno;
×
717
      metaCloneEntryFree(ppEntry);
×
718
      return code;
×
719
    }
720
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
26,842,629!
721
  }
722

723
  return code;
554,281,016✔
724
}
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