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

taosdata / TDengine / #3660

15 Mar 2025 09:06AM UTC coverage: 62.039% (-1.3%) from 63.314%
#3660

push

travis-ci

web-flow
feat(stream): support stream processing for virtual tables (#30144)

* enh: add client processing

* enh: add mnode vtables processing

* enh: add mnode vtable processing

* enh: add normal child vtable support

* fix: compile issues

* fix: compile issues

* fix: create stream issues

* fix: multi stream scan issue

* fix: remove debug info

* fix: agg task and task level issues

* fix: correct task output type

* fix: split vtablescan from agg

* fix: memory leak issues

* fix: add limitations

* Update 09-error-code.md

* Update 09-error-code.md

* fix: remove usless case

* feat(stream): extract original table data in source scan task

Implemented functionality in the source task to extract data
corresponding to the virtual table from the original table using WAL.
The extracted data is then sent to the downstream merge task for further
processing.

* feat(stream): multi-way merge using loser tree in virtual merge task

Implemented multi-way merge in the merge task using a loser tree to
combine data from multiple original table into a single virtual table.
The merged virtual table data is then pushed downstream for further
processing.  Introduced memory limit handling during the merge process
with configurable behavior when the memory limit is reached.

* fix(test): remove useless cases

---------

Co-authored-by: dapan1121 <wpan@taosdata.com>
Co-authored-by: Pan Wei <72057773+dapan1121@users.noreply.github.com>

154078 of 317582 branches covered (48.52%)

Branch coverage included in aggregate %.

313 of 2391 new or added lines in 34 files covered. (13.09%)

26134 existing lines in 205 files now uncovered.

240261 of 318051 relevant lines covered (75.54%)

16655189.27 hits per line

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

56.84
/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

18
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
19,024,781✔
19
  for (int32_t i = 0; i < nCols; i++) {
442,511,964✔
20
    if (HAS_TYPE_MOD(pSchema + i)) {
423,573,422✔
21
      return true;
86,239✔
22
    }
23
  }
24
  return false;
18,938,542✔
25
}
26

27
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
392,039✔
28
  if (pME->pExtSchemas) {
392,039✔
29
    const SSchemaWrapper *pSchWrapper = NULL;
11,007✔
30
    bool                  hasTypeMods = false;
11,007✔
31
    if (pME->type == TSDB_SUPER_TABLE) {
11,007✔
32
      pSchWrapper = &pME->stbEntry.schemaRow;
10,797✔
33
    } else if (pME->type == TSDB_NORMAL_TABLE) {
210!
34
      pSchWrapper = &pME->ntbEntry.schemaRow;
214✔
35
    } else {
UNCOV
36
      return 0;
×
37
    }
38
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
11,011✔
39

40
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
4,090,859✔
41
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
8,159,704!
42
    }
43
  }
44
  return 0;
392,039✔
45
}
46

UNCOV
47
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
×
UNCOV
48
  const SColRefWrapper *pw = &pME->colRef;
×
UNCOV
49
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
×
UNCOV
50
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
×
UNCOV
51
  uDebug("encode cols:%d", pw->nCols);
×
52

UNCOV
53
  for (int32_t i = 0; i < pw->nCols; i++) {
×
54
    SColRef *p = &pw->pColRef[i];
×
UNCOV
55
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
×
56
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
×
UNCOV
57
    if (p->hasRef) {
×
UNCOV
58
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
×
UNCOV
59
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
×
UNCOV
60
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
×
61
    }
62
  }
UNCOV
63
  return 0;
×
64
}
65

66
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
28,209,064✔
67
  bool hasExtSchema = false;
28,209,064✔
68
  SSchemaWrapper* pSchWrapper = NULL;
28,209,064✔
69
  if (pME->type == TSDB_SUPER_TABLE) {
28,209,064✔
70
    pSchWrapper = &pME->stbEntry.schemaRow;
18,786,681✔
71
  } else if (pME->type == TSDB_NORMAL_TABLE) {
9,422,383✔
72
    pSchWrapper = &pME->ntbEntry.schemaRow;
33,330✔
73
  } else {
74
    return 0;
9,389,053✔
75
  }
76

77
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
18,820,011✔
78
  if (hasExtSchema && pSchWrapper->nCols > 0) {
18,940,535✔
79
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
75,458!
80
    if (pME->pExtSchemas == NULL) {
75,479!
UNCOV
81
      return terrno;
×
82
    }
83

84
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
5,056,925✔
85
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
9,962,906!
86
    }
87
  }
88

89
  return 0;
18,940,542✔
90
}
91

92
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
117,675✔
93
  const SSchemaWrapper *pSchWrapper = NULL;
117,675✔
94
  bool                  hasTypeMods = false;
117,675✔
95
  if (pME->type == TSDB_SUPER_TABLE) {
117,675✔
96
    pSchWrapper = &pME->stbEntry.schemaRow;
77,205✔
97
  } else if (pME->type == TSDB_NORMAL_TABLE) {
40,470!
98
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,475✔
99
  } else {
UNCOV
100
    return NULL;
×
101
  }
102
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
117,680✔
103

104
  if (hasTypeMods) {
117,676✔
105
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
77!
106
    if (ret != NULL) {
76!
107
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
76✔
108
    }
109
    return ret;
76✔
110
  }
111
  return NULL;
117,599✔
112
}
113

UNCOV
114
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
×
UNCOV
115
  SColRefWrapper *pWrapper = &pME->colRef;
×
UNCOV
116
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
×
UNCOV
117
  if (pWrapper->nCols == 0) {
×
UNCOV
118
    return 0;
×
119
  }
120

UNCOV
121
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
×
UNCOV
122
  uDebug("decode cols:%d", pWrapper->nCols);
×
UNCOV
123
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
×
UNCOV
124
  if (pWrapper->pColRef == NULL) {
×
UNCOV
125
    return terrno;
×
126
  }
127

UNCOV
128
  for (int i = 0; i < pWrapper->nCols; i++) {
×
129
    SColRef *p = &pWrapper->pColRef[i];
×
UNCOV
130
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
×
UNCOV
131
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
×
UNCOV
132
    if (p->hasRef) {
×
UNCOV
133
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
×
UNCOV
134
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
×
UNCOV
135
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
×
136
    }
137
  }
UNCOV
138
  return 0;
×
139
}
140

141
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
142
                                                            SSchemaWrapper *pSchema) {
UNCOV
143
  pRef->nCols = pSchema->nCols;
×
UNCOV
144
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
UNCOV
145
    return terrno;
×
146
  }
147

UNCOV
148
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
UNCOV
149
    SColRef  *pColRef = &pRef->pColRef[i];
×
UNCOV
150
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
UNCOV
151
    pColRef->id = pColSchema->colId;
×
UNCOV
152
    pColRef->hasRef = false;
×
153
  }
UNCOV
154
  return 0;
×
155
}
156

UNCOV
157
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
×
UNCOV
158
  if (pSrc->nCols > 0) {
×
UNCOV
159
    pDst->nCols = pSrc->nCols;
×
UNCOV
160
    pDst->version = pSrc->version;
×
UNCOV
161
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
×
UNCOV
162
    if (NULL == pDst->pColRef) {
×
UNCOV
163
      return terrno;
×
164
    }
UNCOV
165
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
×
166
  }
UNCOV
167
  return 0;
×
168
}
169

170
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
391,535✔
171
  const SColCmprWrapper *pw = &pME->colCmpr;
391,535✔
172
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
783,070!
173
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
783,070!
174
  uDebug("encode cols:%d", pw->nCols);
391,535✔
175

176
  for (int32_t i = 0; i < pw->nCols; i++) {
5,740,829✔
177
    SColCmpr *p = &pw->pColCmpr[i];
5,348,727✔
178
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,697,454!
179
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,697,454!
180
  }
181
  return 0;
392,102✔
182
}
183
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,152,236✔
184
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,152,236✔
185
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
42,250,785!
186
  if (pWrapper->nCols == 0) {
21,098,549!
187
    return 0;
×
188
  }
189

190
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
42,189,812!
191
  uDebug("dencode cols:%d", pWrapper->nCols);
21,091,263✔
192
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,091,442✔
193
  if (pWrapper->pColCmpr == NULL) {
21,168,999!
UNCOV
194
    return terrno;
×
195
  }
196

197
  for (int i = 0; i < pWrapper->nCols; i++) {
459,613,678✔
198
    SColCmpr *p = &pWrapper->pColCmpr[i];
439,118,205✔
199
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
874,707,488!
200
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
874,033,962!
201
  }
202
  return 0;
20,495,473✔
203
}
204
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
205
                                                            SSchemaWrapper *pSchema) {
206
  pCmpr->nCols = pSchema->nCols;
×
UNCOV
207
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
×
UNCOV
208
    return terrno;
×
209
  }
210

UNCOV
211
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
×
UNCOV
212
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
×
UNCOV
213
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
UNCOV
214
    pColCmpr->id = pColSchema->colId;
×
UNCOV
215
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
×
216
  }
UNCOV
217
  return 0;
×
218
}
219

220
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
184,265✔
221
  if (pSrc->nCols > 0) {
184,265✔
222
    pDst->nCols = pSrc->nCols;
173,365✔
223
    pDst->version = pSrc->version;
173,365✔
224
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
173,365!
225
    if (NULL == pDst->pColCmpr) {
173,456!
UNCOV
226
      return terrno;
×
227
    }
228
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
173,456✔
229
  }
230
  return 0;
184,356✔
231
}
232

233
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
184,358✔
234
  if (pColRef) {
184,358!
235
    taosMemoryFreeClear(pColRef->pColRef);
184,367!
236
  }
237
}
184,358✔
238

239
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
184,343✔
240
  if (pCmpr) {
184,343!
241
    taosMemoryFreeClear(pCmpr->pColCmpr);
184,356!
242
  }
243
}
184,351✔
244

245
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
401,738✔
246
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
401,738✔
247
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
804,734!
248
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
804,734!
249
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
804,734!
250

251
  if (pME->type > 0) {
402,367✔
252
    if (pME->name == NULL) {
392,045!
UNCOV
253
      return TSDB_CODE_INVALID_PARA;
×
254
    }
255

256
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
784,090!
257

258
    if (pME->type == TSDB_SUPER_TABLE) {
392,045✔
259
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
148,868!
260
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
148,868!
261
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
148,868!
262
      if (TABLE_IS_ROLLUP(pME->flags)) {
74,434✔
263
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
13!
264
      }
265
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
317,611!
266
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
576,472!
267
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
576,472!
268
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
576,472!
269
      if (pME->ctbEntry.commentLen > 0) {
288,236✔
270
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
271
      }
272
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
576,472!
273
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
288,236!
274
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
29,375!
275
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
58,750!
276
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
58,750!
277
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
58,750!
278
      if (pME->ntbEntry.commentLen > 0) {
29,375✔
279
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
148!
280
      }
281
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
58,750!
282
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
58,750!
UNCOV
283
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
UNCOV
284
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
285
    } else {
UNCOV
286
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
287
      return TSDB_CODE_INVALID_PARA;
×
288
    }
289
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
392,012!
290
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
28!
291
    } else {
292
      TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
391,984!
293
    }
294
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
391,996!
295
  }
296
  if (pME->type == TSDB_SUPER_TABLE) {
401,977✔
297
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
148,268!
298
  }
299

300
  tEndEncode(pCoder);
401,977✔
301
  return 0;
402,072✔
302
}
303

304
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
30,568,119✔
305
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
30,568,119!
306
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
61,040,221!
307
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
60,726,690!
308
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
60,577,340!
309

310
  if (headerOnly) {
30,278,928✔
311
    tEndDecode(pCoder);
11,722✔
312
    return 0;
11,722✔
313
  }
314

315
  if (pME->type > 0) {
30,267,206!
316
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
60,860,503!
317

318
    if (pME->type == TSDB_SUPER_TABLE) {
30,553,468✔
319
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
37,694,209!
320
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
36,664,450!
321
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
37,874,441!
322
      if (TABLE_IS_ROLLUP(pME->flags)) {
20,020,920✔
323
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
270!
324
      }
325
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,670,188!
326
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
18,804,607!
327
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
18,801,052!
328
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
18,803,012!
329
      if (pME->ctbEntry.commentLen > 0) {
9,410,135✔
330
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
331
      }
332
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
18,815,445!
333
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
9,405,310✔
334
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,273,756!
335
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,546,084!
336
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,543,724!
337
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,543,956!
338
      if (pME->ntbEntry.commentLen > 0) {
2,272,560✔
339
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
346!
340
      }
341
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,544,565!
342
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,622,008!
343
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
344
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
345
      if (!pME->smaEntry.tsma) {
×
UNCOV
346
        return terrno;
×
347
      }
UNCOV
348
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
349
    } else {
UNCOV
350
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
UNCOV
351
      return TSDB_CODE_INVALID_PARA;
×
352
    }
353
    if (pME->type == TSDB_SUPER_TABLE) {
30,578,861✔
354
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
18,882,529!
355
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
18,894,239!
356

357
        if (pME->colCmpr.nCols == 0) {
18,826,933!
UNCOV
358
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
359
        }
360
      } else {
UNCOV
361
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
UNCOV
362
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
363
      }
364
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,696,332✔
365
      if (!tDecodeIsEnd(pCoder)) {
2,274,257!
366
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,274,341✔
367
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,274,347✔
368
        if (pME->colCmpr.nCols == 0) {
2,272,583!
UNCOV
369
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
370
        }
371
      } else {
372
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
373
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
374
      }
375
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,272,583✔
376
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
9,422,075!
377
      if (!tDecodeIsEnd(pCoder)) {
×
378
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
379
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
×
380
      } else {
UNCOV
381
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
382
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
UNCOV
383
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
384
        }
385
      }
386
    }
387
    if (!tDecodeIsEnd(pCoder)) {
30,439,298✔
388
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
28,237,332!
389
    }
390
  }
391
  if (pME->type == TSDB_SUPER_TABLE) {
30,513,434✔
392
    if (!tDecodeIsEnd(pCoder)) {
18,902,001!
393
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
37,736,877!
394
    }
395
  }
396

397

398
  tEndDecode(pCoder);
30,441,287✔
399
  return 0;
30,456,773✔
400
}
401

402
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
30,535,417✔
403

404
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
344,142✔
405
  if (pSrc == NULL || pDst == NULL) {
344,142!
UNCOV
406
    return TSDB_CODE_INVALID_PARA;
×
407
  }
408

409
  pDst->nCols = pSrc->nCols;
344,189✔
410
  pDst->version = pSrc->version;
344,189✔
411
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
344,189!
412
  if (pDst->pSchema == NULL) {
344,262!
UNCOV
413
    return terrno;
×
414
  }
415
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
344,262✔
416
  return TSDB_CODE_SUCCESS;
344,262✔
417
}
418

419
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
344,260✔
420
  if (pSchema) {
344,260!
421
    taosMemoryFreeClear(pSchema->pSchema);
344,265!
422
  }
423
}
344,294✔
424

425
void metaCloneEntryFree(SMetaEntry **ppEntry) {
184,336✔
426
  if (ppEntry == NULL || *ppEntry == NULL) {
184,336!
UNCOV
427
    return;
×
428
  }
429

430
  taosMemoryFreeClear((*ppEntry)->name);
184,352!
431

432
  if ((*ppEntry)->type < 0) {
184,353!
UNCOV
433
    taosMemoryFreeClear(*ppEntry);
×
UNCOV
434
    return;
×
435
  }
436

437
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
184,353✔
438
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
170,896✔
439
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
170,897✔
440
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
13,457!
441
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
10,920!
442
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
10,920!
443
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
2,537!
444
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,537✔
445
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,537!
446
  } else {
UNCOV
447
    return;
×
448
  }
449
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
184,368✔
450
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
184,363!
451
  metaCloneColRefFree(&(*ppEntry)->colRef);
184,363✔
452

453
  taosMemoryFreeClear(*ppEntry);
184,366!
454
  return;
184,377✔
455
}
456

457
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
184,257✔
458
  int32_t code = TSDB_CODE_SUCCESS;
184,257✔
459

460
  if (NULL == pEntry || NULL == ppEntry) {
184,257!
UNCOV
461
    return TSDB_CODE_INVALID_PARA;
×
462
  }
463

464
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
184,295!
465
  if (NULL == *ppEntry) {
184,357!
UNCOV
466
    return terrno;
×
467
  }
468

469
  (*ppEntry)->version = pEntry->version;
184,357✔
470
  (*ppEntry)->type = pEntry->type;
184,357✔
471
  (*ppEntry)->uid = pEntry->uid;
184,357✔
472

473
  if (pEntry->type < 0) {
184,357!
UNCOV
474
    return TSDB_CODE_SUCCESS;
×
475
  }
476

477
  if (pEntry->name) {
184,357!
478
    (*ppEntry)->name = tstrdup(pEntry->name);
184,364✔
479
    if (NULL == (*ppEntry)->name) {
184,320!
UNCOV
480
      code = terrno;
×
UNCOV
481
      metaCloneEntryFree(ppEntry);
×
UNCOV
482
      return code;
×
483
    }
484
  }
485

486
  if (pEntry->type == TSDB_SUPER_TABLE) {
184,313✔
487
    (*ppEntry)->flags = pEntry->flags;
170,853✔
488

489
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
170,853✔
490
    if (code) {
170,821!
UNCOV
491
      metaCloneEntryFree(ppEntry);
×
UNCOV
492
      return code;
×
493
    }
494

495
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
170,821✔
496
    if (code) {
170,838!
UNCOV
497
      metaCloneEntryFree(ppEntry);
×
UNCOV
498
      return code;
×
499
    }
500
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
170,851✔
501
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
13,460!
502
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
10,923✔
503
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
10,923✔
504
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
10,923✔
505

506
    // comment
507
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
10,923✔
508
    if (pEntry->ctbEntry.commentLen > 0) {
10,923✔
509
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
40!
510
      if (NULL == (*ppEntry)->ctbEntry.comment) {
40!
UNCOV
511
        code = terrno;
×
UNCOV
512
        metaCloneEntryFree(ppEntry);
×
UNCOV
513
        return code;
×
514
      }
515
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
40✔
516
    }
517

518
    // tags
519
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
10,923✔
520
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
10,923!
521
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
10,923!
UNCOV
522
      code = terrno;
×
UNCOV
523
      metaCloneEntryFree(ppEntry);
×
UNCOV
524
      return code;
×
525
    }
526
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
10,923✔
527
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,537!
528
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,537✔
529
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,537✔
530
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,537✔
531

532
    // schema
533
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
2,537✔
534
    if (code) {
2,537!
UNCOV
535
      metaCloneEntryFree(ppEntry);
×
UNCOV
536
      return code;
×
537
    }
538

539
    // comment
540
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,537✔
541
    if (pEntry->ntbEntry.commentLen > 0) {
2,537✔
542
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
46!
543
      if (NULL == (*ppEntry)->ntbEntry.comment) {
46!
UNCOV
544
        code = terrno;
×
UNCOV
545
        metaCloneEntryFree(ppEntry);
×
UNCOV
546
        return code;
×
547
      }
548
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
46✔
549
    }
550
  } else {
UNCOV
551
    return TSDB_CODE_INVALID_PARA;
×
552
  }
553

554
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
184,311!
555
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
26✔
UNCOV
556
    if (code) {
×
UNCOV
557
      metaCloneEntryFree(ppEntry);
×
UNCOV
558
      return code;
×
559
    }
560
  } else {
561
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
184,285✔
562
    if (code) {
184,373✔
563
      metaCloneEntryFree(ppEntry);
56✔
UNCOV
564
      return code;
×
565
    }
566
  }
567
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
184,317✔
568
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
10,528!
569
    if (!(*ppEntry)->pExtSchemas) {
10,529!
UNCOV
570
      code = terrno;
×
UNCOV
571
      metaCloneEntryFree(ppEntry);
×
UNCOV
572
      return code;
×
573
    }
574
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
10,529✔
575
  }
576

577
  return code;
184,318✔
578
}
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