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

taosdata / TDengine / #4982

12 Mar 2026 05:32AM UTC coverage: 68.587% (+0.1%) from 68.488%
#4982

push

travis-ci

web-flow
merge: from main to 3.0 branch #34705

merge: from main to 3.0 branch

279 of 443 new or added lines in 34 files covered. (62.98%)

2352 existing lines in 132 files now uncovered.

212163 of 309332 relevant lines covered (68.59%)

135254549.82 hits per line

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

80.9
/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) {
1,233,200,474✔
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;
153,949,573✔
26
    }
27
  }
28
  return false;
1,077,497,409✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
206,009,995✔
32
  if (pME->pExtSchemas) {
206,009,995✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
12,337,962✔
34
    bool                  hasTypeMods = false;
12,337,962✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
12,337,962✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
12,244,903✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
94,582✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
94,582✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,324,635✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,373,877,199✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
206,079,415✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
449,056,484✔
58
    SColRef *p = &pw->pColRef[i];
447,682,166✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
895,364,332✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
895,364,332✔
61
    if (p->hasRef) {
447,682,166✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
593,740,020✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
593,740,020✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
593,740,020✔
65
    }
66
  }
67
  return 0;
1,374,318✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,176,526,826✔
71
  bool hasExtSchema = false;
1,176,526,826✔
72
  SSchemaWrapper* pSchWrapper = NULL;
1,176,526,826✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
1,176,526,826✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
894,391,326✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
282,125,600✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
282,345,201✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,177,032,180✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,177,177,387✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
289,224,355✔
84
    if (pME->pExtSchemas == NULL) {
144,610,045✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
1,177,225,471✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
44,516,653✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
44,516,653✔
100
  bool                  hasTypeMods = false;
44,516,653✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
44,516,653✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
32,574,125✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,968,600✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,980,595✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
44,554,954✔
109

110
  if (hasTypeMods) {
44,524,405✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,942✔
112
    if (ret != NULL) {
39,942✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,942✔
114
    }
115
    return ret;
39,942✔
116
  }
117
  return NULL;
44,484,463✔
118
}
119

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
27,084✔
151
  int32_t    i = 0, j = 0;
27,084✔
152
  for (i = 0; i < nCols; ++i) {
204,960✔
153
    while (j < pParam->nFuncs) {
323,544✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
310,368✔
155
        pFuncIds[i] = pParam->funcIds[j];
144,936✔
156
        break;
144,936✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
165,432✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
32,940✔
160
        break;
32,940✔
161
      }
162
      ++j;
132,492✔
163
    }
