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

taosdata / TDengine / #3678

22 Mar 2025 04:46PM UTC coverage: 62.181% (+0.4%) from 61.745%
#3678

push

travis-ci

web-flow
fix: userOperTest in linux (#30363)

Co-authored-by: taos-support <it@taosdata.com>

154967 of 318145 branches covered (48.71%)

Branch coverage included in aggregate %.

240358 of 317625 relevant lines covered (75.67%)

16255149.31 hits per line

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

59.89
/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,368,563✔
19
  for (int32_t i = 0; i < nCols; i++) {
458,515,804✔
20
    if (HAS_TYPE_MOD(pSchema + i)) {
439,242,399✔
21
      return true;
95,158✔
22
    }
23
  }
24
  return false;
19,273,405✔
25
}
26

27
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
423,719✔
28
  if (pME->pExtSchemas) {
423,719✔
29
    const SSchemaWrapper *pSchWrapper = NULL;
12,762✔
30
    bool                  hasTypeMods = false;
12,762✔
31
    if (pME->type == TSDB_SUPER_TABLE) {
12,762✔
32
      pSchWrapper = &pME->stbEntry.schemaRow;
12,455✔
33
    } else if (pME->type == TSDB_NORMAL_TABLE) {
307!
34
      pSchWrapper = &pME->ntbEntry.schemaRow;
310✔
35
    } else {
36
      return 0;
×
37
    }
38
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,765✔
39

40
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
4,824,898✔
41
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
9,624,256!
42
    }
43
  }
44
  return 0;
423,727✔
45
}
46

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

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

66
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
28,457,893✔
67
  bool hasExtSchema = false;
28,457,893✔
68
  SSchemaWrapper* pSchWrapper = NULL;
28,457,893✔
69
  if (pME->type == TSDB_SUPER_TABLE) {
28,457,893✔
70
    pSchWrapper = &pME->stbEntry.schemaRow;
19,104,468✔
71
  } else if (pME->type == TSDB_NORMAL_TABLE) {
9,353,425✔
72
    pSchWrapper = &pME->ntbEntry.schemaRow;
35,592✔
73
  } else {
74
    return 0;
9,317,833✔
75
  }
76

77
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
19,140,060✔
78
  if (hasExtSchema && pSchWrapper->nCols > 0) {
19,293,627!
79
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
82,737✔
80
    if (pME->pExtSchemas == NULL) {
82,750!
81
      return terrno;
×
82
    }
83

84
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
5,842,407✔
85
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
11,519,337!
86
    }
87
  }
88

89
  return 0;
19,293,617✔
90
}
91

92
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
119,330✔
93
  const SSchemaWrapper *pSchWrapper = NULL;
119,330✔
94
  bool                  hasTypeMods = false;
119,330✔
95
  if (pME->type == TSDB_SUPER_TABLE) {
119,330✔
96
    pSchWrapper = &pME->stbEntry.schemaRow;
78,874✔
97
  } else if (pME->type == TSDB_NORMAL_TABLE) {
40,456!
98
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,463✔
99
  } else {
100
    return NULL;
×
101
  }
102
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
119,337✔
103

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

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

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

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

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

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

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

170
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
424,624✔
171
  const SColCmprWrapper *pw = &pME->colCmpr;
424,624✔
172
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
849,248!
173
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
849,248!
174
  uTrace("encode cols:%d", pw->nCols);
424,624✔
175

176
  for (int32_t i = 0; i < pw->nCols; i++) {
6,562,818✔
177
    SColCmpr *p = &pw->pColCmpr[i];
6,138,507✔
178
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
12,277,014!
179
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
12,277,014!
180
  }
181
  return 0;
424,311✔
182
}
183
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,584,514✔
184
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,584,514✔
185
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
43,081,570!
186
  if (pWrapper->nCols == 0) {
21,497,056!
187
    return 0;
×
188
  }
189

190
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
42,987,150!
191
  uDebug("dencode cols:%d", pWrapper->nCols);
21,490,094✔
192
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,490,347✔
193
  if (pWrapper->pColCmpr == NULL) {
21,627,732!
194
    return terrno;
×
195
  }
