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

taosdata / TDengine / #4908

30 Dec 2025 10:52AM UTC coverage: 65.386% (-0.2%) from 65.541%
#4908

push

travis-ci

web-flow
enh: drop multi-stream (#33962)

60 of 106 new or added lines in 4 files covered. (56.6%)

1330 existing lines in 113 files now uncovered.

193461 of 295877 relevant lines covered (65.39%)

115765274.47 hits per line

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

81.11
/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) {
987,306,930✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
26,729,543✔
26
    }
27
  }
28
  return false;
959,372,487✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
201,155,707✔
32
  if (pME->pExtSchemas) {
201,155,707✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,616,408✔
34
    bool                  hasTypeMods = false;
11,616,408✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,616,408✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,515,432✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
90,014✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
90,014✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,610,455✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,169,400,688✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
201,146,035✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
314,639,718✔
58
    SColRef *p = &pw->pColRef[i];
313,567,818✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
627,135,636✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
627,135,636✔
61
    if (p->hasRef) {
313,567,818✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
375,250,660✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
375,250,660✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
375,250,660✔
65
    }
66
  }
67
  return 0;
1,071,900✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
934,089,427✔
71
  bool hasExtSchema = false;
934,089,427✔
72
  SSchemaWrapper* pSchWrapper = NULL;
934,089,427✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
934,089,427✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
727,825,608✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
206,493,589✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
206,543,372✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
934,321,919✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
934,515,544✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
36,011,492✔
84
    if (pME->pExtSchemas == NULL) {
18,001,213✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
1,408,124,495✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
916,494,967✔
93
  }
94

95
  return 0;
934,514,625✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
41,670,575✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
41,670,575✔
100
  bool                  hasTypeMods = false;
41,670,575✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
41,670,575✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
30,126,980✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,567,082✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,557,514✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
41,689,333✔
109

110
  if (hasTypeMods) {
41,672,931✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
38,318✔
112
    if (ret != NULL) {
38,318✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
38,318✔
114
    }
115
    return ret;
38,318✔
116
  }
117
  return NULL;
41,634,613✔
118
}
119

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

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

131
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
26,172✔
132
  if (*rsmaSchema == NULL) {
26,172✔
133
    return terrno;
×
134
  }
135

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
26,172✔
151
  int32_t    i = 0, j = 0;
26,172✔
152
  for (i = 0; i < nCols; ++i) {
201,379✔
153
    while (j < pParam->nFuncs) {
318,426✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
306,067✔
155
        pFuncIds[i] = pParam->funcIds[j];
143,219✔
156
        break;
143,219✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
162,848✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,988✔
160
        break;
31,988✔
161
      }
162
      ++j;
130,860✔
163
    }
