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

taosdata / TDengine / #4795

13 Oct 2025 06:50AM UTC coverage: 58.426% (+0.2%) from 58.201%
#4795

push

travis-ci

web-flow
Merge pull request #33213 from taosdata/fix/huoh/timemoe_model_directory

fix: fix tdgpt timemoe model directory

138954 of 303332 branches covered (45.81%)

Branch coverage included in aggregate %.

210571 of 294900 relevant lines covered (71.4%)

16934524.21 hits per line

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

67.03
/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) {
18,362,406✔
23
  for (int32_t i = 0; i < nCols; i++) {
434,096,007✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
415,810,089✔
25
      return true;
76,488✔
26
    }
27
  }
28
  return false;
18,285,918✔
29
}
30

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

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,240,188✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,426,918!
46
    }
47
  }
48
  return 0;
564,884✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
19,802✔
58
    SColRef *p = &pw->pColRef[i];
17,760✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
35,520!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
35,520!
61
    if (p->hasRef) {
17,760✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
20,548!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
20,548!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
20,548!
65
    }
66
  }
67
  return 0;
2,042✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
18,069,227✔
71
  bool hasExtSchema = false;
18,069,227✔
72
  SSchemaWrapper* pSchWrapper = NULL;
18,069,227✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
18,069,227!
74
    pSchWrapper = &pME->stbEntry.schemaRow;
18,130,679✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
×
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
756✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
18,131,435✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
18,250,024!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
54,083!
84
    if (pME->pExtSchemas == NULL) {
54,084!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
6,180,380✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
12,252,338!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
18,195,941✔
93
  }
94

95
  return 0;
18,250,279✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
130,201✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
130,201✔
100
  bool                  hasTypeMods = false;
130,201✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
130,201✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
90,225✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,976!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,007✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
130,232✔
109

110
  if (hasTypeMods) {
130,238✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
147!
112
    if (ret != NULL) {
130!
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
130✔
114
    }
115
    return ret;
130✔
116
  }
117
  return NULL;
130,091✔
118
}
119

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
34✔
151
  int32_t    i = 0, j = 0;
34✔
152
  for (i = 0; i < nCols; ++i) {
263✔
153
    while (j < pParam->nFuncs) {
418✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
401✔
155
        pFuncIds[i] = pParam->funcIds[j];
187✔
156
        break;
187✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
214✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
42✔
160
        break;
42✔
161
      }
162
      ++j;
172✔
163
    }
164
    if (j >= pParam->nFuncs) {
246✔
165
      for (; i < nCols; ++i) {
34✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
17✔
167
      }
168
      break;
17✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
34✔
172

173
  return 0;
34✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
18,336✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
18,336✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
36,673!
179
  if (pWrapper->nCols == 0) {
18,337!
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
36,676!
184
  uDebug("decode cols:%d", pWrapper->nCols);
18,339✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
18,339!
186
  if (pWrapper->pColRef == NULL) {
18,344!
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
272,808✔
191
    SColRef *p = &pWrapper->pColRef[i];
254,492✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
508,889!
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
508,807!
194
    if (p->hasRef) {
254,410✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
146,737!
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
146,825!
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
146,806!
198
    }
199
  }
200
  return 0;
18,316✔
201
}
202

203
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
204
                                                            SSchemaWrapper *pSchema) {
205
  pRef->nCols = pSchema->nCols;
×
206
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
207
    return terrno;
×
208
  }
209

210
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
211
    SColRef  *pColRef = &pRef->pColRef[i];
×
212
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
213
    pColRef->id = pColSchema->colId;
×
214
    pColRef->hasRef = false;
×
215
  }
216
  return 0;
×
217
}
218

219
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
1,082✔
220
  if (pSrc->nCols > 0) {
1,082!
221
    pDst->nCols = pSrc->nCols;
1,082✔
222
    pDst->version = pSrc->version;
1,082✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,082!
224
    if (NULL == pDst->pColRef) {
1,082!
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,082✔
228
  }
229
  return 0;
1,082✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
118,435✔
233
  int32_t code = 0;
118,435✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
236,870!
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
236,870!
236
  uTrace("encode cols:%d", pw->nCols);
118,435✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
23,450,893✔
239
    SColCmpr *p = &pw->pColCmpr[i];
23,332,437✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
46,664,874!
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
46,664,874!
242
  }
243
  return code;
