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

taosdata / TDengine / #4933

20 Jan 2026 10:44AM UTC coverage: 66.671% (+0.03%) from 66.646%
#4933

push

travis-ci

web-flow
merge: from main to 3.0 #34340

73 of 178 new or added lines in 9 files covered. (41.01%)

1199 existing lines in 124 files now uncovered.

203121 of 304663 relevant lines covered (66.67%)

132228377.94 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,257,568,954✔
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,678,243✔
26
    }
27
  }
28
  return false;
1,229,357,814✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
174,424,192✔
32
  if (pME->pExtSchemas) {
174,424,192✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
11,676,930✔
34
    bool                  hasTypeMods = false;
11,676,930✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
11,676,930✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
11,595,405✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
88,044✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
88,044✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,682,962✔
43

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

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
355,637,834✔
58
    SColRef *p = &pw->pColRef[i];
354,432,098✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
708,864,196✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
708,864,196✔
61
    if (p->hasRef) {
354,432,098✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
424,063,124✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
424,063,124✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
424,063,124✔
65
    }
66
  }
67
  return 0;
1,205,736✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,204,534,935✔
71
  bool hasExtSchema = false;
1,204,534,935✔
72
  SSchemaWrapper* pSchWrapper = NULL;
1,204,534,935✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
1,204,534,935✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
917,876,426✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
286,886,526✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
286,926,648✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,204,888,899✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,204,525,992✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
35,883,188✔
84
    if (pME->pExtSchemas == NULL) {
17,944,851✔
85
      return terrno;
×
86
    }
87

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

95
  return 0;
1,204,884,815✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
41,450,964✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
41,450,964✔
100
  bool                  hasTypeMods = false;
41,450,964✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
41,450,964✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
30,101,401✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,385,385✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,388,801✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
41,490,861✔
109

110
  if (hasTypeMods) {
41,377,524✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
38,094✔
112
    if (ret != NULL) {
38,094✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
38,094✔
114
    }
115
    return ret;
38,094✔
116
  }
117
  return NULL;
41,339,430✔
118
}
119

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
25,848✔
151
  int32_t    i = 0, j = 0;
25,848✔
152
  for (i = 0; i < nCols; ++i) {
198,886✔
153
    while (j < pParam->nFuncs) {
314,484✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
302,278✔
155
        pFuncIds[i] = pParam->funcIds[j];
141,446✔
156
        break;
141,446✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
160,832✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,592✔
160
        break;
31,592✔
161
      }
162
      ++j;
129,240✔
163
    }