196

197
  for (int i = 0; i < pWrapper->nCols; i++) {
451,609,365✔
198
    SColCmpr *p = &pWrapper->pColCmpr[i];
432,391,208✔
199
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
866,125,827!
200
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
863,716,252!
201
  }
202
  return 0;
19,218,157✔
203
}
204
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
205
                                                            SSchemaWrapper *pSchema) {
206
  pCmpr->nCols = pSchema->nCols;
×
207
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
×
208
    return terrno;
×
209
  }
210

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

220
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
204,578✔
221
  if (pSrc->nCols > 0) {
204,578✔
222
    pDst->nCols = pSrc->nCols;
191,849✔
223
    pDst->version = pSrc->version;
191,849✔
224
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
191,849!
225
    if (NULL == pDst->pColCmpr) {
191,900!
226
      return terrno;
×
227
    }
228
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
191,900✔
229
  }
230
  return 0;
204,629✔
231
}
232

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

239
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
204,620✔
240
  if (pCmpr) {
204,620!
241
    taosMemoryFreeClear(pCmpr->pColCmpr);
204,628!
242
  }
243
}
204,643✔
244

245
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
434,972✔
246
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
434,972✔
247
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
871,744!
248
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
871,744!
249
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
871,744!
250

251
  if (pME->type > 0) {
435,872✔
252
    if (pME->name == NULL) {
424,759!
253
      return TSDB_CODE_INVALID_PARA;
×
254
    }
255

256
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
849,518!
257

258
    if (pME->type == TSDB_SUPER_TABLE) {
424,759✔
259
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
155,482!
260
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
155,482!
261
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
155,482!
262
      if (TABLE_IS_ROLLUP(pME->flags)) {
77,741✔
263
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
264
      }
265
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
347,018!
266
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
633,534!
267
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
633,534!
268
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
633,534!
269
      if (pME->ctbEntry.commentLen > 0) {
316,767✔
270
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
271
      }
272
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
633,534!
273
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
316,767!
274
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
30,251!
275
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
60,502!
276
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
60,502!
277
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
60,502!
278
      if (pME->ntbEntry.commentLen > 0) {
30,251✔
279
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
148!
280
      }
281
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
60,502!
282
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
60,502!
283
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
284
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
285
    } else {
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) {
424,710!
290
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
×
291
    } else {
292
      TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
424,715!
293
    }
294
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
424,304!
295
  }
296
  if (pME->type == TSDB_SUPER_TABLE) {
435,547✔
297
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
155,178!
298
  }
299

300
  tEndEncode(pCoder);
435,547✔
301
  return 0;
435,607✔
302
}
303

304
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
31,033,386✔
305
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
31,033,386!
306
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
61,896,914!
307
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
61,454,123!
308
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
61,256,918!
309

310
  if (headerOnly) {
30,598,723✔
311
    tEndDecode(pCoder);
12,300✔
312
    return 0;
12,300✔
313
  }
314

315
  if (pME->type > 0) {
30,586,423!
316
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
61,754,054!
317

318
    if (pME->type == TSDB_SUPER_TABLE) {
31,064,169✔
319
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
38,308,197!
320
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
36,840,408!
321
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
36,617,749!
322
      if (TABLE_IS_ROLLUP(pME->flags)) {
18,876,026✔
323
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
271!
324
      }
325
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,854,657!
326
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
18,881,102!
327
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
18,826,221!
328
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
18,818,186!
329
      if (pME->ctbEntry.commentLen > 0) {
9,419,366✔
330
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
331
      }
332
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
18,829,551!
333
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
9,410,185!
334
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,400,956!
335
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,798,877!
336
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,793,814!
337
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,791,431!
338
      if (pME->ntbEntry.commentLen > 0) {
2,395,538✔
339
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
346!
340
      }
341
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,791,917!
342
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,734,551!
343
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
344
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
345
      if (!pME->smaEntry.tsma) {
×
346
        return terrno;
×
347
      }
348
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
349
    } else {
350
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
351
      return TSDB_CODE_INVALID_PARA;
×
352
    }
353
    if (pME->type == TSDB_SUPER_TABLE) {
31,059,116✔
354
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,199,836!
355
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,211,266!
356

357
        if (pME->colCmpr.nCols == 0) {
19,088,078!
358
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
359
        }
360
      } else {
361
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
362
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
363
      }
364
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,859,280✔
365
      if (!tDecodeIsEnd(pCoder)) {
2,400,466!
366
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,400,606✔
367
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,400,613✔
368
        if (pME->colCmpr.nCols == 0) {
2,397,475!
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);
×
373
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
374
      }
375
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,397,475✔
376
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
9,458,814!
377
      if (!tDecodeIsEnd(pCoder)) {
×
378
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
×
379
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
×
380
      } else {
381
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
382
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
383
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
384
        }
385
      }