164
    if (j >= pParam->nFuncs) {
187,566✔
165
      for (; i < nCols; ++i) {
24,718✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,359✔
167
      }
168
      break;
12,359✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
26,172✔
172

173
  return 0;
26,172✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
5,065,524✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
5,065,524✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
10,131,048✔
179
  if (pWrapper->nCols == 0) {
5,065,524✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
10,131,048✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
5,065,524✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
10,130,236✔
186
  if (pWrapper->pColRef == NULL) {
5,064,712✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
264,316,897✔
191
    SColRef *p = &pWrapper->pColRef[i];
259,249,541✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
518,516,927✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
518,530,139✔
194
    if (p->hasRef) {
259,268,574✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
148,173,620✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
148,168,439✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
148,171,414✔
198
    }
199
  }
200
  return 0;
5,064,912✔
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) {
638,901✔
220
  if (pSrc->nCols > 0) {
638,901✔
221
    pDst->nCols = pSrc->nCols;
638,901✔
222
    pDst->version = pSrc->version;
638,901✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
638,901✔
224
    if (NULL == pDst->pColRef) {
638,901✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
638,901✔
228
  }
229
  return 0;
638,901✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
68,124,799✔
233
  int32_t code = 0;
68,124,799✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
136,219,006✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
136,226,508✔
236
  uTrace("encode cols:%d", pw->nCols);
68,132,301✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
239
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
242
  }
243
  return code;
68,266,071✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
68,037,731✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
68,037,731✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
68,092,425✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
934,189,489✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
934,189,489✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,868,874,616✔
252
  if (pWrapper->nCols == 0) {
934,253,961✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,868,217,274✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
934,324,328✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,868,249,724✔
259
  if (pWrapper->pColCmpr == NULL) {
934,337,663✔
260
    return terrno;
×
261
  }
262

263
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
264
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
265
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
266
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647✔
267
  }
268
  return 0;
934,910,438✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
175,574✔
273

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

280
  if (pCmpr->pColCmpr == NULL) {
175,574✔
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
910,104✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
734,530✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
734,530✔
287
    pColCmpr->id = pColSchema->colId;
734,530✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
734,530✔
289
  }
290
  return 0;
175,574✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
165,518,335✔
294
  if (pSrc->nCols > 0) {
165,518,335✔
295
    pDst->nCols = pSrc->nCols;
149,408,027✔
296
    pDst->version = pSrc->version;
149,422,774✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
149,378,152✔
298
    if (NULL == pDst->pColCmpr) {
149,391,488✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
149,342,010✔
302
  }
303
  return 0;
165,528,865✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
166,094,020✔
307
  if (pColRef) {
166,094,020✔
308
    taosMemoryFreeClear(pColRef->pColRef);
166,114,301✔
309
  }
310
}
166,116,239✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
166,128,157✔
313
  if (pCmpr) {
166,128,157✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
166,131,265✔
315
  }
316
}
166,182,220✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
205,600,063✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
205,600,063✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
411,212,386✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
411,150,788✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
411,097,085✔
323

324
  if (pME->type > 0) {
205,575,918✔
325
    if (pME->name == NULL) {
201,108,381✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
402,279,986✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
201,173,112✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
47,115,741✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
47,203,105✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
47,215,341✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
23,559,290✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
74,154✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
177,551,875✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
264,620,710✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
264,636,343✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
264,621,418✔
342
      if (pME->ctbEntry.commentLen > 0) {
132,300,216✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,928✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
264,593,070✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
132,295,307✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
45,251,854✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
90,503,708✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
90,503,708✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
90,503,708✔
351
      if (pME->ntbEntry.commentLen > 0) {
45,251,854✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
37,816✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
90,503,708✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
90,503,708✔
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) {
201,146,353✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,168,516✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
200,028,107✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
23,544,102✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
176,495,048✔
368
        if (pME->colCmpr.nCols != 0) {
44,654,178✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
44,478,604✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
175,574✔
372
          SColCmprWrapper colCmprs = {0};
175,574✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
175,574✔
374
          if (code != 0) {
175,574✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
175,574✔
379
          taosMemoryFree(colCmprs.pColCmpr);
175,574✔
380
          TAOS_CHECK_RETURN(code);
175,574✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
201,142,098✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
205,557,973✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
47,084,438✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
46,992,822✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
181,951,645✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
89,308,356✔
391
  }
392

393
  tEndEncode(pCoder);
205,502,322✔
394
  return 0;
205,494,395✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,506,572,690✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,506,572,690✔
399
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
400
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
401
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
402

403
  if (headerOnly) {
1,507,431,381✔
404
    tEndDecode(pCoder);
311,734✔
405
    return 0;
311,734✔
406
  }
407

408
  if (pME->type > 0) {
1,507,119,647✔
409
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
410

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,506,913,852✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,455,820,796✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,456,081,473✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,455,972,122✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
727,952,504✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
277,714✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
778,384,335✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,142,095,833✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,142,270,671✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,142,111,432✔
422
      if (pME->ctbEntry.commentLen > 0) {
570,981,254✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
48,432✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,142,054,438✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
571,128,122✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
207,622,099✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
415,487,058✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
415,694,017✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
415,513,014✔
431
      if (pME->ntbEntry.commentLen > 0) {
207,662,182✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
70,140✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
415,394,310✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
415,547,408✔
436
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
437
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
438
      if (!pME->smaEntry.tsma) {
×
439
        return terrno;
×
440
      }
441
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
442
    } else {
443
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
444
      return TSDB_CODE_INVALID_PARA;
×
445
    }
446
    if (pME->type == TSDB_SUPER_TABLE) {
1,506,614,616✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
728,017,028✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
727,995,174✔
449

450
        if (pME->colCmpr.nCols == 0) {
728,059,153✔
451
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        }
453
      } else {
454
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
455
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
456
      }
457
    } else if (pME->type == TSDB_NORMAL_TABLE) {
778,430,675✔
458
      if (!tDecodeIsEnd(pCoder)) {
206,672,029✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
206,710,091✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
206,710,091✔
461
        if (pME->colCmpr.nCols == 0) {
206,747,314✔
462
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
463
        }
464
      } else {
UNCOV
465
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
466
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
467
      }
468
      TABLE_SET_COL_COMPRESSED(pME->flags);
206,669,165✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
571,902,359✔
470
      if (!tDecodeIsEnd(pCoder)) {
5,065,320✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
5,065,320✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
5,065,320✔
473
      } else {
UNCOV
474
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
475
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
476
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
477
        }
478
      }
479
    }
480
    if (!tDecodeIsEnd(pCoder)) {
1,506,673,248✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
934,600,941✔
482
    } else {
483
      pME->pExtSchemas = NULL;
572,072,307✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,506,389,501✔
487
    if (!tDecodeIsEnd(pCoder)) {
727,795,255✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,455,566,298✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
727,524,188✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,455,361,982✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
778,191,202✔
494
    if (!tDecodeIsEnd(pCoder)) {
206,674,852✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
413,337,634✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,506,034,762✔
501
  return 0;
1,506,387,054✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,506,539,140✔
505

506
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
291,209,406✔
507
  if (pSrc == NULL || pDst == NULL) {
291,209,406✔
508
    return TSDB_CODE_INVALID_PARA;
×
509
  }
510

511
  pDst->nCols = pSrc->nCols;
291,259,897✔
512
  pDst->version = pSrc->version;
291,208,461✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
291,228,654✔
514
  if (pDst->pSchema == NULL) {
291,120,038✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
291,163,407✔
518
  return TSDB_CODE_SUCCESS;
291,281,935✔
519
}
520

521
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
42,166✔
522
  if (pSrc == NULL || pDst == NULL) {
42,166✔
523
    return TSDB_CODE_INVALID_PARA;
×
524
  }
525
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
42,893✔
526
  pDst->name = tstrdup(pSrc->name);
42,893✔
527
  if (pDst->name == NULL) {
42,893✔
528
    return terrno;
×
529
  }
530
  if (pSrc->nFuncs > 0) {
42,166✔
531
    pDst->nFuncs = pSrc->nFuncs;
42,166✔
532
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
42,166✔
533
    if (pDst->funcColIds == NULL) {
42,893✔
534
      return terrno;
×
535
    }
536
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
41,439✔
537

538
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
42,166✔
539
    if (pDst->funcIds == NULL) {
42,893✔
540
      return terrno;
×
541
    }
542
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
41,439✔
543
  } else {
544
    pDst->nFuncs = 0;
×
545
    pDst->funcColIds = NULL;
×
546
    pDst->funcIds = NULL;
×
547
  }
548

549
  return TSDB_CODE_SUCCESS;
41,439✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
291,193,526✔
553
  if (pSchema) {
291,193,526✔
554
    taosMemoryFreeClear(pSchema->pSchema);
291,219,455✔
555
  }
556
}
291,251,537✔
557

558
/**
559
 * @param type 0x01 free name
560
 */
561
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
63,976✔
562
  if (pParam) {
63,976✔
563
    if ((type & 0x01)) {
64,703✔
564
      taosMemoryFreeClear(pParam->name);
64,703✔
565
    }
566
    taosMemoryFreeClear(pParam->funcColIds);
63,976✔
567
    taosMemoryFreeClear(pParam->funcIds);
63,976✔
568
  }
569
}
62,522✔
570

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
166,221,212✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
166,221,212✔
573
    return;
71,656✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
166,162,656✔
577

578
  if ((*ppEntry)->type < 0) {
166,152,670✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
166,068,565✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
141,401,338✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
141,380,260✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
141,396,852✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,976✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,760,505✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,322,932✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,322,932✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,437,573✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,437,573✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,437,573✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
166,161,488✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
166,135,283✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
166,145,655✔
601

602
  taosMemoryFreeClear(*ppEntry);
166,117,411✔
603
  return;
166,127,167✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
166,147,608✔
607
  int32_t code = TSDB_CODE_SUCCESS;
166,147,608✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
166,147,608✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
166,194,399✔
614
  if (NULL == *ppEntry) {
166,080,505✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
166,118,314✔
619
  (*ppEntry)->type = pEntry->type;
166,110,736✔
620
  (*ppEntry)->uid = pEntry->uid;
166,115,949✔
621

622
  if (pEntry->type < 0) {
166,148,770✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
166,147,011✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
166,147,565✔
628
    if (NULL == (*ppEntry)->name) {
166,161,760✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
166,165,683✔
636
    (*ppEntry)->flags = pEntry->flags;
141,382,314✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
141,326,500✔
639
    if (code) {
141,413,794✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
141,413,794✔
645
    if (code) {
141,434,401✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
141,434,401✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,893✔
651
      if (code) {
41,439✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
141,426,129✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
141,395,195✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,761,103✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,323,530✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,323,530✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,323,530✔
662

663
    // comment
664
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
16,323,530✔
665
    if (pEntry->ctbEntry.commentLen > 0) {
16,323,530✔
666
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
8,246✔
667
      if (NULL == (*ppEntry)->ctbEntry.comment) {
8,246✔
668
        code = terrno;
×
669
        metaCloneEntryFree(ppEntry);
×
670
        return code;
×
671
      }
672
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
8,246✔
673
    }
674

675
    // tags
676
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
16,323,530✔
677
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
16,323,530✔
678
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
16,323,530✔
679
      code = terrno;
×
680
      metaCloneEntryFree(ppEntry);
×
681
      return code;
×
682
    }
683
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
16,323,530✔
684
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,437,573✔
685
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,437,573✔
686
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,437,573✔
687
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,437,573✔
688
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
8,437,573✔
689

690
    // schema
691
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
8,437,573✔
692
    if (code) {
8,437,573✔
693
      metaCloneEntryFree(ppEntry);
×
694
      return code;
×
695
    }
696

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,437,573✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,437,573✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
11,726✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
11,726✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
11,726✔
707
    }
708
  } else {
709
    return TSDB_CODE_INVALID_PARA;
×
710
  }
711

712
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
166,164,126✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
687,978✔
714
    if (code) {
638,901✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
165,493,591✔
720
    if (code) {
165,522,487✔
721
      metaCloneEntryFree(ppEntry);
14✔
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
166,161,374✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,104,758✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,100,356✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,092,218✔
733
  }
734

735
  return code;
166,160,438✔
736
}
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