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

taosdata / TDengine / #4885

15 Dec 2025 03:26AM UTC coverage: 65.258% (+4.6%) from 60.617%
#4885

push

travis-ci

web-flow
feat(tmq): [TS-6379]remove limition for table operation in tmq  (#33834)

872 of 1074 new or added lines in 16 files covered. (81.19%)

659 existing lines in 92 files now uncovered.

177890 of 272597 relevant lines covered (65.26%)

103732965.73 hits per line

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

80.5
/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) {
689,486,966✔
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;
40,588,610✔
26
    }
27
  }
28
  return false;
647,939,755✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
181,679,716✔
32
  if (pME->pExtSchemas) {
181,679,716✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
14,905,041✔
34
    bool                  hasTypeMods = false;
14,905,041✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
14,905,041✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
14,755,182✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
152,230✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
152,230✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,910,836✔
43

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

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
12,068,492✔
58
    SColRef *p = &pw->pColRef[i];
10,800,508✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
21,601,016✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
21,601,016✔
61
    if (p->hasRef) {
10,800,508✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
12,077,012✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
12,077,012✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
12,077,012✔
65
    }
66
  }
67
  return 0;
1,267,984✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
660,241,076✔
71
  bool hasExtSchema = false;
660,241,076✔
72
  SSchemaWrapper* pSchWrapper = NULL;
660,241,076✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
660,241,076✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
653,145,946✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
7,120,376✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
7,120,376✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
660,212,119✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
660,219,244✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
57,540,579✔
84
    if (pME->pExtSchemas == NULL) {
28,771,280✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
2,047,428,804✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
631,450,681✔
93
  }
94

95
  return 0;
660,274,589✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
14,377,018✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
14,377,018✔
100
  bool                  hasTypeMods = false;
14,377,018✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
14,377,018✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
12,628,772✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,757,342✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
1,759,058✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,385,111✔
109

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

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

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

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
27,792✔
151
  int32_t    i = 0, j = 0;
27,792✔
152
  for (i = 0; i < nCols; ++i) {
213,844✔
153
    while (j < pParam->nFuncs) {
338,136✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
325,012✔
155
        pFuncIds[i] = pParam->funcIds[j];
152,084✔
156
        break;
152,084✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
172,928✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
33,968✔
160
        break;
33,968✔
161
      }
162
      ++j;
138,960✔
163
    }
