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

taosdata / TDengine / #4623

30 Jul 2025 02:24AM UTC coverage: 60.377% (-0.8%) from 61.137%
#4623

push

travis-ci

web-flow
docs: add example cases for datatype tests in cases.task (#32379)

138520 of 291367 branches covered (47.54%)

Branch coverage included in aggregate %.

208789 of 283863 relevant lines covered (73.55%)

18031536.81 hits per line

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

65.47
/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) {
19,894,275✔
23
  for (int32_t i = 0; i < nCols; i++) {
467,712,069✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
447,898,260✔
25
      return true;
80,466✔
26
    }
27
  }
28
  return false;
19,813,809✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
671,864✔
32
  if (pME->pExtSchemas) {
671,864✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
27,008✔
34
    bool                  hasTypeMods = false;
27,008✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
27,008✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,857✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
151!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
154✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
27,011✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,542,722✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
11,031,420!
46
    }
47
  }
48
  return 0;
671,868✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
16,492✔
58
    SColRef *p = &pw->pColRef[i];
14,884✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
29,768!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
29,768!
61
    if (p->hasRef) {
14,884✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
16,932!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
16,932!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
16,932!
65
    }
66
  }
67
  return 0;
1,608✔
68
}
69

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

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
19,696,083✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
19,782,939!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
57,946!
84
    if (pME->pExtSchemas == NULL) {
57,951!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,303,077✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
14,490,174!
90
    }
91
  }
92

93
  return 0;
19,783,022✔
94
}
95

96
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
132,695✔
97
  const SSchemaWrapper *pSchWrapper = NULL;
132,695✔
98
  bool                  hasTypeMods = false;
132,695✔
99
  if (pME->type == TSDB_SUPER_TABLE) {
132,695✔
100
    pSchWrapper = &pME->stbEntry.schemaRow;
92,721✔
101
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,974!
102
    pSchWrapper = &pME->ntbEntry.schemaRow;
39,984✔
103
  } else {
104
    return NULL;
×
105
  }
106
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
132,705✔
107

108
  if (hasTypeMods) {
132,714✔
109
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
73!
110
    if (ret != NULL) {
70!
111
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
70✔
112
    }
113
    return ret;
70✔
114
  }
115
  return NULL;
132,641✔
116
}
117

118
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
5,090✔
119
  SColRefWrapper *pWrapper = &pME->colRef;
5,090✔
120
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
10,180!
121
  if (pWrapper->nCols == 0) {
5,090!
122
    return 0;
×
123
  }
124

125
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
10,180!
126
  uDebug("decode cols:%d", pWrapper->nCols);
5,090!
127
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
5,090!
128
  if (pWrapper->pColRef == NULL) {
5,088!
129
    return terrno;
×
130
  }
131

132
  for (int i = 0; i < pWrapper->nCols; i++) {
67,313✔
133
    SColRef *p = &pWrapper->pColRef[i];
62,255✔
134
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
124,463!
135
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
124,424!
136
    if (p->hasRef) {
62,216✔
137
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
33,796!
138
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
33,783!
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
33,880✔
140
    }
141
  }
142
  return 0;
5,058✔
143
}
144

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

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

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

174
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
144,851✔
175
  int32_t code = 0;
144,851✔
176
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
289,702!
177
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
289,702!
178
  uTrace("encode cols:%d", pw->nCols);
144,851✔
179

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,628,930✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,484,148✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,968,296!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,968,296!
184
  }
185
  return code;
144,782✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
144,548✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
144,548✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
144,548✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,987,335✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,987,335✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
43,866,448!
194
  if (pWrapper->nCols == 0) {
21,879,113!
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
43,754,376!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
21,875,263✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,875,339✔
201
  if (pWrapper->pColCmpr == NULL) {
22,011,843!
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
485,117,694✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
463,933,554✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
923,052,837!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
922,225,134!
209
  }
210
  return 0;
21,184,140✔
211
}
212
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
213
                                                            SSchemaWrapper *pSchema) {
214
  pCmpr->nCols = pSchema->nCols;
×
215

216
  if (pDecoder == NULL) {
×
217
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
338!
218
  } else {
219
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
220
  }
221

222
  if (pCmpr->pColCmpr == NULL) {
338!
223
    return terrno;
×
224
  }
225

226
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,536!
227
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,198✔
228
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,198✔
229
    pColCmpr->id = pColSchema->colId;
1,198✔
230
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,198✔
231
  }
232
  return 0;
338✔
233
}
234