164
    if (j >= pParam->nFuncs) {
185,244✔
165
      for (; i < nCols; ++i) {
24,412✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,206✔
167
      }
168
      break;
12,206✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
25,848✔
172

173
  return 0;
25,848✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
32,449,313✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
32,449,313✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
64,904,763✔
179
  if (pWrapper->nCols == 0) {
32,453,007✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
64,901,277✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
32,451,964✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
64,905,375✔
186
  if (pWrapper->pColRef == NULL) {
32,454,101✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
757,977,680✔
191
    SColRef *p = &pWrapper->pColRef[i];
725,512,473✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,450,997,124✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,451,022,845✔
194
    if (p->hasRef) {
725,560,371✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
401,780,052✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
401,779,528✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
401,780,229✔
198
    }
199
  }
200
  return 0;
32,456,633✔
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) {
634,734✔
220
  if (pSrc->nCols > 0) {
634,734✔
221
    pDst->nCols = pSrc->nCols;
634,734✔
222
    pDst->version = pSrc->version;
634,734✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
634,734✔
224
    if (NULL == pDst->pColRef) {
634,734✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
634,734✔
228
  }
229
  return 0;
634,734✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
41,709,668✔
233
  int32_t code = 0;
41,709,668✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
83,401,675✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
83,398,286✔
236
  uTrace("encode cols:%d", pw->nCols);
41,706,279✔
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;
41,761,272✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
41,565,609✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
41,565,609✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
41,571,031✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,204,600,390✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,204,600,390✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
252
  if (pWrapper->nCols == 0) {
1,204,305,413✔
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,204,910,209✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
259
  if (pWrapper->pColCmpr == NULL) {
1,204,897,886✔
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,205,542,349✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
203,596✔
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,040,162✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
836,566✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
836,566✔
287
    pColCmpr->id = pColSchema->colId;
836,566✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
836,566✔
289
  }
290
  return 0;
203,596✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
165,348,097✔
294
  if (pSrc->nCols > 0) {
165,348,097✔
295
    pDst->nCols = pSrc->nCols;
149,119,840✔
296
    pDst->version = pSrc->version;
149,117,043✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
149,120,743✔
298
    if (NULL == pDst->pColCmpr) {
149,102,843✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
149,104,354✔
302
  }
303
  return 0;
165,360,431✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
165,983,087✔
307
  if (pColRef) {
165,983,087✔
308
    taosMemoryFreeClear(pColRef->pColRef);
165,988,274✔
309
  }
310
}
165,991,018✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
165,981,834✔
313
  if (pCmpr) {
165,981,834✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
165,985,438✔
315
  }
316
}
165,980,790✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
178,819,602✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
178,819,602✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
357,605,419✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
357,580,189✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
357,590,134✔
323

324
  if (pME->type > 0) {
178,794,659✔
325
    if (pME->name == NULL) {
174,442,342✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
348,832,555✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
174,407,371✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
47,998,012✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
48,060,103✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
48,033,430✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
23,987,649✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
73,954✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
150,416,078✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
264,072,096✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
264,068,943✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
264,065,003✔
342
      if (pME->ctbEntry.commentLen > 0) {
132,036,649✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,624✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
264,064,198✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
132,029,185✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
18,388,142✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
36,776,284✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
36,776,284✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
36,776,284✔
351
      if (pME->ntbEntry.commentLen > 0) {
18,388,142✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
38,264✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
36,776,284✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
36,776,284✔
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) {
174,421,898✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,263,182✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
173,181,735✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,010,192✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
149,196,490✔
368
        if (pME->colCmpr.nCols != 0) {
17,738,996✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
17,535,400✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
203,596✔
372
          SColCmprWrapper colCmprs = {0};
203,596✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
203,596✔
374
          if (code != 0) {
203,596✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
203,596✔
379
          taosMemoryFree(colCmprs.pColCmpr);
203,596✔
380
          TAOS_CHECK_RETURN(code);
203,596✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
174,438,182✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
178,785,309✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
48,014,760✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
47,953,777✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
154,779,608✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
35,477,992✔
391
  }
392

393
  tEndEncode(pCoder);
178,767,262✔
394
  return 0;
178,808,318✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,035,391,968✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,035,391,968✔
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,036,316,450✔
404
    tEndDecode(pCoder);
320,146✔
405
    return 0;
320,146✔
406
  }
407

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

411
    if (pME->type == TSDB_SUPER_TABLE) {
2,035,787,248✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,836,550,543✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,836,592,259✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,836,006,850✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
917,832,479✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
273,558✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,116,937,463✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,646,858,409✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,647,067,768✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,646,666,674✔
422
      if (pME->ctbEntry.commentLen > 0) {
823,122,664✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
47,772✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,646,763,550✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
823,545,901✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
293,862,593✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
587,941,181✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
588,054,816✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
587,894,683✔
431
      if (pME->ntbEntry.commentLen > 0) {
293,861,333✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
70,620✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
587,805,595✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
587,935,854✔
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,035,268,998✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
918,130,578✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
918,077,766✔
449

450
        if (pME->colCmpr.nCols == 0) {
918,074,024✔
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,116,877,371✔
458
      if (!tDecodeIsEnd(pCoder)) {
286,938,204✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
286,999,256✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
286,999,256✔
461
        if (pME->colCmpr.nCols == 0) {
286,927,176✔
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);
286,962,823✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
829,927,012✔
470
      if (!tDecodeIsEnd(pCoder)) {
32,455,290✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
32,456,134✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
32,456,850✔
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)) {
2,035,457,804✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,205,221,855✔
482
    } else {
483
      pME->pExtSchemas = NULL;
830,235,949✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
2,034,830,985✔
487
    if (!tDecodeIsEnd(pCoder)) {
917,911,971✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,835,950,003✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
917,846,398✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,835,655,906✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,116,698,661✔
494
    if (!tDecodeIsEnd(pCoder)) {
286,957,602✔
495
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->ntbEntry.ownerId));
573,927,143✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
2,034,420,930✔
501
  return 0;
2,035,159,900✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,035,211,155✔
505

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

511
  pDst->nCols = pSrc->nCols;
290,676,228✔
512
  pDst->version = pSrc->version;
290,661,558✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
290,658,816✔
514
  if (pDst->pSchema == NULL) {
290,582,221✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
290,597,467✔
518
  return TSDB_CODE_SUCCESS;
290,679,133✔
519
}
520

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

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

549
  return TSDB_CODE_SUCCESS;
42,362✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
290,635,780✔
553
  if (pSchema) {
290,635,780✔
554
    taosMemoryFreeClear(pSchema->pSchema);
290,645,404✔
555
  }
556
}
290,641,296✔
557

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

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

576
  taosMemoryFreeClear((*ppEntry)->name);
165,990,844✔
577

578
  if ((*ppEntry)->type < 0) {
165,977,103✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
165,975,836✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
141,117,602✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
141,102,275✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
141,101,384✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,902✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,867,686✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,433,853✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,434,313✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,434,449✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,434,449✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,434,449✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
165,979,701✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
165,972,337✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
165,971,307✔
601

602
  taosMemoryFreeClear(*ppEntry);
165,956,380✔
603
  return;
165,972,017✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
165,972,292✔
607
  int32_t code = TSDB_CODE_SUCCESS;
165,972,292✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
165,972,292✔
610
    return TSDB_CODE_INVALID_PARA;
2,725✔
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
165,969,852✔
614
  if (NULL == *ppEntry) {
165,931,272✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
165,959,852✔
619
  (*ppEntry)->type = pEntry->type;
165,978,206✔
620
  (*ppEntry)->uid = pEntry->uid;
165,978,583✔
621

622
  if (pEntry->type < 0) {
165,968,987✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
165,958,733✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
165,980,723✔
628
    if (NULL == (*ppEntry)->name) {
165,984,071✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
165,972,320✔
636
    (*ppEntry)->flags = pEntry->flags;
141,122,048✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
141,109,473✔
639
    if (code) {
141,119,042✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
141,119,042✔
645
    if (code) {
141,126,811✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
141,126,811✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,362✔
651
      if (code) {
42,362✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
141,125,701✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
141,121,105✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,868,474✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,434,025✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,434,025✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,434,313✔
662

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

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

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

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,434,449✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,434,449✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
11,856✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
11,856✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
11,856✔
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) {
165,986,210✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
637,269✔
714
    if (code) {
634,734✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
165,353,268✔
720
    if (code) {
165,356,185✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
165,990,919✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,116,838✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,115,781✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,113,231✔
733
  }
734

735
  return code;
165,983,208✔
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