164
    if (j >= pParam->nFuncs) {
199,176✔
165
      for (; i < nCols; ++i) {
26,248✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
13,124✔
167
      }
168
      break;
13,124✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
27,792✔
172

173
  return 0;
27,792✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
11,500,123✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
11,500,123✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
23,000,275✔
179
  if (pWrapper->nCols == 0) {
11,499,750✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
22,999,902✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
11,500,152✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
23,000,266✔
186
  if (pWrapper->pColRef == NULL) {
11,500,152✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
135,760,976✔
191
    SColRef *p = &pWrapper->pColRef[i];
124,257,684✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
248,551,552✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
248,560,183✔
194
    if (p->hasRef) {
124,281,478✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
72,993,136✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
72,986,405✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
72,990,041✔
198
    }
199
  }
200
  return 0;
11,500,525✔
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) {
711,221✔
220
  if (pSrc->nCols > 0) {
711,221✔
221
    pDst->nCols = pSrc->nCols;
711,221✔
222
    pDst->version = pSrc->version;
711,221✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
711,221✔
224
    if (NULL == pDst->pColRef) {
711,221✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
711,221✔
228
  }
229
  return 0;
711,221✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
43,533,458✔
233
  int32_t code = 0;
43,533,458✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
87,079,261✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
87,114,262✔
236
  uTrace("encode cols:%d", pw->nCols);
43,568,459✔
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;
43,596,638✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
43,338,437✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
43,338,437✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
43,340,744✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
745,802,384✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
745,802,384✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,491,711,530✔
252
  if (pWrapper->nCols == 0) {
745,809,741✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,491,620,983✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
745,838,202✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,491,700,034✔
259
  if (pWrapper->pColCmpr == NULL) {
745,902,024✔
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;
746,038,768✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
251,200✔
273

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

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

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,281,906✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,030,706✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,030,706✔
287
    pColCmpr->id = pColSchema->colId;
1,030,706✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,030,706✔
289
  }
290
  return 0;
251,200✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
175,039,601✔
294
  if (pSrc->nCols > 0) {
175,039,601✔
295
    pDst->nCols = pSrc->nCols;
157,664,644✔
296
    pDst->version = pSrc->version;
157,665,763✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
157,650,665✔
298
    if (NULL == pDst->pColCmpr) {
157,655,114✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
157,642,519✔
302
  }
303
  return 0;
175,039,000✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
175,752,354✔
307
  if (pColRef) {
175,752,354✔
308
    taosMemoryFreeClear(pColRef->pColRef);
175,754,528✔
309
  }
310
}
175,759,399✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
175,750,149✔
313
  if (pCmpr) {
175,750,149✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
175,753,910✔
315
  }
316
}
175,753,223✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
185,673,644✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
185,673,644✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
371,368,805✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
371,366,099✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
371,368,371✔
323

324
  if (pME->type > 0) {
185,677,588✔
325
    if (pME->name == NULL) {
181,718,045✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
363,431,946✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
181,716,828✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
63,409,457✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
63,463,084✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
63,445,204✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
31,693,583✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
79,516✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
150,005,999✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
274,951,936✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
274,952,316✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
274,949,555✔
342
      if (pME->ctbEntry.commentLen > 0) {
137,473,707✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
15,392✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
274,956,015✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
137,478,730✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
12,533,114✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
25,066,228✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
25,066,228✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
25,066,228✔
351
      if (pME->ntbEntry.commentLen > 0) {
12,533,114✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
14,352✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
25,066,228✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
25,066,228✔
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,711,759✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,354,711✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
180,367,304✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
31,718,541✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
148,744,070✔
368
        if (pME->colCmpr.nCols != 0) {
11,865,154✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
11,613,954✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
251,200✔
372
          SColCmprWrapper colCmprs = {0};
251,200✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
251,200✔
374
          if (code != 0) {
251,200✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
251,200✔
379
          taosMemoryFree(colCmprs.pColCmpr);
251,200✔
380
          TAOS_CHECK_RETURN(code);
251,200✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
181,738,823✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
185,680,154✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
63,401,203✔
388
  }
389

390
  tEndEncode(pCoder);
185,681,565✔
391
  return 0;
185,662,089✔
392
}
393

394
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,314,258,072✔
395
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,314,258,072✔
396
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
397
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
398
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
399

400
  if (headerOnly) {
1,314,656,648✔
401
    tEndDecode(pCoder);
109,328✔
402
    return 0;
109,328✔
403
  }
404

405
  if (pME->type > 0) {
1,314,547,320✔
406
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
407

408
    if (pME->type == TSDB_SUPER_TABLE) {
1,314,374,845✔
409
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,306,545,426✔
410
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,306,571,970✔
411
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,306,533,255✔
412
      if (TABLE_IS_ROLLUP(pME->flags)) {
653,236,696✔
413
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
294,904✔
414
      }
415
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
660,941,666✔
416
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,131,850,767✔
417
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,132,002,282✔
418
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,131,901,682✔
419
      if (pME->ctbEntry.commentLen > 0) {
565,905,199✔
420
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
21,556✔
421
      }
422
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,131,829,226✔
423
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
565,997,400✔
424
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
95,222,011✔
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
190,465,842✔
426
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
190,483,025✔
427
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
190,470,692✔
428
      if (pME->ntbEntry.commentLen > 0) {
95,229,288✔
429
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
21,184✔
430
      }
431
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
190,449,717✔
432
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
190,457,949✔
433
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
434
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
435
      if (!pME->smaEntry.tsma) {
×
436
        return terrno;
×
437
      }
438
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
439
    } else {
440
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
441
      return TSDB_CODE_INVALID_PARA;
×
442
    }
443
    if (pME->type == TSDB_SUPER_TABLE) {
1,314,208,248✔
444
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
653,265,388✔
445
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
653,265,416✔
446

447
        if (pME->colCmpr.nCols == 0) {
653,333,372✔
448
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
449
        }
450
      } else {
451
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
453
      }
454
    } else if (pME->type == TSDB_NORMAL_TABLE) {
660,857,940✔
455
      if (!tDecodeIsEnd(pCoder)) {
92,692,234✔
456
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
92,695,494✔
457
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
92,696,286✔
458
        if (pME->colCmpr.nCols == 0) {
92,684,524✔
459
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
460
        }
461
      } else {
UNCOV
462
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
463
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
464
      }
465
      TABLE_SET_COL_COMPRESSED(pME->flags);
92,685,152✔
466
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
568,196,099✔
467
      if (!tDecodeIsEnd(pCoder)) {
11,499,351✔
468
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
11,499,351✔
469
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
11,500,123✔
470
      } else {
471
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
472
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
473
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
474
        }
475
      }
476
    }
477
    if (!tDecodeIsEnd(pCoder)) {
1,314,382,473✔
478
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
660,361,789✔
479
    } else {
480
      pME->pExtSchemas = NULL;
654,020,684✔
481
    }
482
  }
483
  if (pME->type == TSDB_SUPER_TABLE) {
1,314,191,140✔
484
    if (!tDecodeIsEnd(pCoder)) {
653,129,472✔
485
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,306,443,132✔
486
    }
487
  }
488

489

490
  tEndDecode(pCoder);
1,314,286,921✔
491
  return 0;
1,314,220,436✔
492
}
493

494
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,314,200,583✔
495

496
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
307,433,100✔
497
  if (pSrc == NULL || pDst == NULL) {
307,433,100✔
498
    return TSDB_CODE_INVALID_PARA;
×
499
  }
500

501
  pDst->nCols = pSrc->nCols;
307,442,388✔
502
  pDst->version = pSrc->version;
307,438,287✔
503
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
307,439,564✔
504
  if (pDst->pSchema == NULL) {
307,379,159✔
505
    return terrno;
×
506
  }
507
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
307,399,095✔
508
  return TSDB_CODE_SUCCESS;
307,447,639✔
509
}
510

511
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
45,548✔
512
  if (pSrc == NULL || pDst == NULL) {
45,548✔
513
    return TSDB_CODE_INVALID_PARA;
×
514
  }
515
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
45,548✔
516
  pDst->name = tstrdup(pSrc->name);
45,548✔
517
  if (pDst->name == NULL) {
45,548✔
518
    return terrno;
×
519
  }
520
  if (pSrc->nFuncs > 0) {
45,548✔
521
    pDst->nFuncs = pSrc->nFuncs;
45,548✔
522
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
45,548✔
523
    if (pDst->funcColIds == NULL) {
45,548✔
524
      return terrno;
×
525
    }
526
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
45,548✔
527

528
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
45,548✔
529
    if (pDst->funcIds == NULL) {
45,548✔
530
      return terrno;
×
531
    }
532
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
45,548✔
533
  } else {
534
    pDst->nFuncs = 0;
×
535
    pDst->funcColIds = NULL;
×
536
    pDst->funcIds = NULL;
×
537
  }
538

539
  return TSDB_CODE_SUCCESS;
45,548✔
540
}
541

542
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
307,435,926✔
543
  if (pSchema) {
307,435,926✔
544
    taosMemoryFreeClear(pSchema->pSchema);
307,448,188✔
545
  }
546
}
307,422,576✔
547

548
/**
549
 * @param type 0x01 free name
550
 */
551
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
68,708✔
552
  if (pParam) {
68,708✔
553
    if ((type & 0x01)) {
68,708✔
554
      taosMemoryFreeClear(pParam->name);
68,708✔
555
    }
556
    taosMemoryFreeClear(pParam->funcColIds);
67,936✔
557
    taosMemoryFreeClear(pParam->funcIds);
68,708✔
558
  }
559
}
68,708✔
560

