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

taosdata / TDengine / #4918

08 Jan 2026 11:50AM UTC coverage: 65.916% (+0.5%) from 65.42%
#4918

push

travis-ci

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

16 of 22 new or added lines in 3 files covered. (72.73%)

788 existing lines in 116 files now uncovered.

204221 of 309822 relevant lines covered (65.92%)

126504701.11 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,179,163,287✔
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;
29,937,338✔
26
    }
27
  }
28
  return false;
1,145,679,309✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
190,864,869✔
32
  if (pME->pExtSchemas) {
190,864,869✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
12,006,385✔
34
    bool                  hasTypeMods = false;
12,006,385✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
12,006,385✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,900,680✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
105,328✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
105,328✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,004,550✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,026,800,899✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,029,680,961✔
46
    }
47
  }
48
  return 0;
190,889,173✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
236,305,216✔
58
    SColRef *p = &pw->pColRef[i];
235,231,802✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
470,463,604✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
470,463,604✔
61
    if (p->hasRef) {
235,231,802✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
281,161,500✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
281,161,500✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
281,161,500✔
65
    }
66
  }
67
  return 0;
1,073,414✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,126,990,395✔
71
  bool hasExtSchema = false;
1,126,990,395✔
72
  SSchemaWrapper* pSchWrapper = NULL;
1,126,990,395✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
1,126,990,395✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
895,621,571✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
231,798,223✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
232,067,501✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,127,884,321✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,127,736,509✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
41,647,368✔
84
    if (pME->pExtSchemas == NULL) {
20,823,873✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
1,127,918,148✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
40,098,720✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
40,098,720✔
100
  bool                  hasTypeMods = false;
40,098,720✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
40,098,720✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
29,034,627✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,075,599✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,082,524✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
40,112,719✔
109

110
  if (hasTypeMods) {
40,099,790✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
37,068✔
112
    if (ret != NULL) {
37,068✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
37,068✔
114
    }
115
    return ret;
37,068✔
116
  }
117
  return NULL;
40,062,722✔
118
}
119

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
25,524✔
151
  int32_t    i = 0, j = 0;
25,524✔
152
  for (i = 0; i < nCols; ++i) {
196,393✔
153
    while (j < pParam->nFuncs) {
310,542✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
298,489✔
155
        pFuncIds[i] = pParam->funcIds[j];
139,673✔
156
        break;
139,673✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
158,816✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,196✔
160
        break;
31,196✔
161
      }
162
      ++j;
127,620✔
163
    }
