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

taosdata / TDengine / #4689

26 Aug 2025 02:05PM UTC coverage: 57.913% (+0.9%) from 56.997%
#4689

push

travis-ci

web-flow
fix: modify the prompt language of the taos-shell (#32758)

* fix: modify prompt language

* fix: add shell test case

* fix: modify comments

* fix: modify test case for TDengine TSDB

133147 of 292423 branches covered (45.53%)

Branch coverage included in aggregate %.

16 of 17 new or added lines in 2 files covered. (94.12%)

217 existing lines in 63 files now uncovered.

201093 of 284715 relevant lines covered (70.63%)

17961424.45 hits per line

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

65.05
/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) {
20,957,396✔
23
  for (int32_t i = 0; i < nCols; i++) {
500,339,529✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
479,461,810✔
25
      return true;
79,677✔
26
    }
27
  }
28
  return false;
20,877,719✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
595,304✔
32
  if (pME->pExtSchemas) {
595,304✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
26,379✔
34
    bool                  hasTypeMods = false;
26,379✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
26,379✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,237✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
142!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
142✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
26,379✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,448,444✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,844,130!
46
    }
47
  }
48
  return 0;
595,304✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
16,336✔
58
    SColRef *p = &pw->pColRef[i];
14,732✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
29,464!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
29,464!
61
    if (p->hasRef) {
14,732✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
16,804!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
16,804!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
16,804!
65
    }
66
  }
67
  return 0;
1,604✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
20,686,285✔
71
  bool hasExtSchema = false;
20,686,285✔
72
  SSchemaWrapper* pSchWrapper = NULL;
20,686,285✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
20,686,285!
74
    pSchWrapper = &pME->stbEntry.schemaRow;
20,713,416✔
UNCOV
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
×
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
3,380✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
20,716,796✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
20,853,492!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
57,746!
84
    if (pME->pExtSchemas == NULL) {
57,754!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,317,105✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
14,518,476!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
20,795,746✔
93
  }
94

95
  return 0;
20,853,726✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
131,185✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
131,185✔
100
  bool                  hasTypeMods = false;
131,185✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
131,185✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
91,210✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,975!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
39,996✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
131,206✔
109

110
  if (hasTypeMods) {
131,208✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
129!
112
    if (ret != NULL) {
118!
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
118✔
114
    }
115
    return ret;
118✔
116
  }
117
  return NULL;
131,079✔
118
}
119

120
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
7,142✔
121
  SColRefWrapper *pWrapper = &pME->colRef;
7,142✔
122
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
14,284!
123
  if (pWrapper->nCols == 0) {
7,142!
124
    return 0;
×
125
  }
126

127
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
14,287!
128
  uDebug("decode cols:%d", pWrapper->nCols);
7,145!
129
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
7,145!
130
  if (pWrapper->pColRef == NULL) {
7,144!
131
    return terrno;
×
132
  }
133

134
  for (int i = 0; i < pWrapper->nCols; i++) {
76,804✔
135
    SColRef *p = &pWrapper->pColRef[i];
69,675✔
136
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
139,321!
137
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
139,304!
138
    if (p->hasRef) {
69,658✔
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
39,351!
140
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
39,355!
141
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
39,395✔
142
    }
143
  }
144
  return 0;
7,129✔
145
}
146

147
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
148
                                                            SSchemaWrapper *pSchema) {
149
  pRef->nCols = pSchema->nCols;
×
150
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
151
    return terrno;
×
152
  }
153

154
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
155
    SColRef  *pColRef = &pRef->pColRef[i];
×
156
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
157
    pColRef->id = pColSchema->colId;
×
158
    pColRef->hasRef = false;
×
159
  }
160
  return 0;
×
161
}
162

163
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
796✔
164
  if (pSrc->nCols > 0) {
796!
165
    pDst->nCols = pSrc->nCols;
796✔
166
    pDst->version = pSrc->version;
796✔
167
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
796!
168
    if (NULL == pDst->pColRef) {
796!
169
      return terrno;
×
170
    }
171
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
796✔
172
  }
173
  return 0;
796✔
174
}
175

176
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
129,974✔
177
  int32_t code = 0;
129,974✔
178
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
259,948!
179
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
259,948!
180
  uTrace("encode cols:%d", pw->nCols);
129,974✔
181

182
  for (int32_t i = 0; i < pw->nCols; i++) {
24,509,416✔
183
    SColCmpr *p = &pw->pColCmpr[i];
24,379,454✔
184
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,758,908!
185
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,758,908!
186
  }
187
  return code;
129,962✔
188
}
189
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
128,925✔
190
  const SColCmprWrapper *pw = &pME->colCmpr;
128,925✔
191
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
128,925✔
192
}
193
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
23,148,706✔
194
  SColCmprWrapper *pWrapper = &pME->colCmpr;
23,148,706✔
195
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
46,219,249!
196
  if (pWrapper->nCols == 0) {
23,070,543!
197
    return 0;
×
198
  }
199

200
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
46,120,182!
201
  uDebug("dencode cols:%d", pWrapper->nCols);
23,049,639✔
202
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
23,049,639✔
203
  if (pWrapper->pColCmpr == NULL) {
23,181,703!
204
    return terrno;
×
205
  }
206

207
  for (int i = 0; i < pWrapper->nCols; i++) {
512,244,896✔
208
    SColCmpr *p = &pWrapper->pColCmpr[i];
489,783,707✔
209
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
976,046,457!
210
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
975,325,943!
211
  }
212
  return 0;
22,461,189✔
213
}
214
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
215
                                                            SSchemaWrapper *pSchema) {
UNCOV
216
  pCmpr->nCols = pSchema->nCols;
×
217

UNCOV
218
  if (pDecoder == NULL) {
×
219
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
334!
220
  } else {
221
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
222
  }
223

224
  if (pCmpr->pColCmpr == NULL) {
334!
225
    return terrno;
×
226
  }
227

228
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,740!
229
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,406✔
230
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,406✔
231
    pColCmpr->id = pColSchema->colId;
1,406✔
232
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,406✔
233
  }
234
  return 0;
334✔
235
}
236

237
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
527,566✔
238
  if (pSrc->nCols > 0) {
527,566✔
239
    pDst->nCols = pSrc->nCols;
480,148✔
240
    pDst->version = pSrc->version;
480,148✔
241
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
480,148!
242
    if (NULL == pDst->pColCmpr) {
480,263!
243
      return terrno;
×
244
    }
245
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
480,263✔
246
  }
247
  return 0;
527,681✔
248
}
249

250
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
528,458✔
251
  if (pColRef) {
528,458!
252
    taosMemoryFreeClear(pColRef->pColRef);
528,471!
253
  }
254
}
528,458✔
255

256
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
528,436✔
257
  if (pCmpr) {
528,436!
258
    taosMemoryFreeClear(pCmpr->pColCmpr);
528,453!
259
  }
260
}
528,494✔
261

262
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
632,787✔
263
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
632,787✔
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,267,316!
265
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,267,316!
266
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,267,316!
267

268
  if (pME->type > 0) {
633,658✔
269
    if (pME->name == NULL) {
595,371!
270
      return TSDB_CODE_INVALID_PARA;
×
271
    }
272

273
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,190,742!
274

275
    if (pME->type == TSDB_SUPER_TABLE) {
595,371✔
276
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
189,556!
277
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
189,556!
278
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
189,556!
279
      if (TABLE_IS_ROLLUP(pME->flags)) {
94,778!
280
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
281
      }
282
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
500,593✔
283
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
928,834!
284
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
928,834!
285
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
928,834!
286
      if (pME->ctbEntry.commentLen > 0) {
464,417✔
287
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
288
      }
289
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
928,834!
290
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
464,417!
291
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
36,176!
292
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
72,352!
293
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
72,352!
294
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
72,352!
295
      if (pME->ntbEntry.commentLen > 0) {
36,176✔
296
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
297
      }
298
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
72,352!
299
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
72,352!
300
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
301
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
302
    } else {
303
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
304
      return TSDB_CODE_INVALID_PARA;
×
305
    }
306
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
595,407✔
307
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,807!
308
    } else {
309
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
593,600✔
310
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
94,569✔
311
      } else if (pME->type == TSDB_NORMAL_TABLE) {
499,031✔
312
        if (pME->colCmpr.nCols != 0) {
35,182✔
313
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
34,848!
314
        } else {
315
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
334!
316
          SColCmprWrapper colCmprs = {0};
334✔
317
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
334!
318
          if (code != 0) {
334!
319
            taosMemoryFree(colCmprs.pColCmpr);
×
320
            TAOS_CHECK_RETURN(code);
×
321
          }
322
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
334✔
323
          taosMemoryFree(colCmprs.pColCmpr);
334!
324
          TAOS_CHECK_RETURN(code);
334!
325
        }
326
      }
327
    }
328
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
595,354!
329
  }
330
  if (pME->type == TSDB_SUPER_TABLE) {
633,438✔
331
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
189,114!
332
  }
333

334
  tEndEncode(pCoder);
633,438✔
335
  return 0;
633,485✔
336
}
337

338
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
34,330,848✔
339
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
34,330,848!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
68,526,019!
341
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
68,063,467!
342
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
67,835,609!
343

344
  if (headerOnly) {
33,889,441✔
345
    tEndDecode(pCoder);
90,304✔
346
    return 0;
90,304✔
347
  }
348

349
  if (pME->type > 0) {
33,799,137!
350
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
68,156,555!
351

352
    if (pME->type == TSDB_SUPER_TABLE) {
34,265,424✔
353
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
41,530,160!
354
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
38,427,654!
355
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
37,044,724!
356
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,326,654!
357
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
358
      }
359
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
13,444,848✔
360
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
22,197,342!
361
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
22,172,301!
362
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
22,160,005!
363
      if (pME->ctbEntry.commentLen > 0) {
11,090,100✔
364
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
365
      }
366
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
22,186,402!
367
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
11,096,302!
368
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,349,902!
369
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,696,449!
370
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,690,641!
371
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,689,560!
372
      if (pME->ntbEntry.commentLen > 0) {
2,345,466✔
373
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
374
      }
375
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,691,531!
376
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,592,891!
377
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
378
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
379
      if (!pME->smaEntry.tsma) {
×
380
        return terrno;
×
381
      }
382
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
383
    } else {
384
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
385
      return TSDB_CODE_INVALID_PARA;
×
386
    }
387
    if (pME->type == TSDB_SUPER_TABLE) {
34,280,246✔
388
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
20,802,729!
389
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
20,811,960!
390

391
        if (pME->colCmpr.nCols == 0) {
20,700,399!
392
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
393
        }
394
      } else {
395
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
396
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
397
      }
398
    } else if (pME->type == TSDB_NORMAL_TABLE) {
13,477,517✔
399
      if (!tDecodeIsEnd(pCoder)) {
2,347,876!
400
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,348,003!
401
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,348,003✔
402
        if (pME->colCmpr.nCols == 0) {
2,344,057!
403
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
404
        }
405
      } else {
406
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
407
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
408
      }
409
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,344,057✔
410
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,129,641!
411
      if (!tDecodeIsEnd(pCoder)) {
7,142!
412
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
7,142!
413
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
7,142!
414
      } else {
415
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
416
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
417
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
418
        }
419
      }
420
    }
421
    if (!tDecodeIsEnd(pCoder)) {
34,003,650✔
422
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
20,699,421!
423
    } else {
424
      pME->pExtSchemas = NULL;
13,304,229✔
425
    }
426
  }
427
  if (pME->type == TSDB_SUPER_TABLE) {
34,060,116✔
428
    if (!tDecodeIsEnd(pCoder)) {
20,848,003!
429
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
41,593,041!
430
    }
431
  }
432

433

434
  tEndDecode(pCoder);
33,953,743✔
435
  return 0;
34,102,745✔
436
}
437

438
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
34,234,807✔
439

440
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
946,669✔
441
  if (pSrc == NULL || pDst == NULL) {
946,669!
442
    return TSDB_CODE_INVALID_PARA;
×
443
  }
444

445
  pDst->nCols = pSrc->nCols;
946,713✔
446
  pDst->version = pSrc->version;
946,713✔
447
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
946,713!
448
  if (pDst->pSchema == NULL) {
946,757!
449
    return terrno;
×
450
  }
451
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
946,757✔
452
  return TSDB_CODE_SUCCESS;
946,757✔
453
}
454

455
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
946,776✔
456
  if (pSchema) {
946,776!
457
    taosMemoryFreeClear(pSchema->pSchema);
946,792!
458
  }
459
}
946,925✔
460

461
void metaCloneEntryFree(SMetaEntry **ppEntry) {
528,490✔
462
  if (ppEntry == NULL || *ppEntry == NULL) {
528,490!
463
    return;
82✔
464
  }
465

466
  taosMemoryFreeClear((*ppEntry)->name);
528,408!
467

468
  if ((*ppEntry)->type < 0) {
528,435!
469
    taosMemoryFreeClear(*ppEntry);
×
470
    return;
×
471
  }
472

473
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
528,435✔
474
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
466,068✔
475
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
466,110✔
476
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,367✔
477
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,519!
478
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,519!
479
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,848!
480
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,848✔
481
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,848!
482
  } else {
483
    return;
×
484
  }
485
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
528,477✔
486
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
528,473!
487
  metaCloneColRefFree(&(*ppEntry)->colRef);
528,471✔
488

489
  taosMemoryFreeClear(*ppEntry);
528,462!
490
  return;
528,514✔
491
}
492

493
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
528,261✔
494
  int32_t code = TSDB_CODE_SUCCESS;
528,261✔
495

496
  if (NULL == pEntry || NULL == ppEntry) {
528,261!
497
    return TSDB_CODE_INVALID_PARA;
×
498
  }
499

500
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
528,295!
501
  if (NULL == *ppEntry) {
528,512!
502
    return terrno;
×
503
  }
504

505
  (*ppEntry)->version = pEntry->version;
528,512✔
506
  (*ppEntry)->type = pEntry->type;
528,512✔
507
  (*ppEntry)->uid = pEntry->uid;
528,512✔
508

509
  if (pEntry->type < 0) {
528,512!
510
    return TSDB_CODE_SUCCESS;
×
511
  }
512

513
  if (pEntry->name) {
528,512!
514
    (*ppEntry)->name = tstrdup(pEntry->name);
528,512✔
515
    if (NULL == (*ppEntry)->name) {
528,443!
516
      code = terrno;
×
517
      metaCloneEntryFree(ppEntry);
×
518
      return code;
×
519
    }
520
  }
521

522
  if (pEntry->type == TSDB_SUPER_TABLE) {
528,479✔
523
    (*ppEntry)->flags = pEntry->flags;
466,109✔
524

525
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
466,109✔
526
    if (code) {
466,038!
527
      metaCloneEntryFree(ppEntry);
×
528
      return code;
×
529
    }
530

531
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
466,038✔
532
    if (code) {
466,013!
533
      metaCloneEntryFree(ppEntry);
×
534
      return code;
×
535
    }
536
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
466,034✔
537
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,370✔
538
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,522✔
539
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,522✔
540
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,522✔
541

542
    // comment
543
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
47,522✔
544
    if (pEntry->ctbEntry.commentLen > 0) {
47,522✔
545
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
546
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
547
        code = terrno;
×
548
        metaCloneEntryFree(ppEntry);
×
549
        return code;
×
550
      }
551
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
552
    }
553

554
    // tags
555
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
47,522✔
556
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
47,522!
557
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
47,520!
558
      code = terrno;
×
559
      metaCloneEntryFree(ppEntry);
×
560
      return code;
×
561
    }
562
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
47,520✔
563
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,848!
564
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,848✔
565
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,848✔
566
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,848✔
567

568
    // schema
569
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,848✔
570
    if (code) {
14,848!
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574

575
    // comment
576
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,848✔
577
    if (pEntry->ntbEntry.commentLen > 0) {
14,848✔
578
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
49!
579
      if (NULL == (*ppEntry)->ntbEntry.comment) {
49!
580
        code = terrno;
×
581
        metaCloneEntryFree(ppEntry);
×
582
        return code;
×
583
      }
584
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
49✔
585
    }
586
  } else {
587
    return TSDB_CODE_INVALID_PARA;
×
588
  }
589

590
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
528,402✔
591
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
821✔
592
    if (code) {
796!
593
      metaCloneEntryFree(ppEntry);
×
594
      return code;
×
595
    }
596
  } else {
597
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
527,581✔
598
    if (code) {
527,658✔
599
      metaCloneEntryFree(ppEntry);
15✔
600
      return code;
×
601
    }
602
  }
603
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
528,439!
604
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,222!
605
    if (!(*ppEntry)->pExtSchemas) {
23,223!
606
      code = terrno;
×
607
      metaCloneEntryFree(ppEntry);
×
608
      return code;
×
609
    }
610
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,223✔
611
  }
612

613
  return code;
528,440✔
614
}
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