561
void metaCloneEntryFree(SMetaEntry **ppEntry) {
175,827,507✔
562
  if (ppEntry == NULL || *ppEntry == NULL) {
175,827,507✔
563
    return;
80,788✔
564
  }
565

566
  taosMemoryFreeClear((*ppEntry)->name);
175,751,269✔
567

568
  if ((*ppEntry)->type < 0) {
175,765,850✔
569
    taosMemoryFreeClear(*ppEntry);
×
570
    return;
×
571
  }
572

573
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
175,733,787✔
574
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
149,293,460✔
575
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
149,297,559✔
576
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
149,299,643✔
577
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
68,708✔
578
    }
579
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
26,445,428✔
580
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
17,615,853✔
581
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
17,615,853✔
582
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,831,373✔
583
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,831,373✔
584
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,831,373✔
585
  } else {
586
    return;
×
587
  }
588
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
175,749,011✔
589
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
175,739,521✔
590
  metaCloneColRefFree(&(*ppEntry)->colRef);
175,745,909✔
591

592
  taosMemoryFreeClear(*ppEntry);
175,735,051✔
593
  return;
175,740,332✔
594
}
595

596
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
175,740,282✔
597
  int32_t code = TSDB_CODE_SUCCESS;
175,740,282✔
598

599
  if (NULL == pEntry || NULL == ppEntry) {
175,740,282✔
600
    return TSDB_CODE_INVALID_PARA;
×
601
  }