118,456✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
118,326✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
118,326✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
118,326✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
20,298,524✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
20,298,524✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
40,489,107!
252
  if (pWrapper->nCols == 0) {
20,190,583!
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
40,364,661!
257
  uDebug("dencode cols:%d", pWrapper->nCols);
20,174,078✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
20,174,078✔
259
  if (pWrapper->pColCmpr == NULL) {
20,308,290!
260
    return terrno;
×
261
  }
262

263
  for (int i = 0; i < pWrapper->nCols; i++) {
442,562,525✔
264
    SColCmpr *p = &pWrapper->pColCmpr[i];
423,616,716✔
265
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
847,720,229!
266
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
846,357,748!
267
  }
268
  return 0;
18,945,809✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
×
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,552!
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,258✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,258✔
287
    pColCmpr->id = pColSchema->colId;
1,258✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,258✔
289
  }
290
  return 0;
294✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
507,635✔
294
  if (pSrc->nCols > 0) {
507,635✔
295
    pDst->nCols = pSrc->nCols;
460,384✔
296
    pDst->version = pSrc->version;
460,384✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
460,384!
298
    if (NULL == pDst->pColCmpr) {
460,481!
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
460,481✔
302
  }
303
  return 0;
507,732✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
508,805✔
307
  if (pColRef) {
508,805!
308
    taosMemoryFreeClear(pColRef->pColRef);
508,836!
309
  }
310
}
508,805✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
508,743✔
313
  if (pCmpr) {
508,743!
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
508,788!
315
  }
316
}
508,787✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
602,533✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
602,533✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,206,092!
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,206,092!
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,206,092!
323

324
  if (pME->type > 0) {
603,046✔
325
    if (pME->name == NULL) {
565,374!
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,130,748!
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
565,374✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
171,796!
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
171,796!
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
171,796!
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
85,898✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
96!
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
479,476✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
891,184!
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
891,184!
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
891,184!
342
      if (pME->ctbEntry.commentLen > 0) {
445,592✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
44!
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
891,184!
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
445,592!
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
33,884!
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
67,768!
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
67,768!
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
67,768!
351
      if (pME->ntbEntry.commentLen > 0) {
33,884✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
108!
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
67,768!
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
67,768!
356
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
357
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
358
    } else {
359
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
360
      return TSDB_CODE_INVALID_PARA;
×
361
    }
362
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
565,394✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,139!
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
563,255✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
85,773✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
477,482✔
368
        if (pME->colCmpr.nCols != 0) {
32,862✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
32,568!
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
294!
372
          SColCmprWrapper colCmprs = {0};
294✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
294!
374
          if (code != 0) {
294!
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
294✔
379
          taosMemoryFree(colCmprs.pColCmpr);
294!
380
          TAOS_CHECK_RETURN(code);
294!
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
565,168!
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
602,960✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
171,664!
388
  }
389

390
  tEndEncode(pCoder);
602,960✔
391
  return 0;
602,921✔
392
}
393

394
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
29,382,672✔
395
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
29,382,672!
396
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
58,511,080!
397
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
57,938,757!
398
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
57,594,486!
399

400
  if (headerOnly) {
28,760,634✔
401
    tEndDecode(pCoder);
90,234✔
402
    return 0;
90,234✔
403
  }
404

405
  if (pME->type > 0) {
28,670,400!
406
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
58,100,193!
407

408
    if (pME->type == TSDB_SUPER_TABLE) {
29,279,935✔
409
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
36,290,396!
410
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
33,636,134!
411
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
34,048,945!
412
      if (TABLE_IS_ROLLUP(pME->flags)) {
18,491,348✔
413
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
365!
414
      }
415
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,068,076✔
416
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
17,949,321!
417
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
17,920,848!
418
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
17,921,262!
419
      if (pME->ctbEntry.commentLen > 0) {
8,975,071✔
420
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
76!
421
      }
422
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
17,940,935!
423
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
8,965,864✔
424
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,093,412!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,184,040!
426
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,179,883!
427
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,180,006!
428
      if (pME->ntbEntry.commentLen > 0) {
2,090,751✔
429
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
190!
430
      }
431
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,180,946!
432
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,201,320!
433
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
434
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
435
      if (!pME->smaEntry.tsma) {
×
436
        return terrno;
×
437
      }
438
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
439
    } else {
440
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
441
      return TSDB_CODE_INVALID_PARA;
×
442
    }
443
    if (pME->type == TSDB_SUPER_TABLE) {
29,324,443✔
444
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
18,215,319!
445
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
18,223,260!
446

447
        if (pME->colCmpr.nCols == 0) {
18,078,037!
448
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
449
        }
450
      } else {
451
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
453
      }
454
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,109,124✔
455
      if (!tDecodeIsEnd(pCoder)) {
2,088,975✔
456
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,088,959✔
457
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,088,959✔
458
        if (pME->colCmpr.nCols == 0) {
2,085,904!
459
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
460
        }
461
      } else {
462
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
16!
463
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
464
      }
465
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,085,904✔
466
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
9,020,149✔
467
      if (!tDecodeIsEnd(pCoder)) {
18,336!
468
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
18,336✔
469
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
18,336!
470
      } else {
471
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
472
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
473
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
474
        }
475
      }
476
    }
477
    if (!tDecodeIsEnd(pCoder)) {
29,021,043✔
478
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
18,076,708!
479
    } else {
480
      pME->pExtSchemas = NULL;
10,944,335✔
481
    }
482
  }
483
  if (pME->type == TSDB_SUPER_TABLE) {
29,039,943✔
484
    if (!tDecodeIsEnd(pCoder)) {
18,233,601!
485
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
36,375,234!
486
    }
487
  }
488

489

490
  tEndDecode(pCoder);
28,922,391✔
491
  return 0;
29,120,158✔
492
}
493

