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

taosdata / TDengine / #4676

18 Aug 2025 07:58AM UTC coverage: 60.007% (+0.1%) from 59.866%
#4676

push

travis-ci

web-flow
test: update case desc (#32551)

137637 of 292075 branches covered (47.12%)

Branch coverage included in aggregate %.

208283 of 284395 relevant lines covered (73.24%)

14871103.77 hits per line

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

64.99
/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) {
20,438,807✔
23
  for (int32_t i = 0; i < nCols; i++) {
490,597,785✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
470,249,324✔
25
      return true;
90,346✔
26
    }
27
  }
28
  return false;
20,348,461✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
606,973✔
32
  if (pME->pExtSchemas) {
606,973✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
26,630✔
34
    bool                  hasTypeMods = false;
26,630✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
26,630✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,447✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
183!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
184✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
26,631✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,347,604✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,641,942!
46
    }
47
  }
48
  return 0;
606,976✔
49
}
50

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

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

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

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
20,184,043✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
20,337,977!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
68,210!
84
    if (pME->pExtSchemas == NULL) {
68,230!
85
      return terrno;
×
86
    }
87

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

93
  return 0;
20,338,040✔
94
}
95

96
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
130,390✔
97
  const SSchemaWrapper *pSchWrapper = NULL;
130,390✔
98
  bool                  hasTypeMods = false;
130,390✔
99
  if (pME->type == TSDB_SUPER_TABLE) {
130,390✔
100
    pSchWrapper = &pME->stbEntry.schemaRow;
90,388✔
101
  } else if (pME->type == TSDB_NORMAL_TABLE) {
40,002!
102
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,025✔
103
  } else {
104
    return NULL;
×
105
  }
106
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
130,413✔
107

108
  if (hasTypeMods) {
130,418✔
109
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
144!
110
    if (ret != NULL) {
118!
111
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
118✔
112
    }
113
    return ret;
118✔
114
  }
115
  return NULL;
130,274✔
116
}
117

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

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

132
  for (int i = 0; i < pWrapper->nCols; i++) {
57,168✔
133
    SColRef *p = &pWrapper->pColRef[i];
53,135✔
134
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
106,222!
135
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
106,184!
136
    if (p->hasRef) {
53,097✔
137
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
26,264!
138
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
26,273!
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
26,323✔
140
    }
141
  }
142
  return 0;
4,033✔
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) {
764✔
162
  if (pSrc->nCols > 0) {
764!
163
    pDst->nCols = pSrc->nCols;
764✔
164
    pDst->version = pSrc->version;
764✔
165
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
764!
166
    if (NULL == pDst->pColRef) {
764!
167
      return terrno;
×
168
    }
169
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
764✔
170
  }
171
  return 0;
764✔
172
}
173

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

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,235,012✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,102,573✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,205,146!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,205,146!
184
  }
185
  return code;
132,439✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
132,369✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
132,369✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
132,369✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
22,990,277✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
22,990,277✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
45,819,788!
194
  if (pWrapper->nCols == 0) {
22,829,511!
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
45,650,145!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
22,820,634✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
22,820,665✔
201
  if (pWrapper->pColCmpr == NULL) {
23,023,641!
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
490,707,751✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
468,994,153✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
931,846,664!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
930,536,621!
209
  }
210
  return 0;
21,713,598✔
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));
330!
218
  } else {
219
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
220
  }
221

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

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

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

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

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
537,950✔
255
  if (pCmpr) {
537,950!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
537,978!
257
  }
258
}
538,013✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
645,596✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
645,596✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,292,998!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,292,998!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,292,998!
265

266
  if (pME->type > 0) {
646,499✔
267
    if (pME->name == NULL) {
607,955!
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,215,910!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
607,955✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
193,838!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
193,838!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
193,838!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
96,919!
278
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
279
      }
280
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
511,036✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
948,296!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
948,296!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
948,296!
284
      if (pME->ctbEntry.commentLen > 0) {
474,148✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
948,296!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
474,148!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
36,888!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
73,776!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
73,776!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
73,776!
293
      if (pME->ntbEntry.commentLen > 0) {
36,888✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
73,776!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
73,776!
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) {
607,929✔
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,628!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
606,301!
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
96,855✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
509,446✔
310
        if (pME->colCmpr.nCols != 0) {
35,932✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
35,602!
312
        } else {
313
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
330!
314
          SColCmprWrapper colCmprs = {0};
330✔
315
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
330!
316
          if (code != 0) {
330!
317
            taosMemoryFree(colCmprs.pColCmpr);
×
318
            TAOS_CHECK_RETURN(code);
×
319
          }
320
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
330✔
321
          taosMemoryFree(colCmprs.pColCmpr);
330!
322
          TAOS_CHECK_RETURN(code);
330!
323
        }
324
      }
325
    }
326
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
607,502!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
646,394✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
193,814!
330
  }