235
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
594,278✔
236
  if (pSrc->nCols > 0) {
594,278✔
237
    pDst->nCols = pSrc->nCols;
545,015✔
238
    pDst->version = pSrc->version;
545,015✔
239
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
545,015!
240
    if (NULL == pDst->pColCmpr) {
545,177!
241
      return terrno;
×
242
    }
243
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
545,177✔
244
  }
245
  return 0;
594,440✔
246
}
247

248
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
595,211✔
249
  if (pColRef) {
595,211!
250
    taosMemoryFreeClear(pColRef->pColRef);
595,219!
251
  }
252
}
595,211✔
253

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
595,128✔
255
  if (pCmpr) {
595,128!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
595,176!
257
  }
258
}
595,210✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
710,136✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
710,136✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,422,598!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,422,598!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,422,598!
265

266
  if (pME->type > 0) {
711,299✔
267
    if (pME->name == NULL) {
672,145!
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,344,290!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
672,145✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
204,036!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
204,036!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
204,036!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
102,018✔
278
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
8!
279
      }
280
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
570,127✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
1,052,694!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
1,052,694!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
1,052,694!
284
      if (pME->ctbEntry.commentLen > 0) {
526,347✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
1,052,694!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
526,347!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
43,780!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
87,560!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
87,560!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
87,560!
293
      if (pME->ntbEntry.commentLen > 0) {
43,780✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
76!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
87,560!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
87,560!
298
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
299
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
300
    } else {
301
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
302
      return TSDB_CODE_INVALID_PARA;
×
303
    }
304
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
672,028!
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,487!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
670,541!
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
102,140✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
568,401✔
310
        if (pME->colCmpr.nCols != 0) {
42,778✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
42,440!
312
        } else {
313
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
338!
314
          SColCmprWrapper colCmprs = {0};
338✔
315
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
338!
316
          if (code != 0) {
338!
317
            taosMemoryFree(colCmprs.pColCmpr);
×
318
            TAOS_CHECK_RETURN(code);
×
319
          }
320
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
338✔
321
          taosMemoryFree(colCmprs.pColCmpr);
338!
322
          TAOS_CHECK_RETURN(code);
338!
323
        }
324
      }
325
    }
326
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
671,758!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
711,026✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
203,752!
330
  }
331

332
  tEndEncode(pCoder);
711,026✔
333
  return 0;
710,886✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
33,122,889✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
33,122,889!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
66,096,561!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
65,646,752!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
65,399,667!
341

342
  if (headerOnly) {
32,654,071✔
343
    tEndDecode(pCoder);
88,314✔
344
    return 0;
88,314✔
345
  }
346

347
  if (pME->type > 0) {
32,565,757!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
65,749,704!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
33,045,711✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
39,383,274!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
37,647,096!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
37,349,058!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,331,421✔
355
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
36!
356
      }
357
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
13,291,896✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
22,097,759!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
22,083,941!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
22,076,147!
361
      if (pME->ctbEntry.commentLen > 0) {
11,044,915✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
22,086,988!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
11,042,073!
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,246,846!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,490,869!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,487,119!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,486,017!
370
      if (pME->ntbEntry.commentLen > 0) {
2,242,921✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
218!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,486,113!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,458,837!
375
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
376
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
377
      if (!pME->smaEntry.tsma) {
×
378
        return terrno;
×
379
      }
380
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
381
    } else {
382
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
383
      return TSDB_CODE_INVALID_PARA;
×
384
    }
385
    if (pME->type == TSDB_SUPER_TABLE) {
33,075,925✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,740,259!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,751,296!
388

389
        if (pME->colCmpr.nCols == 0) {
19,645,417!
390
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
391
        }
392
      } else {
393
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
394
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
395
      }
396
    } else if (pME->type == TSDB_NORMAL_TABLE) {
13,335,666✔
397
      if (!tDecodeIsEnd(pCoder)) {
2,245,230!
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,245,498✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,245,500✔
400
        if (pME->colCmpr.nCols == 0) {
2,242,694!
401
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
402
        }
403
      } else {
404
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
405
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
406
      }
407
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,242,694✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,090,436!
409
      if (!tDecodeIsEnd(pCoder)) {
5,090!
410
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
5,090!
411
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
5,090!
412
      } else {
413
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
414
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
415
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
416
        }
417
      }
418
    }