494
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
29,275,798✔
495

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

501
  pDst->nCols = pSrc->nCols;
907,480✔
502
  pDst->version = pSrc->version;
907,480✔
503
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
907,480!
504
  if (pDst->pSchema == NULL) {
907,484!
505
    return terrno;
×
506
  }
507
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
907,484✔
508
  return TSDB_CODE_SUCCESS;
907,484✔
509
}
510

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

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

539
  return TSDB_CODE_SUCCESS;
54✔
540
}
541

542
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
907,464✔
543
  if (pSchema) {
907,464!
544
    taosMemoryFreeClear(pSchema->pSchema);
907,485!
545
  }
546
}
907,666✔
547

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

561
void metaCloneEntryFree(SMetaEntry **ppEntry) {
508,825✔
562
  if (ppEntry == NULL || *ppEntry == NULL) {
508,825!
563
    return;
76✔
564
  }
565

566
  taosMemoryFreeClear((*ppEntry)->name);
508,749!
567

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

573
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
508,778✔
574
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
446,515✔
575
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
446,559✔
576
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
446,616✔
577
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
83✔
578
    }
579
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,263✔
580
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,659!
581
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,659!
582
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,604!
583
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,604✔
584
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,604!
585
  } else {
586
    return;
×
587
  }
588
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
508,887✔
589
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
508,821!
590
  metaCloneColRefFree(&(*ppEntry)->colRef);
508,823✔
591

592
  taosMemoryFreeClear(*ppEntry);
508,818!
593
  return;
508,886✔
594
}
595

596
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
508,595✔
597
  int32_t code = TSDB_CODE_SUCCESS;
508,595✔
598

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

603
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
508,640!
604
  if (NULL == *ppEntry) {
508,838!
605
    return terrno;
×
606
  }
607

608
  (*ppEntry)->version = pEntry->version;
508,838✔
609
  (*ppEntry)->type = pEntry->type;
508,838✔
610
  (*ppEntry)->uid = pEntry->uid;
508,838✔
611

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

616
  if (pEntry->name) {
508,838!
617
    (*ppEntry)->name = tstrdup(pEntry->name);
508,846✔
618
    if (NULL == (*ppEntry)->name) {
508,790!
619
      code = terrno;
×
620
      metaCloneEntryFree(ppEntry);
×
621
      return code;
×
622
    }
623
  }
624

625
  if (pEntry->type == TSDB_SUPER_TABLE) {
508,823✔
626
    (*ppEntry)->flags = pEntry->flags;
446,581✔
627

628
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
446,581✔
629
    if (code) {
446,507!
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633

634
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
446,507✔
635
    if (code) {
446,525!
636
      metaCloneEntryFree(ppEntry);
×
637
      return code;
×
638
    }
639
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
446,525✔
640
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
54✔
641
      if (code) {
54✔
642
        metaCloneEntryFree(ppEntry);
36✔
643
        return code;
×
644
      }
645
    }
646
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
446,489✔
647
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,242✔
648
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,638✔
649
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,638✔
650
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,638✔
651

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

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

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

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

700
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
508,724✔
701
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,073✔
702
    if (code) {
1,082!
703
      metaCloneEntryFree(ppEntry);
×
704
      return code;
×
705
    }
706
  } else {
707
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
507,651✔
708
    if (code) {
507,749✔
709
      metaCloneEntryFree(ppEntry);
47✔
710
      return code;
×
711
    }
712
  }
713
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
508,784!
714
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
24,267!
715
    if (!(*ppEntry)->pExtSchemas) {
24,268!
716
      code = terrno;
×
717
      metaCloneEntryFree(ppEntry);
×
718
      return code;
×
719
    }
720
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
24,268✔
721
  }
722

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

© 2026 Coveralls, Inc