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

taosdata / TDengine / #4541

19 Jul 2025 01:13AM UTC coverage: 56.753% (-1.6%) from 58.31%
#4541

push

travis-ci

web-flow
fix: subquery memleak (#32024)

124299 of 282344 branches covered (44.02%)

Branch coverage included in aggregate %.

181106 of 255787 relevant lines covered (70.8%)

24937406.43 hits per line

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

67.68
/source/dnode/vnode/src/meta/metaEntry.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "meta.h"
17

18
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
37,526,146✔
19
  for (int32_t i = 0; i < nCols; i++) {
907,115,441✔
20
    if (HAS_TYPE_MOD(pSchema + i)) {
869,716,507✔
21
      return true;
127,212✔
22
    }
23
  }
24
  return false;
37,398,934✔
25
}
26

27
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
725,803✔
28
  if (pME->pExtSchemas) {
725,803✔
29
    const SSchemaWrapper *pSchWrapper = NULL;
17,061✔
30
    bool                  hasTypeMods = false;
17,061✔
31
    if (pME->type == TSDB_SUPER_TABLE) {
17,061✔
32
      pSchWrapper = &pME->stbEntry.schemaRow;
16,741✔
33
    } else if (pME->type == TSDB_NORMAL_TABLE) {
320!
34
      pSchWrapper = &pME->ntbEntry.schemaRow;
320✔
35
    } else {
36
      return 0;
×
37
    }
38
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
17,061✔
39

40
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,192,379✔
41
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,350,632!
42
    }
43
  }
44
  return 0;
725,805✔
45
}
46

47
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
1,250✔
48
  const SColRefWrapper *pw = &pME->colRef;
1,250✔
49
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
2,500!
50
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
2,500!
51
  uTrace("encode cols:%d", pw->nCols);
1,250!
52

53
  for (int32_t i = 0; i < pw->nCols; i++) {
13,598✔
54
    SColRef *p = &pw->pColRef[i];
12,348✔
55
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
24,696!
56
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
24,696!
57
    if (p->hasRef) {
12,348✔
58
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
12,668!
59
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
12,668!
60
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
12,668!
61
    }
62
  }
63
  return 0;
1,250✔
64
}
65

66
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
56,583,673✔
67
  bool hasExtSchema = false;
56,583,673✔
68
  SSchemaWrapper* pSchWrapper = NULL;
56,583,673✔
69
  if (pME->type == TSDB_SUPER_TABLE) {
56,583,673✔
70
    pSchWrapper = &pME->stbEntry.schemaRow;
37,231,836✔
71
  } else if (pME->type == TSDB_NORMAL_TABLE) {
19,351,837✔
72
    pSchWrapper = &pME->ntbEntry.schemaRow;
50,603✔
73
  } else {
74
    return 0;
19,301,234✔
75
  }
76

77
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
37,282,439✔
78
  if (hasExtSchema && pSchWrapper->nCols > 0) {
37,482,461!
79
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
110,653!
80
    if (pME->pExtSchemas == NULL) {
110,658!
81
      return terrno;
×
82
    }
83

84
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,759,018✔
85
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
15,296,707!
86
    }
87
  }
88

89
  return 0;
37,482,479✔
90
}
91

92
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
118,186✔
93
  const SSchemaWrapper *pSchWrapper = NULL;
118,186✔
94
  bool                  hasTypeMods = false;
118,186✔
95
  if (pME->type == TSDB_SUPER_TABLE) {
118,186✔
96
    pSchWrapper = &pME->stbEntry.schemaRow;
78,184✔
97
  } else if (pME->type == TSDB_NORMAL_TABLE) {
40,002!
98
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,024✔
99
  } else {
100
    return NULL;
×
101
  }
102
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
118,208✔
103

104
  if (hasTypeMods) {
118,218✔
105
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
127!
106
    if (ret != NULL) {
118!
107
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
118✔
108
    }
109
    return ret;
118✔
110
  }
111
  return NULL;
118,091✔
112
}
113

114
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
3,560✔
115
  SColRefWrapper *pWrapper = &pME->colRef;
3,560✔
116
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
7,118!
117
  if (pWrapper->nCols == 0) {
3,558!
118
    return 0;
×
119
  }
120

121
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
7,117!
122
  uDebug("decode cols:%d", pWrapper->nCols);
3,559✔
123
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
3,559!
124
  if (pWrapper->pColRef == NULL) {
3,565!
125
    return terrno;
×
126
  }
127