602

603
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
175,760,140✔
604
  if (NULL == *ppEntry) {
175,720,501✔
605
    return terrno;
×
606
  }
607

608
  (*ppEntry)->version = pEntry->version;
175,728,911✔
609
  (*ppEntry)->type = pEntry->type;
175,727,318✔
610
  (*ppEntry)->uid = pEntry->uid;
175,744,016✔
611

612
  if (pEntry->type < 0) {
175,753,189✔
613
    return TSDB_CODE_SUCCESS;
×
614
  }
615

616
  if (pEntry->name) {
175,754,088✔
617
    (*ppEntry)->name = tstrdup(pEntry->name);
175,744,820✔
618
    if (NULL == (*ppEntry)->name) {
175,756,684✔
619
      code = terrno;
×
620
      metaCloneEntryFree(ppEntry);
×
621
      return code;
×
622
    }
623
  }
624

625
  if (pEntry->type == TSDB_SUPER_TABLE) {
175,745,892✔
626
    (*ppEntry)->flags = pEntry->flags;
149,298,187✔
627

628
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
149,303,406✔
629
    if (code) {
149,308,401✔
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633

634
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
149,308,401✔
635
    if (code) {
149,313,230✔
636
      metaCloneEntryFree(ppEntry);
×
637
      return code;
×
638
    }
639
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
149,313,230✔
640
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
45,548✔
641
      if (code) {
45,548✔
642
        metaCloneEntryFree(ppEntry);
×
643
        return code;
×
644
      }
645
    }
646
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
149,307,387✔
647
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
26,447,226✔
648
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
17,615,853✔
649
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
17,615,853✔
650
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
17,615,853✔
651

652
    // comment
653
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
17,615,853✔
654
    if (pEntry->ctbEntry.commentLen > 0) {
17,615,853✔
655
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
4,690✔
656
      if (NULL == (*ppEntry)->ctbEntry.comment) {
4,690✔
657
        code = terrno;
×
658
        metaCloneEntryFree(ppEntry);
×
659
        return code;
×
660
      }
661
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
4,690✔
662
    }
663

664
    // tags
665
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
17,615,853✔
666
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
17,615,853✔
667
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
17,615,853✔
668
      code = terrno;
×
669
      metaCloneEntryFree(ppEntry);
×
670
      return code;
×
671
    }
672
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
17,615,853✔
673
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,831,373✔
674
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,831,373✔
675
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,831,373✔
676
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,831,373✔
677

678
    // schema
679
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
8,831,373✔
680
    if (code) {
8,831,373✔
681
      metaCloneEntryFree(ppEntry);
×
682
      return code;
×
683
    }
684

685
    // comment
686
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,831,373✔
687
    if (pEntry->ntbEntry.commentLen > 0) {
8,831,373✔
688
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
4,506✔
689
      if (NULL == (*ppEntry)->ntbEntry.comment) {
4,506✔
690
        code = terrno;
×
691
        metaCloneEntryFree(ppEntry);
×
692
        return code;
×
693
      }
694
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
4,506✔
695
    }
696
  } else {
697
    return TSDB_CODE_INVALID_PARA;
×
698
  }
699

700
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
175,755,652✔
701
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
720,319✔
702
    if (code) {
711,221✔
703
      metaCloneEntryFree(ppEntry);
×
704
      return code;
×
705
    }
706
  } else {
707
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
175,036,038✔
708
    if (code) {
175,035,276✔
709
      metaCloneEntryFree(ppEntry);
×
710
      return code;
×
711
    }
712
  }
713
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
175,746,497✔
714
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
12,644,988✔
715
    if (!(*ppEntry)->pExtSchemas) {
12,647,199✔
716
      code = terrno;
×
717
      metaCloneEntryFree(ppEntry);
×
718
      return code;
×
719
    }
720
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
12,643,176✔
721
  }
722

723
  return code;
175,749,746✔
724
}
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