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

taosdata / TDengine / #4929

16 Jan 2026 02:32AM UTC coverage: 66.723% (+0.02%) from 66.708%
#4929

push

travis-ci

web-flow
enh: interp supports using non-null prev/next values to fill (#34236)

281 of 327 new or added lines in 11 files covered. (85.93%)

539 existing lines in 127 files now uncovered.

203225 of 304580 relevant lines covered (66.72%)

128590777.46 hits per line

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

81.11
/source/dnode/vnode/src/meta/metaEntry.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "meta.h"
17
#include "osMemPool.h"
18
#include "osMemory.h"
19
#include "tencode.h"
20
#include "tmsg.h"
21

22
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
1,228,850,723✔
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;
27,844,134✔
26
    }
27
  }
28
  return false;
1,199,105,916✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
181,080,596✔
32
  if (pME->pExtSchemas) {
181,080,596✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,888,234✔
34
    bool                  hasTypeMods = false;
11,888,234✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,888,234✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,792,233✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
94,338✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
94,338✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,884,949✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,261,221,064✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
181,101,738✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
359,571,576✔
58
    SColRef *p = &pw->pColRef[i];
358,309,356✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
716,618,712✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
716,618,712✔
61
    if (p->hasRef) {
358,309,356✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
428,676,224✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
428,676,224✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
428,676,224✔
65
    }
66
  }
67
  return 0;
1,262,220✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,173,825,806✔
71
  bool hasExtSchema = false;
1,173,825,806✔
72
  SSchemaWrapper* pSchWrapper = NULL;
1,173,825,806✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
1,173,825,806✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
889,745,060✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
284,205,619✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
284,317,425✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,174,097,966✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,173,881,989✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
37,892,775✔
84
    if (pME->pExtSchemas == NULL) {
18,944,970✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
1,174,268,867✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
43,240,953✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
43,240,953✔
100
  bool                  hasTypeMods = false;
43,240,953✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
43,240,953✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
31,309,129✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,953,151✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,958,234✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
43,271,126✔
109

110
  if (hasTypeMods) {
43,214,667✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,690✔
112
    if (ret != NULL) {
39,690✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,690✔
114
    }
115
    return ret;
39,690✔
116
  }
117
  return NULL;
43,174,977✔
118
}
119

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
26,784✔
151
  int32_t    i = 0, j = 0;
26,784✔
152
  for (i = 0; i < nCols; ++i) {
206,088✔
153
    while (j < pParam->nFuncs) {
325,872✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
313,224✔
155
        pFuncIds[i] = pParam->funcIds[j];
146,568✔
156
        break;
146,568✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
166,656✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
32,736✔
160
        break;
32,736✔
161
      }
162
      ++j;
133,920✔
163
    }
