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

taosdata / TDengine / #4723

08 Sep 2025 08:43AM UTC coverage: 59.07% (+0.2%) from 58.882%
#4723

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

135654 of 292179 branches covered (46.43%)

Branch coverage included in aggregate %.

204582 of 283811 relevant lines covered (72.08%)

16429044.24 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,202,599✔
23
  for (int32_t i = 0; i < nCols; i++) {
489,832,709✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
469,718,993✔
25
      return true;
88,883✔
26
    }
27
  }
28
  return false;
20,113,716✔
29
}
30

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

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,404,382✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,755,452!
46
    }
47
  }
48
  return 0;
537,059✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
16,800✔
58
    SColRef *p = &pw->pColRef[i];
15,182✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
30,364!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
30,364!
61
    if (p->hasRef) {
15,182✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
17,496!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
17,496!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
17,496!
65
    }
66
  }
67
  return 0;
1,618✔
68
}
69

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

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
19,956,313✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
20,087,234!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
66,699!
84
    if (pME->pExtSchemas == NULL) {
66,707!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,294,452!
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
14,455,534!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
20,020,535✔
93
  }
94

95
  return 0;
20,087,198✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
130,663✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
130,663✔
100
  bool                  hasTypeMods = false;
130,663✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
130,663✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
90,713✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,950!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
39,983✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
130,696✔
109

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

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

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

134
  for (int i = 0; i < pWrapper->nCols; i++) {
74,148✔
135
    SColRef *p = &pWrapper->pColRef[i];
68,194✔
136
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
136,357!
137
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
136,358!
138
    if (p->hasRef) {
68,195✔
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
38,629!
140
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
38,606!
141
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
38,646✔
142
    }
143
  }
144
  return 0;
5,954✔
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) {
797✔
164
  if (pSrc->nCols > 0) {
797!
165
    pDst->nCols = pSrc->nCols;
797✔
166
    pDst->version = pSrc->version;
797✔
167
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
797!
168
    if (NULL == pDst->pColRef) {
797!
169
      return terrno;
×
170
    }
171
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
797✔
172
  }
173
  return 0;
797✔
174
}
175

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

182
  for (int32_t i = 0; i < pw->nCols; i++) {
24,495,828✔
183
    SColCmpr *p = &pw->pColCmpr[i];
24,364,488✔
184
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,728,976!
185
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,728,976!
186
  }
187
  return code;
131,340✔
188
}
189
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
130,981✔
190
  const SColCmprWrapper *pw = &pME->colCmpr;
130,981✔
191
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
130,981✔
192
}
193
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
22,323,996✔
194
  SColCmprWrapper *pWrapper = &pME->colCmpr;
22,323,996✔
195
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
44,549,393!
196
  if (pWrapper->nCols == 0) {
22,225,397!
197
    return 0;
×
198
  }
199

200
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
44,443,433!
201
  uDebug("dencode cols:%d", pWrapper->nCols);
22,218,036✔
202
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
22,218,036✔
203
  if (pWrapper->pColCmpr == NULL) {
22,350,899!
204
    return terrno;
×
205
  }
206

207
  for (int i = 0; i < pWrapper->nCols; i++) {
507,141,176✔
208
    SColCmpr *p = &pWrapper->pColCmpr[i];
485,445,585✔
209
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
966,647,155!
210
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
965,991,847!
211
  }
212
  return 0;
21,695,591✔
213
}
214
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
215
                                                            SSchemaWrapper *pSchema) {
216
  pCmpr->nCols = pSchema->nCols;
×
217

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

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

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

237
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
492,773✔
238
  if (pSrc->nCols > 0) {
492,773✔
239
    pDst->nCols = pSrc->nCols;
445,124✔
240
    pDst->version = pSrc->version;
445,124✔
241
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
445,124!
242
    if (NULL == pDst->pColCmpr) {
445,264!
243
      return terrno;
×
244
    }
245
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
445,264✔
246
  }
247
  return 0;
492,913✔
248
}
249

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

256
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
493,590✔
257
  if (pCmpr) {
493,590!
258
    taosMemoryFreeClear(pCmpr->pColCmpr);
493,630!
259
  }
260
}
493,664✔
261

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

268
  if (pME->type > 0) {
576,128✔
269
    if (pME->name == NULL) {
537,788!
270
      return TSDB_CODE_INVALID_PARA;
×
271
    }
272

273
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,075,576!
274

275
    if (pME->type == TSDB_SUPER_TABLE) {
537,788✔
276
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
191,656!
277
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
191,656!
278
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
191,656!
279
      if (TABLE_IS_ROLLUP(pME->flags)) {
95,828!
280
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
281
      }
282
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
441,960✔
283
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
810,916!
284
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
810,916!
285
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
810,916!
286
      if (pME->ctbEntry.commentLen > 0) {
405,458✔
287
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
288
      }
289
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
810,916!
290
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
405,458!
291
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
36,502!
292
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
73,004!
293
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
73,004!
294
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
73,004!
295
      if (pME->ntbEntry.commentLen > 0) {
36,502✔
296
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
297
      }
298
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
73,004!
299
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
73,004!
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) {
537,778!
307
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,547!
308
    } else {
309
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
536,231!
310
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
95,904✔
311
      } else if (pME->type == TSDB_NORMAL_TABLE) {
440,327✔
312
        if (pME->colCmpr.nCols != 0) {
35,500✔
313
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
35,096!
314
        } else {
315
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
404!
316
          SColCmprWrapper colCmprs = {0};
404✔
317
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
404!
318
          if (code != 0) {
404!
319
            taosMemoryFree(colCmprs.pColCmpr);
×
320
            TAOS_CHECK_RETURN(code);
×
321
          }
322
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
404✔
323
          taosMemoryFree(colCmprs.pColCmpr);
404!
324
          TAOS_CHECK_RETURN(code);
404!
325
        }
326
      }
327
    }