331

332
  tEndEncode(pCoder);
646,394✔
333
  return 0;
646,464✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
35,267,919✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
35,267,919!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
70,278,466!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
69,627,314!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
69,318,548!
341

342
  if (headerOnly) {
34,622,042✔
343
    tEndDecode(pCoder);
90,364✔
344
    return 0;
90,364✔
345
  }
346

347
  if (pME->type > 0) {
34,531,678!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
69,895,866!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
35,227,207✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
40,401,111!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
39,153,611!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
38,877,121!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,830,491!
355
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
356
      }
357
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
14,933,077✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
24,427,026!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
24,358,894!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
24,342,932!
361
      if (pME->ctbEntry.commentLen > 0) {
12,187,386✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
24,382,035!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
12,194,649!
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,709,399!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
5,414,078!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
5,405,976!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
5,404,198!
370
      if (pME->ntbEntry.commentLen > 0) {
2,702,901✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
5,406,414!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
5,374,460!
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) {
35,243,417✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
20,285,461!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
20,299,708!
388

389
        if (pME->colCmpr.nCols == 0) {
20,120,606!
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) {
14,957,956✔
397
      if (!tDecodeIsEnd(pCoder)) {
2,707,475!
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,707,817✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,707,819✔
400
        if (pME->colCmpr.nCols == 0) {
2,703,138!
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,703,138✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
12,250,481!
409
      if (!tDecodeIsEnd(pCoder)) {
4,030!
410
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,030!
411
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,030!
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)) {
34,857,017✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
20,121,841!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
34,935,176✔
424
    if (!tDecodeIsEnd(pCoder)) {
20,335,968!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
40,512,156!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
34,774,504✔
431
  return 0;
34,967,382✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
35,203,359✔
435

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

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

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
965,812✔
452
  if (pSchema) {
965,812!
453
    taosMemoryFreeClear(pSchema->pSchema);
965,827!
454
  }
455
}
965,965✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
538,027✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
538,027!
459
    return;
67✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
537,960!
463

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

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
537,971✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
475,605✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
475,659✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,366✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,580!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,580!
475
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,786!
476
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,786✔
477
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,786!
478
  } else {
479
    return;
×
480
  }
481
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
537,997✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
538,022!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
538,022✔
484

485
  taosMemoryFreeClear(*ppEntry);
538,011!
486
  return;
538,058✔
487
}
488

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

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

496
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
537,835!
497
  if (NULL == *ppEntry) {
538,025!
498
    return terrno;
×
499
  }
500

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

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

509
  if (pEntry->name) {
538,025!
510
    (*ppEntry)->name = tstrdup(pEntry->name);
538,030✔
511
    if (NULL == (*ppEntry)->name) {
537,931!
512
      code = terrno;
×
513
      metaCloneEntryFree(ppEntry);
×
514
      return code;
×
515
    }
516
  }
517

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
537,998✔
519
    (*ppEntry)->flags = pEntry->flags;
475,633✔
520

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

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
475,531✔
528
    if (code) {
475,545!
529
      metaCloneEntryFree(ppEntry);
×
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
475,564✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,365✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,579✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,579✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,579✔
537

538
    // comment
539
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
47,579✔
540
    if (pEntry->ctbEntry.commentLen > 0) {
47,579✔
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;
47,579✔
552
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
47,579!
553
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
47,580!
554
      code = terrno;
×
555
      metaCloneEntryFree(ppEntry);
×
556
      return code;
×
557
    }
558
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
47,580✔
559
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,786!
560
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,786✔
561
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,786✔
562
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,786✔
563

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

571
    // comment
572
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,786✔
573
    if (pEntry->ntbEntry.commentLen > 0) {
14,786✔
574
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
49!
575
      if (NULL == (*ppEntry)->ntbEntry.comment) {
49!
576
        code = terrno;
×
577
        metaCloneEntryFree(ppEntry);
×
578
        return code;
×
579
      }
580
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
49✔
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) {
537,930✔
587
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
810✔
588
    if (code) {
764!
589
      metaCloneEntryFree(ppEntry);
×
590
      return code;
×
591
    }
592
  } else {
593
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
537,120✔
594
    if (code) {
537,238✔
595
      metaCloneEntryFree(ppEntry);
40✔
596
      return code;
×
597
    }
598
  }
599
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
537,962!
600
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,679!
601
    if (!(*ppEntry)->pExtSchemas) {
23,675!
602
      code = terrno;
×
603
      metaCloneEntryFree(ppEntry);
×
604
      return code;
×
605
    }
606
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,675✔
607
  }
608

609
  return code;
537,958✔
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