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

taosdata / TDengine / #4609

28 Jul 2025 03:45AM UTC coverage: 60.413% (-0.7%) from 61.072%
#4609

push

travis-ci

web-flow
merge: from 3.3.6 to main branch #32314 

Merge/3.3.6tomain

138583 of 291345 branches covered (47.57%)

Branch coverage included in aggregate %.

79 of 97 new or added lines in 12 files covered. (81.44%)

9880 existing lines in 148 files now uncovered.

208900 of 283831 relevant lines covered (73.6%)

18073489.5 hits per line

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

66.63
/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,683,870✔
23
  for (int32_t i = 0; i < nCols; i++) {
463,153,781✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
443,556,400✔
25
      return true;
86,489✔
26
    }
27
  }
28
  return false;
19,597,381✔
29
}
30

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

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,464,878✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,875,812!
46
    }
47
  }
48
  return 0;
669,047✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
15,234✔
58
    SColRef *p = &pw->pColRef[i];
13,700✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
27,400!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
27,400!
61
    if (p->hasRef) {
13,700✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
14,880!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
14,880!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
14,880!
65
    }
66
  }
67
  return 0;
1,534✔
68
}
69

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

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
19,415,658✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
19,572,158✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
64,028!
84
    if (pME->pExtSchemas == NULL) {
64,033!
UNCOV
85
      return terrno;
×
86
    }
87

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

93
  return 0;
19,572,375✔
94
}
95

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

108
  if (hasTypeMods) {
130,771✔
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;
130,698✔
116
}
117

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

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

132
  for (int i = 0; i < pWrapper->nCols; i++) {
61,202✔
133
    SColRef *p = &pWrapper->pColRef[i];
56,485✔
134
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
112,932!
135
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
112,886!
136
    if (p->hasRef) {
56,439✔
137
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
28,521!
138
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
28,547!
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
28,588✔
140
    }
141
  }
142
  return 0;
4,717✔
143
}
144

145
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
146
                                                            SSchemaWrapper *pSchema) {
UNCOV
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++) {
×
UNCOV
153
    SColRef  *pColRef = &pRef->pColRef[i];
×
154
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
UNCOV
155
    pColRef->id = pColSchema->colId;
×
UNCOV
156
    pColRef->hasRef = false;
×
157
  }
UNCOV
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!
UNCOV
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) {
143,637✔
175
  int32_t code = 0;
143,637✔
176
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
287,274!
177
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
287,274!
178
  uTrace("encode cols:%d", pw->nCols);
143,637✔
179

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,435,279✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,291,654✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,583,308!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,583,308!
184
  }
185
  return code;
143,625✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
143,317✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
143,317✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
143,317✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,733,728✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,733,728✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
43,340,580!
194
  if (pWrapper->nCols == 0) {
21,606,852!
UNCOV
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
43,222,441!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
21,615,589✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,615,677✔
201
  if (pWrapper->pColCmpr == NULL) {
21,751,641!
UNCOV
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
472,568,446✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
452,235,556✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
904,064,315!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
902,645,564!
209
  }
210
  return 0;
20,332,890✔
211
}
212
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
213
                                                            SSchemaWrapper *pSchema) {
UNCOV
214
  pCmpr->nCols = pSchema->nCols;
×
215

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

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

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

235
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
592,786✔
236
  if (pSrc->nCols > 0) {
592,786✔
237
    pDst->nCols = pSrc->nCols;
543,483✔
238
    pDst->version = pSrc->version;
543,483✔
239
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
543,483!
240
    if (NULL == pDst->pColCmpr) {
543,603!
UNCOV
241
      return terrno;
×
242
    }
243
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
543,603✔
244
  }
245
  return 0;
592,906✔
246
}
247

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

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
593,662✔
255
  if (pCmpr) {
593,662!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
593,683!
257
  }
258
}
593,722✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
707,059✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
707,059✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,417,060!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,417,060!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,417,060!
265