328
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
537,757!
329
  }
330
  if (pME->type == TSDB_SUPER_TABLE) {
576,107✔
331
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
191,688!
332
  }
333

334
  tEndEncode(pCoder);
576,107✔
335
  return 0;
576,096✔
336
}
337

338
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
33,058,436✔
339
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
33,058,436!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
65,951,865!
341
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
65,491,588!
342
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
65,276,871!
343

344
  if (headerOnly) {
32,613,245✔
345
    tEndDecode(pCoder);
43,224✔
346
    return 0;
43,224✔
347
  }
348

349
  if (pME->type > 0) {
32,570,021!
350
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
65,676,018!
351

352
    if (pME->type == TSDB_SUPER_TABLE) {
33,029,550✔
353
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
39,988,829!
354
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
39,378,090!
355
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
38,849,258!
356
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,407,361!
357
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
358
      }
359
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
12,976,914✔
360
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
21,384,577!
361
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
21,355,401!
362
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
21,343,971!
363
      if (pME->ctbEntry.commentLen > 0) {
10,681,464✔
364
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
365
      }
366
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
21,365,252!
367
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
10,683,788!
368
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,285,231!
369
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,567,127!
370
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,562,058!
371
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,560,343!
372
      if (pME->ntbEntry.commentLen > 0) {
2,280,181✔
373
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
374
      }
375
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,560,484!
376
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,534,832!
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,055,615✔
388
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
20,045,371!
389
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
20,052,460!
390

391
        if (pME->colCmpr.nCols == 0) {
19,949,898!
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,010,244✔
399
      if (!tDecodeIsEnd(pCoder)) {
2,283,463!
400
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,283,618!
401
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,283,618✔
402
        if (pME->colCmpr.nCols == 0) {
2,280,076!
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,280,076✔
410
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
10,726,781!
411
      if (!tDecodeIsEnd(pCoder)) {
5,961!
412
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
5,961!
413
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
5,961!
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,812,499✔
422
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
19,949,401!
423
    } else {
424
      pME->pExtSchemas = NULL;
12,863,098✔
425
    }
426
  }
427
  if (pME->type == TSDB_SUPER_TABLE) {
32,868,458✔
428
    if (!tDecodeIsEnd(pCoder)) {
20,082,540!
429
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
40,063,323!
430
    }
431
  }
432

433

434
  tEndDecode(pCoder);
32,763,089✔
435
  return 0;
32,881,862✔
436
}
437

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

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

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

455
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
876,725✔
456
  if (pSchema) {
876,725!
457
    taosMemoryFreeClear(pSchema->pSchema);
876,754!
458
  }
459
}
876,882✔
460

461
void metaCloneEntryFree(SMetaEntry **ppEntry) {
493,665✔
462
  if (ppEntry == NULL || *ppEntry == NULL) {
493,665!
463
    return;
44✔
464
  }
465

466
  taosMemoryFreeClear((*ppEntry)->name);
493,621!
467

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

473
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
493,662✔
474
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
431,041✔
475
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
431,093✔
476
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,621✔
477
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,748!
478
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,748!
479
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,873!
480
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,873✔
481
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,873!
482
  } else {
483
    return;
×
484
  }
485
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
493,686✔
486
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
493,666!
487
  metaCloneColRefFree(&(*ppEntry)->colRef);
493,667✔
488

489
  taosMemoryFreeClear(*ppEntry);
493,648!
490
  return;
493,711✔
491
}
492

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

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

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

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

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

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

522
  if (pEntry->type == TSDB_SUPER_TABLE) {
493,687✔
523
    (*ppEntry)->flags = pEntry->flags;
431,071✔
524

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

531
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
430,978✔
532
    if (code) {
430,968!
533
      metaCloneEntryFree(ppEntry);
×
534
      return code;
×
535
    }
536
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
430,987✔
537
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,616✔
538
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,743✔
539
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,743✔
540
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,743✔
541

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

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

575
    // comment
576
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,873✔
577
    if (pEntry->ntbEntry.commentLen > 0) {
14,873✔
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) {
493,602✔
591
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
821✔
592
    if (code) {
797!
593
      metaCloneEntryFree(ppEntry);
×
594
      return code;
×
595
    }
596
  } else {
597
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
492,781✔
598
    if (code) {
492,891✔
599
      metaCloneEntryFree(ppEntry);
25✔
600
      return code;
×
601
    }
602
  }
603
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
493,663!
604
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,698!
605
    if (!(*ppEntry)->pExtSchemas) {
23,696!
606
      code = terrno;
×
607
      metaCloneEntryFree(ppEntry);
×
608
      return code;
×
609
    }
610
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,696✔
611
  }
612

613
  return code;
493,661✔
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