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

taosdata / TDengine / #4926

13 Jan 2026 05:43AM UTC coverage: 66.053% (-0.05%) from 66.107%
#4926

push

travis-ci

web-flow
feat: [6654385780] show snap progress (#34203)

48 of 59 new or added lines in 7 files covered. (81.36%)

582 existing lines in 124 files now uncovered.

200362 of 303334 relevant lines covered (66.05%)

132283104.31 hits per line

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

81.31
/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,253,510,268✔
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,334,851✔
26
    }
27
  }
28
  return false;
1,220,575,680✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
191,675,130✔
32
  if (pME->pExtSchemas) {
191,675,130✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,747,547✔
34
    bool                  hasTypeMods = false;
11,747,547✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,747,547✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,645,607✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
106,698✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
106,698✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,754,717✔
43

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

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
215,489,188✔
58
    SColRef *p = &pw->pColRef[i];
214,279,012✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
428,558,024✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
428,558,024✔
61
    if (p->hasRef) {
214,279,012✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
255,866,912✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
255,866,912✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
255,866,912✔
65
    }
66
  }
67
  return 0;
1,210,176✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,200,872,015✔
71
  bool hasExtSchema = false;
1,200,872,015✔
72
  SSchemaWrapper* pSchWrapper = NULL;
1,200,872,015✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
1,200,872,015✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
909,676,834✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
291,584,612✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
291,622,710✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,201,320,450✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,200,931,764✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
40,998,104✔
84
    if (pME->pExtSchemas == NULL) {
20,500,843✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
1,201,031,904✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
40,866,466✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
40,866,466✔
100
  bool                  hasTypeMods = false;
40,866,466✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
40,866,466✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
29,618,158✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,271,986✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,281,856✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
40,898,002✔
109

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

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
25,704✔
151
  int32_t    i = 0, j = 0;
25,704✔
152
  for (i = 0; i < nCols; ++i) {
197,778✔
153
    while (j < pParam->nFuncs) {
312,732✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
300,594✔
155
        pFuncIds[i] = pParam->funcIds[j];
140,658✔
156
        break;
140,658✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
159,936✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,416✔
160
        break;
31,416✔
161
      }
162
      ++j;
128,520✔
163
    }
164
    if (j >= pParam->nFuncs) {
184,212✔
165
      for (; i < nCols; ++i) {
24,276✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,138✔
167
      }
168
      break;
12,138✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
25,704✔
172

173
  return 0;
25,704✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
28,360,951✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
28,360,951✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
56,726,043✔
179
  if (pWrapper->nCols == 0) {
28,362,216✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
56,719,433✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
28,360,631✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
56,723,445✔
186
  if (pWrapper->pColRef == NULL) {
28,363,149✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
587,918,285✔
191
    SColRef *p = &pWrapper->pColRef[i];
559,533,676✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,119,132,912✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,119,181,111✔
194
    if (p->hasRef) {
559,603,414✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
311,333,123✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
311,327,281✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
311,337,337✔
198
    }
199
  }
200
  return 0;
28,368,093✔
201
}
202

203
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
204
                                                            SSchemaWrapper *pSchema) {
205
  pRef->nCols = pSchema->nCols;
×
206
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
207
    return terrno;
×
208
  }
209

210
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
211
    SColRef  *pColRef = &pRef->pColRef[i];
×
212
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
213
    pColRef->id = pColSchema->colId;
×
214
    pColRef->hasRef = false;
×
215
  }
216
  return 0;
×
217
}
218

