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

taosdata / TDengine / #4909

30 Dec 2025 10:52AM UTC coverage: 65.542% (+0.2%) from 65.386%
#4909

push

travis-ci

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

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

857 existing lines in 113 files now uncovered.

193924 of 295877 relevant lines covered (65.54%)

120594206.86 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,026,615,068✔
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,224,854✔
26
    }
27
  }
28
  return false;
999,145,790✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
165,884,420✔
32
  if (pME->pExtSchemas) {
165,884,420✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,291,080✔
34
    bool                  hasTypeMods = false;
11,291,080✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,291,080✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,201,081✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
88,726✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
88,726✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,289,703✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
991,589,301✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
1,960,534,230✔
46
    }
47
  }
48
  return 0;
165,905,740✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
10,355,704✔
58
    SColRef *p = &pw->pColRef[i];
9,275,242✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
18,550,484✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
18,550,484✔
61
    if (p->hasRef) {
9,275,242✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
10,036,708✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
10,036,708✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
10,036,708✔
65
    }
66
  }
67
  return 0;
1,080,462✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
978,703,414✔
71
  bool hasExtSchema = false;
978,703,414✔
72
  SSchemaWrapper* pSchWrapper = NULL;
978,703,414✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
978,703,414✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
789,895,278✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
189,012,439✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
189,043,698✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
978,952,954✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
979,137,168✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
35,526,811✔
84
    if (pME->pExtSchemas == NULL) {
17,762,851✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
979,080,637✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
36,658,039✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
36,658,039✔
100
  bool                  hasTypeMods = false;
36,658,039✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
36,658,039✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
28,433,181✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
8,250,087✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
8,250,087✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
36,684,710✔
109

110
  if (hasTypeMods) {
36,649,392✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
37,580✔
112
    if (ret != NULL) {
37,580✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
37,580✔
114
    }
115
    return ret;
37,580✔
116
  }
117
  return NULL;
36,611,812✔
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) {
8,719,099✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
8,719,099✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
17,440,498✔
179
  if (pWrapper->nCols == 0) {
8,720,235✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
17,441,080✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
8,721,981✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
17,443,414✔
186
  if (pWrapper->pColRef == NULL) {
8,721,433✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
112,530,699✔
191
    SColRef *p = &pWrapper->pColRef[i];
103,803,273✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
207,632,758✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
207,639,381✔
194
    if (p->hasRef) {
103,824,376✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
59,684,410✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
59,681,413✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
59,681,772✔
198
    }
199
  }
200
  return 0;
8,722,541✔
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) {
627,104✔
220
  if (pSrc->nCols > 0) {
627,104✔
221
    pDst->nCols = pSrc->nCols;
627,104✔
222
    pDst->version = pSrc->version;
627,104✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
627,104✔
224
    if (NULL == pDst->pColRef) {
627,104✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
627,104✔
228
  }
229
  return 0;
627,104✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
36,832,626✔
233
  int32_t code = 0;
36,832,626✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
73,671,806✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
73,685,730✔
236
  uTrace("encode cols:%d", pw->nCols);
36,846,550✔
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;
36,898,203✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
36,689,024✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
36,689,024✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
36,731,453✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
978,746,173✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
978,746,173✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,958,123,771✔
252
  if (pWrapper->nCols == 0) {
978,993,033✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,957,756,882✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
979,071,776✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,957,808,219✔
259
  if (pWrapper->pColCmpr == NULL) {
978,922,005✔
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;
979,338,205✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
171,516✔
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
887,994✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
716,478✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
716,478✔
287
    pColCmpr->id = pColSchema->colId;
716,478✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
716,478✔
289
  }
290
  return 0;
171,516✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
160,871,003✔
294
  if (pSrc->nCols > 0) {
160,871,003✔
295
    pDst->nCols = pSrc->nCols;
145,211,984✔
296
    pDst->version = pSrc->version;
145,220,319✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
145,205,288✔
298
    if (NULL == pDst->pColCmpr) {
145,204,578✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
145,195,811✔
302
  }
303
  return 0;
160,874,687✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
161,469,645✔
307
  if (pColRef) {
161,469,645✔
308
    taosMemoryFreeClear(pColRef->pColRef);
161,480,562✔
309
  }
310
}
161,484,660✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
161,490,041✔
313
  if (pCmpr) {
161,490,041✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
161,494,885✔
315
  }
316
}
161,508,287✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
170,223,370✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
170,223,370✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
340,519,404✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
340,493,861✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
340,466,357✔
323

324
  if (pME->type > 0) {
170,240,585✔
325
    if (pME->name == NULL) {
165,887,288✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
331,820,618✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
165,923,867✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
45,966,466✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
46,009,905✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
46,011,173✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
22,980,794✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
74,881✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
142,909,500✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
256,856,304✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
256,870,271✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
256,873,604✔
342
      if (pME->ctbEntry.commentLen > 0) {
128,435,566✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,308✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
256,854,970✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
128,429,658✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,486,902✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
28,973,804✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
28,973,804✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
28,973,804✔
351
      if (pME->ntbEntry.commentLen > 0) {
14,486,902✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
37,628✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
28,973,804✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
28,973,994✔
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) {
165,900,760✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,117,347✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
164,815,415✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
22,970,855✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
141,852,257✔
368
        if (pME->colCmpr.nCols != 0) {
13,892,966✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
13,721,640✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
171,326✔
372
          SColCmprWrapper colCmprs = {0};
171,516✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
171,516✔
374
          if (code != 0) {
171,516✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
171,516✔
379
          taosMemoryFree(colCmprs.pColCmpr);
171,516✔
380
          TAOS_CHECK_RETURN(code);
171,516✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
165,893,137✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
170,218,994✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
45,951,677✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
45,907,067✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
147,219,877✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
27,786,312✔
391
  }
392

393
  tEndEncode(pCoder);
170,190,450✔
394
  return 0;
170,188,714✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,584,312,155✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,584,312,155✔
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,585,020,662✔
404
    tEndDecode(pCoder);
312,890✔
405
    return 0;
312,890✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,584,565,050✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,580,084,725✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,580,261,783✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,580,114,479✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
790,032,904✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
278,441✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
793,882,963✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,205,982,241✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,206,263,159✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,206,070,973✔
422
      if (pME->ctbEntry.commentLen > 0) {
602,938,765✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
47,284✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,205,897,733✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
603,110,215✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
191,270,679✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
382,629,497✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
382,713,032✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
382,622,359✔
431
      if (pME->ntbEntry.commentLen > 0) {
191,263,670✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
69,562✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
382,543,308✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
382,624,636✔
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,584,041,020✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
790,082,016✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
790,089,310✔
449

450
        if (pME->colCmpr.nCols == 0) {
790,118,989✔
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) {
793,818,341✔
458
      if (!tDecodeIsEnd(pCoder)) {
189,084,259✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
189,098,599✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
189,098,599✔
461
        if (pME->colCmpr.nCols == 0) {
189,114,705✔
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);
189,073,676✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
604,820,851✔
470
      if (!tDecodeIsEnd(pCoder)) {
8,721,959✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
8,721,959✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
8,722,667✔
473
      } else {
474
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
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,584,302,145✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
979,133,520✔
482
    } else {
483
      pME->pExtSchemas = NULL;
605,168,625✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,583,827,599✔
487
    if (!tDecodeIsEnd(pCoder)) {
789,947,358✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,579,838,965✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
789,648,968✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,579,617,289✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
793,652,144✔
494
    if (!tDecodeIsEnd(pCoder)) {
189,080,639✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
378,146,426✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,583,631,721✔
501
  return 0;
1,583,842,595✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,584,083,008✔
505

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

511
  pDst->nCols = pSrc->nCols;
282,985,929✔
512
  pDst->version = pSrc->version;
282,969,731✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
282,976,398✔
514
  if (pDst->pSchema == NULL) {
282,931,861✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
282,949,811✔
518
  return TSDB_CODE_SUCCESS;
282,989,577✔
519
}
520

521
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
42,893✔
522
  if (pSrc == NULL || pDst == NULL) {
42,893✔
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,166✔
528
    return terrno;
×
529
  }
530
  if (pSrc->nFuncs > 0) {
42,166✔
531
    pDst->nFuncs = pSrc->nFuncs;
42,893✔
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));
42,166✔
537

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

549
  return TSDB_CODE_SUCCESS;
42,166✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
282,975,622✔
553
  if (pSchema) {
282,975,622✔
554
    taosMemoryFreeClear(pSchema->pSchema);
282,987,208✔
555
  }
556
}
282,986,995✔
557

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

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
161,567,908✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
161,567,908✔
573
    return;
70,837✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
161,503,115✔
577

578
  if ((*ppEntry)->type < 0) {
161,500,944✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
161,478,455✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
137,356,262✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
137,347,805✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
137,352,134✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
64,703✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,152,307✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
15,868,185✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
15,868,185✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,283,722✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,283,722✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,283,896✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
161,505,874✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
161,499,649✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
161,500,658✔
601

602
  taosMemoryFreeClear(*ppEntry);
161,485,821✔
603
  return;
161,493,473✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
161,478,768✔
607
  int32_t code = TSDB_CODE_SUCCESS;
161,478,768✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
161,478,768✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
161,510,555✔
614
  if (NULL == *ppEntry) {
161,474,765✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
161,487,287✔
619
  (*ppEntry)->type = pEntry->type;
161,493,638✔
620
  (*ppEntry)->uid = pEntry->uid;
161,492,724✔
621

622
  if (pEntry->type < 0) {
161,506,463✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
161,495,218✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
161,498,086✔
628
    if (NULL == (*ppEntry)->name) {
161,501,944✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
161,497,381✔
636
    (*ppEntry)->flags = pEntry->flags;
137,342,640✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
137,318,346✔
639
    if (code) {
137,346,293✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
137,346,293✔
645
    if (code) {
137,362,233✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
137,362,233✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,166✔
651
      if (code) {
42,166✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
137,358,327✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
137,346,121✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,152,760✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
15,868,585✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
15,868,864✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
15,868,864✔
662

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

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

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,283,896✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,283,896✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
11,661✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
11,661✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
11,661✔
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) {
161,507,632✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
655,714✔
714
    if (code) {
627,104✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
160,852,773✔
720
    if (code) {
160,874,746✔
UNCOV
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
161,501,850✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
8,841,658✔
727
    if (!(*ppEntry)->pExtSchemas) {
8,840,931✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
8,836,806✔
733
  }
734

735
  return code;
161,493,001✔
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