128
  for (int i = 0; i < pWrapper->nCols; i++) {
60,187✔
129
    SColRef *p = &pWrapper->pColRef[i];
56,649✔
130
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
113,226!
131
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
113,158!
132
    if (p->hasRef) {
56,581✔
133
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
30,224!
134
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
30,195!
135
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
30,280✔
136
    }
137
  }
138
  return 0;
3,538✔
139
}
140

141
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
142
                                                            SSchemaWrapper *pSchema) {
143
  pRef->nCols = pSchema->nCols;
×
144
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
145
    return terrno;
×
146
  }
147

148
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
149
    SColRef  *pColRef = &pRef->pColRef[i];
×
150
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
151
    pColRef->id = pColSchema->colId;
×
152
    pColRef->hasRef = false;
×
153
  }
154
  return 0;
×
155
}
156

157
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
762✔
158
  if (pSrc->nCols > 0) {
762!
159
    pDst->nCols = pSrc->nCols;
762✔
160
    pDst->version = pSrc->version;
762✔
161
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
762!
162
    if (NULL == pDst->pColRef) {
762!
163
      return terrno;
×
164
    }
165
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
762✔
166
  }
167
  return 0;
762✔
168
}
169

170
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
724,774✔
171
  const SColCmprWrapper *pw = &pME->colCmpr;
724,774✔
172
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
1,449,548!
173
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
1,449,548!
174
  uTrace("encode cols:%d", pw->nCols);
724,774✔
175

176
  for (int32_t i = 0; i < pw->nCols; i++) {
25,432,217✔
177
    SColCmpr *p = &pw->pColCmpr[i];
24,707,518✔
178
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
49,415,036!
179
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
49,415,036!
180
  }
181
  return 0;
724,699✔
182
}
183
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
41,515,833✔
184
  SColCmprWrapper *pWrapper = &pME->colCmpr;
41,515,833✔
185
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
82,816,427!
186
  if (pWrapper->nCols == 0) {
41,300,594!
187
    return 0;
×
188
  }
189

190
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
82,576,256!
191
  uDebug("dencode cols:%d", pWrapper->nCols);
41,275,662✔
192
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
41,275,833✔
193
  if (pWrapper->pColCmpr == NULL) {
41,556,809!
194
    return terrno;
×
195
  }
196

197
  for (int i = 0; i < pWrapper->nCols; i++) {
908,392,889✔
198
    SColCmpr *p = &pWrapper->pColCmpr[i];
867,952,457✔
199
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,727,940,228!
200
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
1,726,823,851!
201
  }
202
  return 0;
40,440,432✔
203
}
204
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
205
                                                            SSchemaWrapper *pSchema) {
206
  pCmpr->nCols = pSchema->nCols;
×
207
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
×
208
    return terrno;
×
209
  }
210

211
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
×
212
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
×
213
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
214
    pColCmpr->id = pColSchema->colId;
×
215
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
×
216
  }
217
  return 0;
×
218
}
219

220
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
609,570✔
221
  if (pSrc->nCols > 0) {
609,570✔
222
    pDst->nCols = pSrc->nCols;
575,032✔
223
    pDst->version = pSrc->version;
575,032✔
224
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
575,032!
225
    if (NULL == pDst->pColCmpr) {
575,263!
226
      return terrno;
×
227
    }
228
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
575,263✔
229
  }
230
  return 0;
609,801✔
231
}
232

233
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
610,559✔
234
  if (pColRef) {
610,559!
235
    taosMemoryFreeClear(pColRef->pColRef);
610,562!
236
  }
237
}
610,559✔
238

239
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
610,494✔
240
  if (pCmpr) {
610,494!
241
    taosMemoryFreeClear(pCmpr->pColCmpr);
610,522!
242
  }
243
}
610,564✔
244

245
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
763,665✔
246
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
763,665✔
247
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,529,920!
248
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,529,920!
249
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,529,920!
250

251
  if (pME->type > 0) {
764,960✔
252
    if (pME->name == NULL) {
726,002!
253
      return TSDB_CODE_INVALID_PARA;
×
254
    }
255

256
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,452,004!
257

258
    if (pME->type == TSDB_SUPER_TABLE) {
726,002✔
259
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
171,504!
260
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
171,504!
261
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
171,504!
262
      if (TABLE_IS_ROLLUP(pME->flags)) {
85,752✔
263
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
264
      }
265
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
640,250✔
266
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
1,187,150!
267
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
1,187,150!
268
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
1,187,150!
269
      if (pME->ctbEntry.commentLen > 0) {
593,575✔
270
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
271
      }
272
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
1,187,150!
273
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
593,575!
274
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
46,675!
275
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
93,350!
276
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
93,350!
277
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
93,350!
278
      if (pME->ntbEntry.commentLen > 0) {
46,675✔
279
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
280
      }
281
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
93,350!
282
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
93,350!
283
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
284
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
285
    } else {
286
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
287
      return TSDB_CODE_INVALID_PARA;
×
288
    }
289
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
726,001!
290
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,089!
291
    } else {
292
      TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
724,912!
293
    }