164
    if (j >= pParam->nFuncs) {
182,922✔
165
      for (; i < nCols; ++i) {
24,106✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,053✔
167
      }
168
      break;
12,053✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
25,524✔
172

173
  return 0;
25,524✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
16,674,661✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
16,674,661✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
33,351,820✔
179
  if (pWrapper->nCols == 0) {
16,675,091✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
33,350,792✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
16,675,641✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
33,351,880✔
186
  if (pWrapper->pColRef == NULL) {
16,675,749✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
407,229,406✔
191
    SColRef *p = &pWrapper->pColRef[i];
390,529,530✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
781,124,490✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
781,143,327✔
194
    if (p->hasRef) {
390,577,413✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
213,929,596✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
213,925,672✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
213,927,740✔
198
    }
199
  }
200
  return 0;
16,678,689✔
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) {
625,312✔
220
  if (pSrc->nCols > 0) {
625,312✔
221
    pDst->nCols = pSrc->nCols;
625,312✔
222
    pDst->version = pSrc->version;
625,312✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
625,312✔
224
    if (NULL == pDst->pColRef) {
625,312✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
625,312✔
228
  }
229
  return 0;
625,312✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
60,178,079✔
233
  int32_t code = 0;
60,178,079✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
120,327,487✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
120,335,272✔
236
  uTrace("encode cols:%d", pw->nCols);
60,185,864✔
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;
60,216,372✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
60,031,333✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
60,031,333✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
60,073,129✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,127,160,302✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,127,160,302✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
252
  if (pWrapper->nCols == 0) {
1,127,479,360✔
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,127,512,052✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
1,127,654,386✔
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,128,543,844✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
161,412✔
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
834,098✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
672,686✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
672,686✔
287
    pColCmpr->id = pColSchema->colId;
672,686✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
672,686✔
289
  }
290
  return 0;
161,412✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
163,355,719✔
294
  if (pSrc->nCols > 0) {
163,355,719✔
295
    pDst->nCols = pSrc->nCols;
147,335,150✔
296
    pDst->version = pSrc->version;
147,332,503✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
147,321,153✔
298
    if (NULL == pDst->pColCmpr) {
147,320,095✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
147,316,029✔
302
  }
303
  return 0;
163,347,108✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
163,977,725✔
307
  if (pColRef) {
163,977,725✔
308
    taosMemoryFreeClear(pColRef->pColRef);
163,985,565✔
309
  }
310
}
163,986,082✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
163,971,309✔
313
  if (pCmpr) {
163,971,309✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
163,977,503✔
315
  }
316
}
163,991,989✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
195,185,522✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
195,185,522✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
390,366,264✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
390,362,233✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
390,339,418✔
323

324
  if (pME->type > 0) {
195,151,110✔
325
    if (pME->name == NULL) {
190,872,967✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
381,751,133✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
190,876,949✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
47,424,921✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
47,487,890✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
47,513,902✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
23,735,517✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
72,318✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
167,131,853✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
260,142,556✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
260,147,799✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
260,152,023✔
342
      if (pME->ctbEntry.commentLen > 0) {
130,074,805✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,184✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
260,147,011✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
130,071,804✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
37,064,956✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
74,129,912✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
74,129,912✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
74,129,912✔
351
      if (pME->ntbEntry.commentLen > 0) {
37,064,956✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
37,584✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
74,129,912✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
74,129,912✔
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) {
190,873,383✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,114,125✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
189,765,924✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
23,752,164✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
166,072,384✔
368
        if (pME->colCmpr.nCols != 0) {
36,473,520✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
36,312,108✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
161,412✔
372
          SColCmprWrapper colCmprs = {0};
161,412✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
161,412✔
374
          if (code != 0) {
161,412✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
161,412✔
379
          taosMemoryFree(colCmprs.pColCmpr);
161,412✔
380
          TAOS_CHECK_RETURN(code);
161,412✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
190,884,733✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
195,185,653✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
47,448,134✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
47,401,452✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
171,428,797✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
72,947,040✔
391
  }
392

393
  tEndEncode(pCoder);
195,129,384✔
394
  return 0;
195,166,770✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,764,238,774✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,764,238,774✔
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,765,462,109✔
404
    tEndDecode(pCoder);
303,380✔
405
    return 0;
303,380✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,764,618,646✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,792,035,953✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,792,145,492✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,791,710,316✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
895,629,033✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
270,129✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
868,161,377✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,267,283,783✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,267,149,036✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,267,015,666✔
422
      if (pME->ctbEntry.commentLen > 0) {
633,432,965✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
47,012✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,266,997,713✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
633,555,247✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
234,982,425✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
470,432,658✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
470,791,190✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
470,473,679✔
431
      if (pME->ntbEntry.commentLen > 0) {
235,074,907✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
69,380✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
470,174,017✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
470,432,627✔
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,764,389,179✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
895,903,422✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
895,666,768✔
449

450
        if (pME->colCmpr.nCols == 0) {
896,181,958✔
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) {
868,409,482✔
458
      if (!tDecodeIsEnd(pCoder)) {
232,218,547✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
232,247,738✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
232,247,738✔
461
        if (pME->colCmpr.nCols == 0) {
232,183,798✔
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);
232,210,374✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
636,406,761✔
470
      if (!tDecodeIsEnd(pCoder)) {
16,676,669✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
16,677,159✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
16,677,159✔
473
      } else {
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,764,727,301✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,128,112,919✔
482
    } else {
483
      pME->pExtSchemas = NULL;
636,614,382✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,764,116,412✔
487
    if (!tDecodeIsEnd(pCoder)) {
895,522,677✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,791,718,579✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
895,752,654✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,791,611,536✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
868,207,966✔
494
    if (!tDecodeIsEnd(pCoder)) {
232,074,113✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
464,167,119✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,764,120,479✔
501
  return 0;
1,764,071,611✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,764,056,195✔
505

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

511
  pDst->nCols = pSrc->nCols;
287,216,390✔
512
  pDst->version = pSrc->version;
287,215,661✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
287,211,620✔
514
  if (pDst->pSchema == NULL) {
287,139,756✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
287,175,641✔
518
  return TSDB_CODE_SUCCESS;
287,228,046✔
519
}
520

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

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

549
  return TSDB_CODE_SUCCESS;
41,831✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
287,192,445✔
553
  if (pSchema) {
287,192,445✔
554
    taosMemoryFreeClear(pSchema->pSchema);
287,211,305✔
555
  }
556
}
287,188,131✔
557

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

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
164,050,181✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
164,050,181✔
573
    return;
70,226✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
163,986,676✔
577

578
  if ((*ppEntry)->type < 0) {
163,987,447✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
163,937,976✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
139,463,659✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
139,448,048✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
139,457,296✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,101✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,507,923✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,230,851✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,231,463✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,277,681✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,277,681✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,277,681✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
163,967,239✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
163,958,714✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
163,965,104✔
601

602
  taosMemoryFreeClear(*ppEntry);
163,943,831✔
603
  return;
163,968,529✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
163,967,844✔
607
  int32_t code = TSDB_CODE_SUCCESS;
163,967,844✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
163,967,844✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
163,989,739✔
614
  if (NULL == *ppEntry) {
163,935,273✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
163,941,542✔
619
  (*ppEntry)->type = pEntry->type;
163,966,171✔
620
  (*ppEntry)->uid = pEntry->uid;
163,963,635✔
621

622
  if (pEntry->type < 0) {
163,986,273✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
163,974,000✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
163,964,159✔
628
    if (NULL == (*ppEntry)->name) {
163,958,659✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
163,978,185✔
636
    (*ppEntry)->flags = pEntry->flags;
139,446,133✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
139,466,437✔
639
    if (code) {
139,467,959✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
139,467,959✔
645
    if (code) {
139,484,495✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
139,484,495✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
41,831✔
651
      if (code) {
41,831✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
139,483,916✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
139,475,881✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,507,920✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,230,851✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,231,463✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,231,463✔
662

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

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

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,277,681✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,277,681✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
11,646✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
11,646✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
11,646✔
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) {
163,992,837✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
638,130✔
714
    if (code) {
625,312✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
163,340,074✔
720
    if (code) {
163,344,469✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
163,969,781✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,499,725✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,490,730✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,494,321✔
733
  }
734

735
  return code;
163,982,421✔
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