219
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
638,196✔
220
  if (pSrc->nCols > 0) {
638,196✔
221
    pDst->nCols = pSrc->nCols;
638,196✔
222
    pDst->version = pSrc->version;
638,196✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
638,196✔
224
    if (NULL == pDst->pColRef) {
638,196✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
638,196✔
228
  }
229
  return 0;
638,196✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
58,802,406✔
233
  int32_t code = 0;
58,802,406✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
117,566,940✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
117,558,289✔
236
  uTrace("encode cols:%d", pw->nCols);
58,793,755✔
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;
58,853,786✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
58,610,679✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
58,610,679✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
58,684,065✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,200,952,763✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,200,952,763✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
252
  if (pWrapper->nCols == 0) {
1,201,109,477✔
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,201,372,932✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
1,201,234,344✔
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,202,000,402✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
169,836✔
273

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

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

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

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
165,458,424✔
294
  if (pSrc->nCols > 0) {
165,458,424✔
295
    pDst->nCols = pSrc->nCols;
149,377,226✔
296
    pDst->version = pSrc->version;
149,378,759✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
149,371,505✔
298
    if (NULL == pDst->pColCmpr) {
149,361,358✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
149,354,933✔
302
  }
303
  return 0;
165,469,201✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
166,085,325✔
307
  if (pColRef) {
166,085,325✔
308
    taosMemoryFreeClear(pColRef->pColRef);
166,092,656✔
309
  }
310
}
166,095,963✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
166,085,371✔
313
  if (pCmpr) {
166,085,371✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
166,093,781✔
315
  }
316
}
166,072,857✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
196,079,274✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
196,079,274✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
392,190,811✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
392,147,820✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
392,072,722✔
323

324
  if (pME->type > 0) {
196,025,487✔
325
    if (pME->name == NULL) {
191,684,450✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
383,353,607✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
191,680,837✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
48,195,338✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
48,280,965✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
48,250,157✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
24,086,328✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
71,400✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
167,576,820✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
264,427,376✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
264,421,989✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
264,416,209✔
342
      if (pME->ctbEntry.commentLen > 0) {
132,210,487✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,604✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
264,420,212✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
132,206,989✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
35,370,778✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
70,741,556✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
70,741,556✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
70,741,556✔
351
      if (pME->ntbEntry.commentLen > 0) {
35,370,778✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
37,348✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
70,741,556✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
70,741,556✔
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) {
191,703,660✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,286,346✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
190,447,056✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,130,445✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
166,349,646✔
368
        if (pME->colCmpr.nCols != 0) {
34,719,510✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
34,549,674✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
169,836✔
372
          SColCmprWrapper colCmprs = {0};
169,836✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
169,836✔
374
          if (code != 0) {
169,836✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
169,836✔
379
          taosMemoryFree(colCmprs.pColCmpr);
169,836✔
380
          TAOS_CHECK_RETURN(code);
169,836✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
191,709,092✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
196,057,323✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
48,224,312✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
48,135,498✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
171,932,270✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
69,439,020✔
391
  }
392

393
  tEndEncode(pCoder);
196,011,165✔
394
  return 0;
196,064,385✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,022,573,331✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,022,573,331✔
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) {
2,023,650,987✔
404
    tEndDecode(pCoder);
309,428✔
405
    return 0;
309,428✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
2,023,104,819✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,820,060,462✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,820,058,280✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,819,455,064✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
909,586,697✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
273,462✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,112,382,730✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,630,090,051✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,630,251,533✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,629,862,403✔
422
      if (pME->ctbEntry.commentLen > 0) {
814,734,804✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
47,776✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,629,966,915✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
815,132,955✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
297,887,491✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
595,921,435✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
596,013,369✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
595,892,701✔
431
      if (pME->ntbEntry.commentLen > 0) {
297,877,583✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
69,154✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
595,821,933✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
595,937,554✔
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) {
2,022,571,619✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
909,892,140✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
909,921,565✔
449

450
        if (pME->colCmpr.nCols == 0) {
909,694,629✔
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,112,467,296✔
458
      if (!tDecodeIsEnd(pCoder)) {
291,657,235✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
291,709,187✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
291,709,384✔
461
        if (pME->colCmpr.nCols == 0) {
291,657,981✔
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);
291,700,638✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
820,776,519✔
470
      if (!tDecodeIsEnd(pCoder)) {
28,365,935✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
28,366,209✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
28,366,209✔
473
      } else {
474
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
48✔
475
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
48✔
476
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
477
        }
478
      }
479
    }
480
    if (!tDecodeIsEnd(pCoder)) {
2,022,795,477✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,201,616,176✔
482
    } else {
483
      pME->pExtSchemas = NULL;
821,179,301✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
2,022,043,118✔
487
    if (!tDecodeIsEnd(pCoder)) {
909,723,740✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,819,289,878✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
909,492,388✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,819,273,430✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,112,372,653✔
494
    if (!tDecodeIsEnd(pCoder)) {
291,689,842✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
583,379,386✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
2,022,013,371✔
501
  return 0;
2,022,278,080✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,022,434,327✔
505

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

511
  pDst->nCols = pSrc->nCols;
291,223,264✔
512
  pDst->version = pSrc->version;
291,215,723✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
291,211,317✔
514
  if (pDst->pSchema == NULL) {
291,112,692✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
291,131,872✔
518
  return TSDB_CODE_SUCCESS;
291,224,083✔
519
}
520

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

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

549
  return TSDB_CODE_SUCCESS;
42,126✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
291,172,981✔
553
  if (pSchema) {
291,172,981✔
554
    taosMemoryFreeClear(pSchema->pSchema);
291,183,739✔
555
  }
556
}
291,162,937✔
557

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

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

576
  taosMemoryFreeClear((*ppEntry)->name);
166,094,339✔
577

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

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
166,071,141✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
141,405,782✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
141,391,092✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
141,386,372✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,546✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,679,334✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,292,301✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,292,301✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,387,763✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,387,763✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,387,763✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
166,086,625✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
166,062,613✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
166,074,803✔
601

602
  taosMemoryFreeClear(*ppEntry);
166,045,673✔
603
  return;
166,041,272✔
604
}
605

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

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

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
166,098,246✔
614
  if (NULL == *ppEntry) {
166,032,327✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
166,065,146✔
619
  (*ppEntry)->type = pEntry->type;
166,088,499✔
620
  (*ppEntry)->uid = pEntry->uid;
166,077,652✔
621

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

626
  if (pEntry->name) {
166,055,223✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
166,085,604✔
628
    if (NULL == (*ppEntry)->name) {
166,092,670✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
166,078,767✔
636
    (*ppEntry)->flags = pEntry->flags;
141,419,671✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
141,407,023✔
639
    if (code) {
141,415,148✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
141,415,148✔
645
    if (code) {
141,424,824✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
141,424,824✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,126✔
651
      if (code) {
42,126✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
141,424,535✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
141,422,536✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,679,539✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,292,126✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,292,301✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,292,301✔
662

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

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

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

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

712
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
166,100,333✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
645,556✔
714
    if (code) {
638,196✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
165,457,642✔
720
    if (code) {
165,468,598✔
UNCOV
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
166,106,794✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,241,683✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,235,714✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,238,369✔
733
  }
734

735
  return code;
166,092,827✔
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