266
  if (pME->type > 0) {
708,530✔
267
    if (pME->name == NULL) {
669,375!
UNCOV
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,338,750!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
669,375✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
202,078!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
202,078!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
202,078!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
101,039✔
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) {
568,336✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
1,049,476!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
1,049,476!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
1,049,476!
284
      if (pME->ctbEntry.commentLen > 0) {
524,738✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
1,049,476!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
524,738!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
43,598!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
87,196!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
87,196!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
87,196!
293
      if (pME->ntbEntry.commentLen > 0) {
43,598✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
76!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
87,196!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
87,196!
UNCOV
298
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
UNCOV
299
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
300
    } else {
UNCOV
301
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
UNCOV
302
      return TSDB_CODE_INVALID_PARA;
×
303
    }
304
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
669,294!
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,425!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
667,869✔
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
101,178✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
566,691✔
310
        if (pME->colCmpr.nCols != 0) {
42,602✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
42,232!
312
        } else {
313
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
370!
314
          SColCmprWrapper colCmprs = {0};
370✔
315
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
370!
316
          if (code != 0) {
370!
UNCOV
317
            taosMemoryFree(colCmprs.pColCmpr);
×
UNCOV
318
            TAOS_CHECK_RETURN(code);
×
319
          }
320
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
370✔
321
          taosMemoryFree(colCmprs.pColCmpr);
370!
322
          TAOS_CHECK_RETURN(code);
370!
323
        }
324
      }
325
    }
326
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
669,013!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
708,143✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
201,530!
330
  }
331

332
  tEndEncode(pCoder);
708,143✔
333
  return 0;
707,962✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
32,618,981✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
32,618,981!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
64,990,304!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
64,415,849!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
64,131,295!
341

342
  if (headerOnly) {
32,049,439✔
343
    tEndDecode(pCoder);
88,300✔
344
    return 0;
88,300✔
345
  }
346

347
  if (pME->type > 0) {
31,961,139!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
64,582,274!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
32,517,020✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
38,939,120!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
36,217,546!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
36,608,261!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,798,163✔
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) {
12,985,348✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
21,538,918!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
21,522,016!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
21,519,607!
361
      if (pME->ctbEntry.commentLen > 0) {
10,768,504✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
21,531,576!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
10,763,072✔
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,217,343!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,431,682!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,427,221!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,426,625!
370
      if (pME->ntbEntry.commentLen > 0) {
2,213,743✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
218!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,427,287!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,404,840!
UNCOV
375
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
UNCOV
376
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
UNCOV
377
      if (!pME->smaEntry.tsma) {
×
UNCOV
378
        return terrno;
×
379
      }
UNCOV
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) {
32,550,152✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,521,430!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,530,180!
388

389
        if (pME->colCmpr.nCols == 0) {
19,404,919!
UNCOV
390
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
391
        }
392
      } else {
UNCOV
393
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
UNCOV
394
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
395
      }
396
    } else if (pME->type == TSDB_NORMAL_TABLE) {
13,028,722✔
397
      if (!tDecodeIsEnd(pCoder)) {
2,216,451✔
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,216,153✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,216,154✔
400
        if (pME->colCmpr.nCols == 0) {
2,213,310!
UNCOV
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);
298!
UNCOV
405
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
406
      }
407
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,213,310✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
10,812,271!
409
      if (!tDecodeIsEnd(pCoder)) {
4,730!
410
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,730!
411
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,730!
412
      } else {
413
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
414
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
UNCOV
415
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
416
        }
417
      }
418
    }
419
    if (!tDecodeIsEnd(pCoder)) {
32,274,225✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
19,402,822!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
32,332,515✔
424
    if (!tDecodeIsEnd(pCoder)) {
19,555,560!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
39,010,547!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
32,213,284✔
431
  return 0;
32,350,997✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
32,503,820✔
435

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

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

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
1,073,491✔
452
  if (pSchema) {
1,073,491!
453
    taosMemoryFreeClear(pSchema->pSchema);
1,073,513!
454
  }
455
}
1,073,577✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
593,744✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
593,744!
459
    return;
88✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
593,656!
463

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

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
593,694✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
529,384✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
529,431✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
64,310✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
49,436!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
49,436!
475
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,874!
476
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,874✔
477
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,874!
478
  } else {
UNCOV
479
    return;
×
480
  }
481
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
593,763✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
593,724!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
593,728✔
484

485
  taosMemoryFreeClear(*ppEntry);
593,730!
486
  return;
593,758✔
487
}
488

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

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

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

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

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

509
  if (pEntry->name) {
593,718!
510
    (*ppEntry)->name = tstrdup(pEntry->name);
593,735✔
511
    if (NULL == (*ppEntry)->name) {
593,660✔
512
      code = terrno;
1✔
513
      metaCloneEntryFree(ppEntry);
×
UNCOV
514
      return code;
×
515
    }
516
  }
517

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
593,642✔
519
    (*ppEntry)->flags = pEntry->flags;
529,355✔
520

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

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
529,329✔
528
    if (code) {
529,331✔
529
      metaCloneEntryFree(ppEntry);
10✔
UNCOV
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
529,321✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
64,287✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
49,413✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
49,413✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
49,413✔
537

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

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

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

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

609
  return code;
593,646✔
610
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc