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

taosdata / TDengine / #4696

29 Aug 2025 06:36AM UTC coverage: 58.25% (+0.2%) from 58.041%
#4696

push

travis-ci

web-flow
fix(gpt): fix race-condition in preparing tmp files (#32800)

133424 of 291873 branches covered (45.71%)

Branch coverage included in aggregate %.

5 of 34 new or added lines in 6 files covered. (14.71%)

444 existing lines in 69 files now uncovered.

201767 of 283561 relevant lines covered (71.15%)

17907122.76 hits per line

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

64.96
/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) {
19,944,338✔
23
  for (int32_t i = 0; i < nCols; i++) {
475,782,497✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
455,932,127✔
25
      return true;
93,968✔
26
    }
27
  }
28
  return false;
19,850,370✔
29
}
30

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

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
4,786,435✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
9,514,430!
46
    }
47
  }
48
  return 0;
579,029✔
49
}
50

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

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

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

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
19,673,255✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
19,832,222!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
69,218!
84
    if (pME->pExtSchemas == NULL) {
69,228!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
6,848,488✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
13,558,325!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
19,763,004✔
93
  }
94

95
  return 0;
19,832,427✔
96
}
97

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

110
  if (hasTypeMods) {
131,222✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
127!
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,095✔
118
}
119

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

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

134
  for (int i = 0; i < pWrapper->nCols; i++) {
55,271✔
135
    SColRef *p = &pWrapper->pColRef[i];
51,176✔
136
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
102,315!
137
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
102,264!
138
    if (p->hasRef) {
51,125✔
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
24,814!
140
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
24,825!
141
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
24,859✔
142
    }
143
  }
144
  return 0;
4,095✔
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) {
710✔
164
  if (pSrc->nCols > 0) {
710!
165
    pDst->nCols = pSrc->nCols;
710✔
166
    pDst->version = pSrc->version;
710✔
167
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
710!
168
    if (NULL == pDst->pColRef) {
709!
169
      return terrno;
×
170
    }
171
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
709✔
172
  }
173
  return 0;
709✔
174
}
175

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

182
  for (int32_t i = 0; i < pw->nCols; i++) {
23,978,435✔
183
    SColCmpr *p = &pw->pColCmpr[i];
23,845,303✔
184
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
47,690,606!
185
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
47,690,606!
186
  }
187
  return code;
133,132✔
188
}
189
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
132,151✔
190
  const SColCmprWrapper *pw = &pME->colCmpr;
132,151✔
191
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
132,151✔
192
}
193
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
22,144,029✔
194
  SColCmprWrapper *pWrapper = &pME->colCmpr;
22,144,029✔
195
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
44,201,187!
196
  if (pWrapper->nCols == 0) {
22,057,158!
197
    return 0;
×
198
  }
199

200
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
44,086,371!
201
  uDebug("dencode cols:%d", pWrapper->nCols);
22,029,213✔
202
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
22,029,213✔
203
  if (pWrapper->pColCmpr == NULL) {
22,174,492!
204
    return terrno;
×
205
  }
206

207
  for (int i = 0; i < pWrapper->nCols; i++) {
484,779,803✔
208
    SColCmpr *p = &pWrapper->pColCmpr[i];
463,396,317✔
209
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
922,913,393!
210
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
922,122,387!
211
  }
212
  return 0;
21,383,486✔
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));
294!
220
  } else {
221
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
222
  }
223

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

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

237
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
521,182✔
238
  if (pSrc->nCols > 0) {
521,182✔
239
    pDst->nCols = pSrc->nCols;
473,669✔
240
    pDst->version = pSrc->version;
473,669✔
241
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
473,669!
242
    if (NULL == pDst->pColCmpr) {
473,822!
243
      return terrno;
×
244
    }
245
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
473,822✔
246
  }
247
  return 0;
521,335✔
248
}
249

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

256
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
521,986✔
257
  if (pCmpr) {
521,986!
258
    taosMemoryFreeClear(pCmpr->pColCmpr);
522,004!
259
  }
260
}
522,036✔
261

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

268
  if (pME->type > 0) {
617,386✔
269
    if (pME->name == NULL) {
579,142!
270
      return TSDB_CODE_INVALID_PARA;
×
271
    }
272

273
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,158,284!
274

275
    if (pME->type == TSDB_SUPER_TABLE) {
579,142✔
276
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
196,026!
277
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
196,026!
278
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
196,026!
279
      if (TABLE_IS_ROLLUP(pME->flags)) {
98,013!
280
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
281
      }
282
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
481,129✔
283
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
890,158!
284
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
890,158!
285
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
890,158!
286
      if (pME->ctbEntry.commentLen > 0) {
445,079✔
287
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
288
      }
289
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
890,158!
290
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
445,079!
291
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
36,050!
292
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
72,100!
293
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
72,100!
294
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
72,100!
295
      if (pME->ntbEntry.commentLen > 0) {
36,050✔
296
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
297
      }
298
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
72,100!
299
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
72,100!
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) {
579,190✔
307
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,621!
308
    } else {
309
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
577,569!
310
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
97,750✔
311
      } else if (pME->type == TSDB_NORMAL_TABLE) {
479,819✔
312
        if (pME->colCmpr.nCols != 0) {
35,128✔
313
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
34,834!
314
        } else {
315
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
294!
316
          SColCmprWrapper colCmprs = {0};
294✔
317
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
294!
318
          if (code != 0) {
294!
319
            taosMemoryFree(colCmprs.pColCmpr);
×
320
            TAOS_CHECK_RETURN(code);
×
321
          }
322
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
294✔
323
          taosMemoryFree(colCmprs.pColCmpr);
294!
324
          TAOS_CHECK_RETURN(code);
294!
325
        }
326
      }
327
    }