419
    if (!tDecodeIsEnd(pCoder)) {
32,836,615✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
19,643,115!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
32,833,864✔
424
    if (!tDecodeIsEnd(pCoder)) {
19,779,122!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
39,449,276!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
32,722,032✔
431
  return 0;
32,893,291✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
33,043,163✔
435

436
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
1,076,349✔
437
  if (pSrc == NULL || pDst == NULL) {
1,076,349!
438
    return TSDB_CODE_INVALID_PARA;
×
439
  }
440

441
  pDst->nCols = pSrc->nCols;
1,076,451✔
442
  pDst->version = pSrc->version;
1,076,451✔
443
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
1,076,451!
444
  if (pDst->pSchema == NULL) {
1,076,530!
445
    return terrno;
×
446
  }
447
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
1,076,530✔
448
  return TSDB_CODE_SUCCESS;
1,076,530✔
449
}
450

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
1,076,567✔
452
  if (pSchema) {
1,076,567!
453
    taosMemoryFreeClear(pSchema->pSchema);
1,076,587!
454
  }
455
}
1,076,690✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
595,242✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
595,242!
459
    return;
52✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
595,190!
463

464
  if ((*ppEntry)->type < 0) {
595,216!
465
    taosMemoryFreeClear(*ppEntry);
×
466
    return;
×
467
  }
468

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
595,216✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
530,978✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
531,029✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
64,238✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
49,380!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
49,380!
475
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,858!
476
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,858✔
477
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,858!
478
  } else {
479
    return;
×
480
  }
481
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
595,198✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
595,217!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
595,218✔
484

485
  taosMemoryFreeClear(*ppEntry);
595,211!
486
  return;
595,282✔
487
}
488

489
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
594,970✔
490
  int32_t code = TSDB_CODE_SUCCESS;
594,970✔
491

492
  if (NULL == pEntry || NULL == ppEntry) {
594,970!
493
    return TSDB_CODE_INVALID_PARA;
×
494
  }
495

496
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
595,038!
497
  if (NULL == *ppEntry) {
595,257!
498
    return terrno;
×
499
  }
500

501
  (*ppEntry)->version = pEntry->version;
595,257✔
502
  (*ppEntry)->type = pEntry->type;
595,257✔
503
  (*ppEntry)->uid = pEntry->uid;
595,257✔
504

505
  if (pEntry->type < 0) {
595,257!
506
    return TSDB_CODE_SUCCESS;
×
507
  }
508

509
  if (pEntry->name) {
595,257✔
510
    (*ppEntry)->name = tstrdup(pEntry->name);
595,253✔
511
    if (NULL == (*ppEntry)->name) {
595,194!
512
      code = terrno;
×
513
      metaCloneEntryFree(ppEntry);
×
514
      return code;
×
515
    }
516
  }
517

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
595,206✔
519
    (*ppEntry)->flags = pEntry->flags;
530,967✔
520

521
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
530,967✔
522
    if (code) {
530,883!
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
530,883✔
528
    if (code) {
530,904!
529
      metaCloneEntryFree(ppEntry);
×
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
530,930✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
64,239✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
49,381✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
49,381✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
49,381✔
537

538
    // comment
539
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
49,381✔
540
    if (pEntry->ctbEntry.commentLen > 0) {
49,381✔
541
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
542
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
543
        code = terrno;
×
544
        metaCloneEntryFree(ppEntry);
×
545
        return code;
×
546
      }
547
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
548
    }
549

550
    // tags
551
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
49,381✔
552
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
49,381!
553
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
49,381!
554
      code = terrno;
×
555
      metaCloneEntryFree(ppEntry);
×
556
      return code;
×
557
    }
558
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
49,381✔
559
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,858!
560
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,858✔
561
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,858✔
562
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,858✔
563

564
    // schema
565
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,858✔
566
    if (code) {
14,858!
567
      metaCloneEntryFree(ppEntry);
×
568
      return code;
×
569
    }
570

571
    // comment
572
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,858✔
573
    if (pEntry->ntbEntry.commentLen > 0) {
14,858✔
574
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
25!
575
      if (NULL == (*ppEntry)->ntbEntry.comment) {
25!
576
        code = terrno;
×
577
        metaCloneEntryFree(ppEntry);
×
578
        return code;
×
579
      }
580
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
25✔
581
    }
582
  } else {
583
    return TSDB_CODE_INVALID_PARA;
×
584
  }
585

586
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
595,169✔
587
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
857✔
588
    if (code) {
796!
589
      metaCloneEntryFree(ppEntry);
×
590
      return code;
×
591
    }
592
  } else {
593
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
594,312✔
594
    if (code) {
594,444✔
595
      metaCloneEntryFree(ppEntry);
29✔
596
      return code;
×
597
    }
598
  }
599
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
595,211!
600
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,797!
601
    if (!(*ppEntry)->pExtSchemas) {
23,796!
602
      code = terrno;
×
603
      metaCloneEntryFree(ppEntry);
×
604
      return code;
×
605
    }
606
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,796✔
607
  }
608

609
  return code;
595,210✔
610
}
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