294
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
725,910!
295
  }
296
  if (pME->type == TSDB_SUPER_TABLE) {
764,519✔
297
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
170,536!
298
  }
299

300
  tEndEncode(pCoder);
764,519✔
301
  return 0;
764,370✔
302
}
303

304
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
61,150,116✔
305
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
61,150,116!
306
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
121,736,101!
307
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
120,633,686!
308
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
120,164,837!
309

310
  if (headerOnly) {
60,106,702✔
311
    tEndDecode(pCoder);
177,074✔
312
    return 0;
177,074✔
313
  }
314

315
  if (pME->type > 0) {
59,929,628!
316
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
120,940,424!
317

318
    if (pME->type == TSDB_SUPER_TABLE) {
60,923,324✔
319
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
74,489,077!
320
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
69,155,972!
321
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
70,985,598!
322
      if (TABLE_IS_ROLLUP(pME->flags)) {
38,961,510✔
323
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
56!
324
      }
325
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
23,566,131✔
326
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
38,799,009!
327
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
38,765,139!
328
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
38,752,411!
329
      if (pME->ctbEntry.commentLen > 0) {
19,389,799✔
330
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
331
      }
332
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
38,774,340!
333
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
19,384,541✔
334
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
4,169,649!
335
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
8,334,029!
336
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
8,325,327!
337
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
8,324,063!
338
      if (pME->ntbEntry.commentLen > 0) {
4,163,116✔
339
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
340
      }
341
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
8,325,799!
342
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
8,306,280!
343
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
344
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
345
      if (!pME->smaEntry.tsma) {
×
346
        return terrno;
×
347
      }
348
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
349
    } else {
350
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
351
      return TSDB_CODE_INVALID_PARA;
×
352
    }
353
    if (pME->type == TSDB_SUPER_TABLE) {
61,004,955✔
354
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
37,352,824!
355
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
37,373,570!
356

357
        if (pME->colCmpr.nCols == 0) {
37,181,135!
358
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
359
        }
360
      } else {
361
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
362
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
363
      }
364
    } else if (pME->type == TSDB_NORMAL_TABLE) {
23,652,131✔
365
      if (!tDecodeIsEnd(pCoder)) {
4,170,071!
366
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,170,597✔
367
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
4,170,602✔
368
        if (pME->colCmpr.nCols == 0) {
4,163,916!
369
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
370
        }
371
      } else {
372
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
373
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
374
      }
375
      TABLE_SET_COL_COMPRESSED(pME->flags);
4,163,916✔
376
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
19,482,060!
377
      if (!tDecodeIsEnd(pCoder)) {
3,560!
378
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
3,560✔
379
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
3,560!
380
      } else {
381
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
382
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
383
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
384
        }
385
      }
386
    }
387
    if (!tDecodeIsEnd(pCoder)) {
60,612,436✔
388
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
56,618,129!
389
    }
390
  }
391
  if (pME->type == TSDB_SUPER_TABLE) {
60,842,548✔
392
    if (!tDecodeIsEnd(pCoder)) {
37,426,244!
393
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
74,631,674!
394
    }
395
  }
396

397

398
  tEndDecode(pCoder);
60,611,638✔
399
  return 0;
60,615,181✔
400
}
401

402
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
60,907,804✔
403

404
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
1,136,267✔
405
  if (pSrc == NULL || pDst == NULL) {
1,136,267!
406
    return TSDB_CODE_INVALID_PARA;
×
407
  }
408

409
  pDst->nCols = pSrc->nCols;
1,136,347✔
410
  pDst->version = pSrc->version;
1,136,347✔
411
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
1,136,347!
412
  if (pDst->pSchema == NULL) {
1,136,374!
413
    return terrno;
×
414
  }
415
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
1,136,374✔
416
  return TSDB_CODE_SUCCESS;
1,136,374✔
417
}
418

419
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
1,136,593✔
420
  if (pSchema) {
1,136,593!
421
    taosMemoryFreeClear(pSchema->pSchema);
1,136,618!
422
  }