328
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
579,125!
329
  }
330
  if (pME->type == TSDB_SUPER_TABLE) {
617,070✔
331
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
195,478!
332
  }
333

334
  tEndEncode(pCoder);
617,070✔
335
  return 0;
617,126✔
336
}
337

338
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
33,311,511✔
339
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
33,311,511!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
66,448,178!
341
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
65,947,603!
342
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
65,685,480!
343

344
  if (headerOnly) {
32,805,103✔
345
    tEndDecode(pCoder);
70,260✔
346
    return 0;
70,260✔
347
  }
348

349
  if (pME->type > 0) {
32,734,843!
350
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
66,119,726!
351

352
    if (pME->type == TSDB_SUPER_TABLE) {
33,267,368✔
353
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
39,460,126!
354
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
37,694,527!
355
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
36,876,711!
356
      if (TABLE_IS_ROLLUP(pME->flags)) {
18,841,847!
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,466,905✔
360
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
22,203,299!
361
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
22,170,734!
362
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
22,162,668!
363
      if (pME->ctbEntry.commentLen > 0) {
11,092,358✔
364
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
365
      }
366
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
22,189,354!
367
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
11,096,996!
368
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,364,030!
369
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,724,862!
370
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,719,659!
371
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,718,489!
372
      if (pME->ntbEntry.commentLen > 0) {
2,359,662✔
373
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
374
      }
375
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,719,622!
376
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,661,291!
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) {
33,291,102✔
388
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,791,763!
389
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,799,005!
390

391
        if (pME->colCmpr.nCols == 0) {
19,662,705!
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,499,339✔
399
      if (!tDecodeIsEnd(pCoder)) {
2,362,360!
400
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,362,520!
401
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,362,520✔
402
        if (pME->colCmpr.nCols == 0) {
2,358,894!
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,358,894✔
410
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,136,979!
411
      if (!tDecodeIsEnd(pCoder)) {
4,111!
412
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,111!
413
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,111!
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)) {
32,987,703✔
422
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
19,662,585!
423
    } else {
424
      pME->pExtSchemas = NULL;
13,325,118✔
425
    }
426
  }
427
  if (pME->type == TSDB_SUPER_TABLE) {
33,036,423✔
428
    if (!tDecodeIsEnd(pCoder)) {
19,828,084!
429
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
39,532,118!
430
    }
431
  }
432

433

434
  tEndDecode(pCoder);
32,910,211✔
435
  return 0;
33,077,755✔
436
}
437

438
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
33,239,550✔
439

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

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

455
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
933,952✔
456
  if (pSchema) {
933,952!
457
    taosMemoryFreeClear(pSchema->pSchema);
933,974!
458
  }
459
}
934,103✔
460

461
void metaCloneEntryFree(SMetaEntry **ppEntry) {
522,043✔
462
  if (ppEntry == NULL || *ppEntry == NULL) {
522,043!
463
    return;
51✔
464
  }
465

466
  taosMemoryFreeClear((*ppEntry)->name);
521,992!
467

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

473
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
522,032✔
474
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
459,751✔
475
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
459,788✔
476
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,281✔
477
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,578!
478
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,578!
479
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,703!
480
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,703✔
481
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,703!
482
  } else {
483
    return;
×
484
  }
485
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
522,049✔
486
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
522,028!
487
  metaCloneColRefFree(&(*ppEntry)->colRef);
522,027✔
488

489
  taosMemoryFreeClear(*ppEntry);
522,026!
490
  return;
522,078✔
491
}
492

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

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

500
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
521,831!
501
  if (NULL == *ppEntry) {
522,066!
502
    return terrno;
×
503
  }
504

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

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

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

522
  if (pEntry->type == TSDB_SUPER_TABLE) {
522,018✔
523
    (*ppEntry)->flags = pEntry->flags;
459,730✔
524

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

531
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
459,651✔
532
    if (code) {
459,627!
533
      metaCloneEntryFree(ppEntry);
×
534
      return code;
×
535
    }
536
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
459,647✔
537
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,288✔
538
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,585✔
539
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,585✔
540
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,585✔
541

542
    // comment
543
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
47,585✔
544
    if (pEntry->ctbEntry.commentLen > 0) {
47,585✔
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,585✔
556
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
47,585!
557
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
47,587!
558
      code = terrno;
×
559
      metaCloneEntryFree(ppEntry);
×
560
      return code;
×
561
    }
562
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
47,587✔
563
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,703!
564
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,703✔
565
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,703✔
566
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,703✔
567

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

575
    // comment
576
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,703✔
577
    if (pEntry->ntbEntry.commentLen > 0) {
14,703✔
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) {
521,937✔
591
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
735✔
592
    if (code) {
709!
593
      metaCloneEntryFree(ppEntry);
×
594
      return code;
×
595
    }
596
  } else {
597
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
521,202✔
598
    if (code) {
521,299✔
599
      metaCloneEntryFree(ppEntry);
4✔
600
      return code;
×
601
    }
602
  }
603
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
522,004!
604
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
26,063!
605
    if (!(*ppEntry)->pExtSchemas) {
26,061!
606
      code = terrno;
×
607
      metaCloneEntryFree(ppEntry);
×
608
      return code;
×
609
    }
610
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
26,061✔
611
  }
612

613
  return code;
522,002✔
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