386
    }
387
    if (!tDecodeIsEnd(pCoder)) {
30,788,617✔
388
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
28,491,884!
389
    }
390
  }
391
  if (pME->type == TSDB_SUPER_TABLE) {
30,925,866✔
392
    if (!tDecodeIsEnd(pCoder)) {
19,245,177!
393
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
38,395,772!
394
    }
395
  }
396

397

398
  tEndDecode(pCoder);
30,811,992✔
399
  return 0;
30,878,331✔
400
}
401

402
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
31,033,478✔
403

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

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

419
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
381,001✔
420
  if (pSchema) {
381,001!
421
    taosMemoryFreeClear(pSchema->pSchema);
381,008!
422
  }
423
}
381,029✔
424

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

430
  taosMemoryFreeClear((*ppEntry)->name);
204,632!
431

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

437
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
204,633✔
438
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
189,207✔
439
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
189,216✔
440
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
15,426!
441
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
12,748!
442
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
12,748!
443
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
2,678!
444
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,678✔
445
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,678!
446
  } else {
447
    return;
×
448
  }
449
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
204,630✔
450
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
204,643!
451
  metaCloneColRefFree(&(*ppEntry)->colRef);
204,642✔
452

453
  taosMemoryFreeClear(*ppEntry);
204,634!
454
  return;
204,653✔
455
}
456

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

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

464
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
204,558!
465
  if (NULL == *ppEntry) {
204,642!
466
    return terrno;
×
467
  }
468

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

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

477
  if (pEntry->name) {
204,642!
478
    (*ppEntry)->name = tstrdup(pEntry->name);
204,650✔
479
    if (NULL == (*ppEntry)->name) {
204,604!
480
      code = terrno;
×
481
      metaCloneEntryFree(ppEntry);
×
482
      return code;
×
483
    }
484
  }
485

486
  if (pEntry->type == TSDB_SUPER_TABLE) {
204,632✔
487
    (*ppEntry)->flags = pEntry->flags;
189,204✔
488

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

495
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
189,151✔
496
    if (code) {
189,162!
497
      metaCloneEntryFree(ppEntry);
×
498
      return code;
×
499
    }
500
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
189,179✔
501
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
15,428!
502
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
12,750✔
503
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
12,750✔
504
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
12,750✔
505

506
    // comment
507
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
12,750✔
508
    if (pEntry->ctbEntry.commentLen > 0) {
12,750✔
509
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
40!
510
      if (NULL == (*ppEntry)->ctbEntry.comment) {
40!
511
        code = terrno;
×
512
        metaCloneEntryFree(ppEntry);
×
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;
12,750✔
520
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
12,750!
521
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
12,750!
522
      code = terrno;
×
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
12,750✔
527
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,678!
528
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,678✔
529
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,678✔
530
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,678✔
531

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

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

554
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
204,607!
555
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
15✔
556
    if (code) {
×
557
      metaCloneEntryFree(ppEntry);
×
558
      return code;
×
559
    }
560
  } else {
561
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
204,592✔
562
    if (code) {
204,638✔
563
      metaCloneEntryFree(ppEntry);
46✔
564
      return code;
×
565
    }
566
  }
567
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
204,592!
568
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
12,207!
569
    if (!(*ppEntry)->pExtSchemas) {
12,207!
570
      code = terrno;
×
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
12,207✔
575
  }
576

577
  return code;
204,592✔
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