164
    if (j >= pParam->nFuncs) {
191,952✔
165
      for (; i < nCols; ++i) {
25,296✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,648✔
167
      }
168
      break;
12,648✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
26,784✔
172

173
  return 0;
26,784✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
29,694,010✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
29,694,010✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
59,395,329✔
179
  if (pWrapper->nCols == 0) {
29,696,852✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
59,392,286✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
29,697,608✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
59,394,833✔
186
  if (pWrapper->pColRef == NULL) {
29,696,453✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
713,642,637✔
191
    SColRef *p = &pWrapper->pColRef[i];
683,927,484✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,367,923,876✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,367,949,375✔
194
    if (p->hasRef) {
683,989,535✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
381,763,975✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
381,762,899✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
381,761,877✔
198
    }
199
  }
200
  return 0;
29,702,239✔
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) {
656,333✔
220
  if (pSrc->nCols > 0) {
656,333✔
221
    pDst->nCols = pSrc->nCols;
656,333✔
222
    pDst->version = pSrc->version;
656,333✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
656,333✔
224
    if (NULL == pDst->pColRef) {
656,333✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
656,333✔
228
  }
229
  return 0;
656,333✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
42,788,997✔
233
  int32_t code = 0;
42,788,997✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
85,551,781✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
85,604,029✔
236
  uTrace("encode cols:%d", pw->nCols);
42,841,245✔
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;
42,927,314✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
42,689,932✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
42,689,932✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
42,693,418✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,173,879,589✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,173,879,589✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
252
  if (pWrapper->nCols == 0) {
1,173,458,947✔
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,174,238,473✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
1,174,076,013✔
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,175,131,517✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
219,268✔
273

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

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

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

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
171,512,189✔
294
  if (pSrc->nCols > 0) {
171,512,189✔
295
    pDst->nCols = pSrc->nCols;
155,029,767✔
296
    pDst->version = pSrc->version;
155,036,448✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
155,014,932✔
298
    if (NULL == pDst->pColCmpr) {
155,009,433✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
154,986,461✔
302
  }
303
  return 0;
171,509,513✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
172,100,953✔
307
  if (pColRef) {
172,100,953✔
308
    taosMemoryFreeClear(pColRef->pColRef);
172,116,409✔
309
  }
310
}
172,113,767✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
172,126,842✔
313
  if (pCmpr) {
172,126,842✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
172,127,350✔
315
  }
316
}
172,149,593✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
185,660,676✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
185,660,676✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
371,368,146✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
371,302,334✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
371,273,006✔
323

324
  if (pME->type > 0) {
185,662,131✔
325
    if (pME->name == NULL) {
181,079,375✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
362,126,359✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
181,054,526✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
49,326,020✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
49,404,890✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
49,349,544✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
24,627,800✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
77,376✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
156,374,488✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
275,043,103✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
275,048,388✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
275,031,970✔
342
      if (pME->ctbEntry.commentLen > 0) {
137,520,113✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
28,556✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
275,000,371✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
137,494,022✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
18,891,788✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
37,783,576✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
37,783,576✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
37,783,576✔
351
      if (pME->ntbEntry.commentLen > 0) {
18,891,788✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
39,084✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
37,783,576✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
37,783,576✔
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) {
181,043,622✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,438,342✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
179,729,461✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,674,138✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
155,130,324✔
368
        if (pME->colCmpr.nCols != 0) {
18,214,930✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
17,995,636✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
219,294✔
372
          SColCmprWrapper colCmprs = {0};
219,294✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
219,294✔
374
          if (code != 0) {
219,294✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
219,294✔
379
          taosMemoryFree(colCmprs.pColCmpr);
219,294✔
380
          TAOS_CHECK_RETURN(code);
219,294✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
181,116,707✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
185,616,242✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
49,235,029✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
49,181,712✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
160,956,834✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
36,429,860✔
391
  }
392

393
  tEndEncode(pCoder);
185,598,931✔
394
  return 0;
185,570,636✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,966,852,836✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,966,852,836✔
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,968,125,271✔
404
    tEndDecode(pCoder);
349,506✔
405
    return 0;
349,506✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,967,282,106✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,780,429,333✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,780,746,862✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,779,991,278✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
889,582,312✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
283,464✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,076,531,693✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,571,700,292✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,571,755,000✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,571,521,008✔
422
      if (pME->ctbEntry.commentLen > 0) {
785,645,202✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
49,536✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,571,544,996✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
785,897,522✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
291,042,241✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
582,496,571✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
582,651,664✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
582,434,231✔
431
      if (pME->ntbEntry.commentLen > 0) {
291,108,093✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
72,426✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
582,240,246✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
582,454,092✔
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,966,723,544✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
890,311,580✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
890,228,316✔
449

450
        if (pME->colCmpr.nCols == 0) {
890,427,874✔
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,076,688,233✔
458
      if (!tDecodeIsEnd(pCoder)) {
284,421,603✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
284,462,769✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
284,462,769✔
461
        if (pME->colCmpr.nCols == 0) {
284,517,425✔
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);
284,424,404✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
792,298,133✔
470
      if (!tDecodeIsEnd(pCoder)) {
29,696,528✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
29,698,692✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
29,700,924✔
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,967,203,698✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,174,707,912✔
482
    } else {
483
      pME->pExtSchemas = NULL;
792,495,786✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,966,516,060✔
487
    if (!tDecodeIsEnd(pCoder)) {
889,923,849✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,780,155,480✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
889,352,180✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,779,309,290✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,076,397,100✔
494
    if (!tDecodeIsEnd(pCoder)) {
284,372,677✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
568,755,949✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,965,862,393✔
501
  return 0;
1,966,651,421✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,966,717,798✔
505

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

511
  pDst->nCols = pSrc->nCols;
302,312,443✔
512
  pDst->version = pSrc->version;
302,316,334✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
302,309,431✔
514
  if (pDst->pSchema == NULL) {
302,230,957✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
302,258,892✔
518
  return TSDB_CODE_SUCCESS;
302,347,749✔
519
}
520

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

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

549
  return TSDB_CODE_SUCCESS;
43,896✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
302,254,356✔
553
  if (pSchema) {
302,254,356✔
554
    taosMemoryFreeClear(pSchema->pSchema);
302,270,367✔
555
  }
556
}
302,301,409✔
557

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

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
172,224,968✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
172,224,968✔
573
    return;
73,562✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
172,162,624✔
577

578
  if ((*ppEntry)->type < 0) {
172,160,844✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
172,116,629✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
146,843,955✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
146,820,561✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
146,819,880✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
66,216✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
25,303,165✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,698,536✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,695,977✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,605,270✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,605,270✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,605,270✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
172,126,782✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
172,106,145✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
172,131,004✔
601

602
  taosMemoryFreeClear(*ppEntry);
172,103,160✔
603
  return;
172,123,320✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
172,146,001✔
607
  int32_t code = TSDB_CODE_SUCCESS;
172,146,001✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
172,146,001✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
172,171,564✔
614
  if (NULL == *ppEntry) {
172,098,998✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
172,111,919✔
619
  (*ppEntry)->type = pEntry->type;
172,131,657✔
620
  (*ppEntry)->uid = pEntry->uid;
172,124,119✔
621

622
  if (pEntry->type < 0) {
172,145,874✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
172,143,346✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
172,155,253✔
628
    if (NULL == (*ppEntry)->name) {
172,171,216✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
172,158,875✔
636
    (*ppEntry)->flags = pEntry->flags;
146,843,449✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
146,832,458✔
639
    if (code) {
146,860,124✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
146,860,124✔
645
    if (code) {
146,880,464✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
146,880,464✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
43,896✔
651
      if (code) {
43,896✔
652
        metaCloneEntryFree(ppEntry);
13✔
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
146,878,853✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
146,856,728✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
25,303,543✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,698,536✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,697,931✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,698,194✔
662

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

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

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,605,270✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,605,270✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
12,115✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
12,115✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
12,115✔
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) {
172,156,436✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
692,272✔
714
    if (code) {
656,333✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
171,481,256✔
720
    if (code) {
171,495,580✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
172,151,913✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,325,940✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,321,454✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,324,425✔
733
  }
734

735
  return code;
172,139,973✔
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