164
    if (j >= pParam->nFuncs) {
191,052✔
165
      for (; i < nCols; ++i) {
26,352✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
13,176✔
167
      }
168
      break;
13,176✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
27,084✔
172

173
  return 0;
27,084✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
42,978,350✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
42,978,350✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
85,958,931✔
179
  if (pWrapper->nCols == 0) {
42,976,575✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
85,940,722✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
42,975,555✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
85,954,867✔
186
  if (pWrapper->pColRef == NULL) {
42,981,391✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
949,476,113✔
191
    SColRef *p = &pWrapper->pColRef[i];
906,438,009✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,813,078,298✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,813,117,490✔
194
    if (p->hasRef) {
906,559,550✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
494,819,712✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
494,823,796✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
494,814,147✔
198
    }
199
  }
200
  return 0;
42,993,617✔
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) {
677,878✔
220
  if (pSrc->nCols > 0) {
677,878✔
221
    pDst->nCols = pSrc->nCols;
677,878✔
222
    pDst->version = pSrc->version;
677,878✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
677,878✔
224
    if (NULL == pDst->pColRef) {
677,878✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
677,878✔
228
  }
229
  return 0;
677,878✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
46,814,015✔
233
  int32_t code = 0;
46,814,015✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
93,673,424✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
93,819,523✔
236
  uTrace("encode cols:%d", pw->nCols);
46,960,114✔
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;
47,069,493✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
46,725,932✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
46,725,932✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
46,835,482✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,176,724,952✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,176,724,952✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
252
  if (pWrapper->nCols == 0) {
1,176,675,766✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
2,147,483,647✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
1,176,771,069✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
1,176,525,214✔
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;
1,178,188,038✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
227,472✔
273

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

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

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

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
202,357,896✔
294
  if (pSrc->nCols > 0) {
202,357,896✔
295
    pDst->nCols = pSrc->nCols;
176,593,946✔
296
    pDst->version = pSrc->version;
176,610,742✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
176,583,489✔
298
    if (NULL == pDst->pColCmpr) {
176,533,939✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
176,543,812✔
302
  }
303
  return 0;
202,368,689✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
202,976,652✔
307
  if (pColRef) {
202,976,652✔
308
    taosMemoryFreeClear(pColRef->pColRef);
203,013,235✔
309
  }
310
}
203,008,693✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
202,980,716✔
313
  if (pCmpr) {
202,980,716✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
202,995,144✔
315
  }
316
}
203,028,659✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
210,803,454✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
210,803,454✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
421,683,307✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
421,676,398✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
421,624,891✔
323

324
  if (pME->type > 0) {
210,783,856✔
325
    if (pME->name == NULL) {
206,028,650✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
412,006,225✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
205,993,514✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
51,563,426✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
51,797,404✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
51,844,482✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
25,821,922✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
108,968✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
180,122,215✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
316,562,252✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
316,591,109✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
316,592,980✔
342
      if (pME->ctbEntry.commentLen > 0) {
158,289,614✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
28,924✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
316,588,742✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
158,307,102✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
21,868,214✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
43,736,428✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
43,736,428✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
43,736,428✔
351
      if (pME->ntbEntry.commentLen > 0) {
21,868,214✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
39,708✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
43,736,428✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
43,736,428✔
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) {
206,015,704✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,509,124✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
204,595,687✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
25,922,034✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
178,702,366✔
368
        if (pME->colCmpr.nCols != 0) {
21,143,808✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
20,916,336✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
227,472✔
372
          SColCmprWrapper colCmprs = {0};
227,472✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
227,472✔
374
          if (code != 0) {
227,472✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
227,472✔
379
          taosMemoryFree(colCmprs.pColCmpr);
227,472✔
380
          TAOS_CHECK_RETURN(code);
227,472✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
206,079,387✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
210,829,025✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
51,698,381✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
51,478,953✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
184,916,314✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
42,287,616✔
391
  }
392

393
  tEndEncode(pCoder);
210,636,233✔
394
  return 0;
210,684,117✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,989,474,778✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,989,474,778✔
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,991,416,908✔
404
    tEndDecode(pCoder);
352,576✔
405
    return 0;
352,576✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,990,058,657✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,789,089,693✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,789,842,409✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,789,677,905✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
894,770,502✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
335,364✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,094,421,511✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,607,446,831✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,607,856,001✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,607,186,266✔
422
      if (pME->ctbEntry.commentLen > 0) {
803,273,717✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
50,056✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,607,174,570✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
803,869,761✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
291,432,111✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
583,460,013✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
583,744,235✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
583,408,948✔
431
      if (pME->ntbEntry.commentLen > 0) {
291,538,892✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
73,402✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
583,033,435✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
583,484,599✔
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,989,915,878✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
895,202,721✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
895,100,205✔
449

450
        if (pME->colCmpr.nCols == 0) {
895,332,530✔
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) {
1,094,504,265✔
458
      if (!tDecodeIsEnd(pCoder)) {
282,501,845✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
282,546,215✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
282,546,215✔
461
        if (pME->colCmpr.nCols == 0) {
282,632,579✔
462
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
463
        }
464
      } else {
465
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
466
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
467
      }
468
      TABLE_SET_COL_COMPRESSED(pME->flags);
282,521,314✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
811,917,832✔
470
      if (!tDecodeIsEnd(pCoder)) {
42,981,941✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
42,983,001✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
42,983,213✔
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,989,970,433✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,177,100,356✔
482
    } else {
483
      pME->pExtSchemas = NULL;
812,870,077✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,989,109,707✔
487
    if (!tDecodeIsEnd(pCoder)) {
894,295,102✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,788,889,488✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
893,682,064✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,788,490,819✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,094,223,809✔
494
    if (!tDecodeIsEnd(pCoder)) {
282,382,563✔
495
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
564,893,654✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,988,784,616✔
501
  return 0;
1,989,133,681✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,989,321,461✔
505

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

511
  pDst->nCols = pSrc->nCols;
345,341,440✔
512
  pDst->version = pSrc->version;
345,339,067✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
345,311,822✔
514
  if (pDst->pSchema == NULL) {
345,136,043✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
345,166,402✔
518
  return TSDB_CODE_SUCCESS;
345,366,680✔
519
}
520

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

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

549
  return TSDB_CODE_SUCCESS;
74,040✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
345,253,577✔
553
  if (pSchema) {
345,253,577✔
554
    taosMemoryFreeClear(pSchema->pSchema);
345,291,304✔
555
  }
556
}
345,278,329✔
557

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

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
203,100,896✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
203,100,896✔
573
    return;
76,779✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
203,042,952✔
577

578
  if ((*ppEntry)->type < 0) {
203,053,218✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
202,992,067✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
168,296,516✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
168,250,665✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
168,260,256✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
112,890✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
34,749,757✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
26,005,438✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
26,001,255✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,747,972✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,747,972✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,747,972✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
203,014,890✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
203,014,224✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
203,022,214✔
601

602
  taosMemoryFreeClear(*ppEntry);
202,983,834✔
603
  return;
203,001,605✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
203,002,381✔
607
  int32_t code = TSDB_CODE_SUCCESS;
203,002,381✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
203,002,381✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
203,066,128✔
614
  if (NULL == *ppEntry) {
202,928,714✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
202,980,031✔
619
  (*ppEntry)->type = pEntry->type;
202,997,870✔
620
  (*ppEntry)->uid = pEntry->uid;
202,976,561✔
621

622
  if (pEntry->type < 0) {
202,998,503✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
202,996,256✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
202,994,811✔
628
    if (NULL == (*ppEntry)->name) {
203,036,047✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
203,037,407✔
636
    (*ppEntry)->flags = pEntry->flags;
168,274,786✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
168,221,940✔
639
    if (code) {
168,298,659✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
168,298,659✔
645
    if (code) {
168,326,188✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
168,326,188✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
74,040✔
651
      if (code) {
74,040✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
168,318,326✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
168,291,384✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
34,752,017✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
26,004,409✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
26,004,409✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
26,003,623✔
662

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

675
    // tags
676
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
26,004,045✔
677
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
26,001,407✔
678
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
26,004,638✔
679
      code = terrno;
×
680
      metaCloneEntryFree(ppEntry);
×
681
      return code;
×
682
    }
683
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
26,002,267✔
684
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,747,972✔
685
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,747,972✔
686
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,747,972✔
687
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,747,972✔
688
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
8,747,972✔
689

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,747,972✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,747,972✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
12,307✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
12,307✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
12,307✔
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) {
203,052,895✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
729,751✔
714
    if (code) {
677,878✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
202,317,183✔
720
    if (code) {
202,350,800✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
203,028,678✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,738,045✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,726,836✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,723,250✔
733
  }
734

735
  return code;
203,026,787✔
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