423
}
1,136,712✔
424

425
void metaCloneEntryFree(SMetaEntry **ppEntry) {
610,578✔
426
  if (ppEntry == NULL || *ppEntry == NULL) {
610,578!
427
    return;
77✔
428
  }
429

430
  taosMemoryFreeClear((*ppEntry)->name);
610,501!
431

432
  if ((*ppEntry)->type < 0) {
610,538!
433
    taosMemoryFreeClear(*ppEntry);
×
434
    return;
×
435
  }
436

437
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
610,538✔
438
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
560,900✔
439
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
560,960✔
440
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
49,638✔
441
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
34,679!
442
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
34,679!
443
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,959!
444
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,959✔
445
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,959!
446
  } else {
447
    return;
×
448
  }
449
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
610,630✔
450
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
610,555!
451
  metaCloneColRefFree(&(*ppEntry)->colRef);
610,558✔
452

453
  taosMemoryFreeClear(*ppEntry);
610,568!
454
  return;
610,633✔
455
}
456

457
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
610,286✔
458
  int32_t code = TSDB_CODE_SUCCESS;
610,286✔
459

460
  if (NULL == pEntry || NULL == ppEntry) {
610,286!
461
    return TSDB_CODE_INVALID_PARA;
×
462
  }
463

464
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
610,338!
465
  if (NULL == *ppEntry) {
610,543!
466
    return terrno;
×
467
  }
468

469
  (*ppEntry)->version = pEntry->version;
610,543✔
470
  (*ppEntry)->type = pEntry->type;
610,543✔
471
  (*ppEntry)->uid = pEntry->uid;
610,543✔
472

473
  if (pEntry->type < 0) {
610,543!
474
    return TSDB_CODE_SUCCESS;
×
475
  }
476

477
  if (pEntry->name) {
610,543!
478
    (*ppEntry)->name = tstrdup(pEntry->name);
610,576✔
479
    if (NULL == (*ppEntry)->name) {
610,463!
480
      code = terrno;
×
481
      metaCloneEntryFree(ppEntry);
×
482
      return code;
×
483
    }
484
  }
485

486
  if (pEntry->type == TSDB_SUPER_TABLE) {
610,441✔
487
    (*ppEntry)->flags = pEntry->flags;
560,834✔
488

489
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
560,834✔
490
    if (code) {
560,770!
491
      metaCloneEntryFree(ppEntry);
×
492
      return code;
×
493
    }
494

495
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
560,770✔
496
    if (code) {
560,764!
497
      metaCloneEntryFree(ppEntry);
×
498
      return code;
×
499
    }
500
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
560,778✔
501
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
49,607✔
502
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
34,648✔
503
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
34,648✔
504
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
34,648✔
505

506
    // comment
507
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
34,648✔
508
    if (pEntry->ctbEntry.commentLen > 0) {
34,648✔
509
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
510
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
511
        code = terrno;
×
512
        metaCloneEntryFree(ppEntry);
×
513
        return code;
×
514
      }
515
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
516
    }
517

518
    // tags
519
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
34,648✔
520
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
34,648!
521
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
34,650!
522
      code = terrno;
×
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
34,650✔
527
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,959!
528
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,959✔
529
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,959✔
530
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,959✔
531

532
    // schema
533
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,959✔
534
    if (code) {
14,959!
535
      metaCloneEntryFree(ppEntry);
×
536
      return code;
×
537
    }
538

539
    // comment
540
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,959✔
541
    if (pEntry->ntbEntry.commentLen > 0) {
14,959✔
542
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
49!
543
      if (NULL == (*ppEntry)->ntbEntry.comment) {
49!
544
        code = terrno;
×
545
        metaCloneEntryFree(ppEntry);
×
546
        return code;
×
547
      }
548
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
49✔
549
    }
550
  } else {
551
    return TSDB_CODE_INVALID_PARA;
×
552
  }
553

554
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
610,387✔
555
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
794✔
556
    if (code) {
762!
557
      metaCloneEntryFree(ppEntry);
×
558
      return code;
×
559
    }
560
  } else {
561
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
609,593✔
562
    if (code) {
609,810✔
563
      metaCloneEntryFree(ppEntry);
48✔
564
      return code;
×
565
    }
566
  }
567
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
610,524✔
568
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
16,855!
569
    if (!(*ppEntry)->pExtSchemas) {
16,855!
570
      code = terrno;
×
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
16,855✔
575
  }
576

577
  return code;
610,524✔
578
}
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