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

taosdata / TDengine / #4579

25 Jul 2025 01:12AM UTC coverage: 57.921% (+1.7%) from 56.254%
#4579

push

travis-ci

web-flow
enh: refactor some tsdb log info (#32159)

142530 of 316723 branches covered (45.0%)

Branch coverage included in aggregate %.

0 of 13 new or added lines in 2 files covered. (0.0%)

151 existing lines in 26 files now uncovered.

215698 of 301752 relevant lines covered (71.48%)

4618632.12 hits per line

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

69.37
/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) {
3,287,845✔
19
  for (int32_t i = 0; i < nCols; i++) {
59,652,456✔
20
    if (HAS_TYPE_MOD(pSchema + i)) {
56,447,869✔
21
      return true;
83,258✔
22
    }
23
  }
24
  return false;
3,204,587✔
25
}
26

27
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
519,263✔
28
  if (pME->pExtSchemas) {
519,263✔
29
    const SSchemaWrapper *pSchWrapper = NULL;
26,463✔
30
    bool                  hasTypeMods = false;
26,463✔
31
    if (pME->type == TSDB_SUPER_TABLE) {
26,463✔
32
      pSchWrapper = &pME->stbEntry.schemaRow;
26,309✔
33
    } else if (pME->type == TSDB_NORMAL_TABLE) {
154!
34
      pSchWrapper = &pME->ntbEntry.schemaRow;
156✔
35
    } else {
36
      return 0;
×
37
    }
38
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
26,465✔
39

40
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,504,828✔
41
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,956,728!
42
    }
43
  }
44
  return 0;
519,264✔
45
}
46

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

53
  for (int32_t i = 0; i < pw->nCols; i++) {
15,742✔
54
    SColRef *p = &pw->pColRef[i];
14,286✔
55
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
28,572!
56
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
28,572!
57
    if (p->hasRef) {
14,286✔
58
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
16,076!
59
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
16,076!
60
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
16,076!
61
    }
62
  }
63
  return 0;
1,456✔
64
}
65

66
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
5,730,472✔
67
  bool hasExtSchema = false;
5,730,472✔
68
  SSchemaWrapper* pSchWrapper = NULL;
5,730,472✔
69
  if (pME->type == TSDB_SUPER_TABLE) {
5,730,472✔
70
    pSchWrapper = &pME->stbEntry.schemaRow;
3,139,549✔
71
  } else if (pME->type == TSDB_NORMAL_TABLE) {
2,590,923✔
72
    pSchWrapper = &pME->ntbEntry.schemaRow;
3,779✔
73
  } else {
74
    return 0;
2,587,144✔
75
  }
76

77
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
3,143,328✔
78
  if (hasExtSchema && pSchWrapper->nCols > 0) {
3,144,415!
79
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
61,172!
80
    if (pME->pExtSchemas == NULL) {
61,179!
81
      return terrno;
×
82
    }
83

84
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,346,184✔
85
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
14,569,653!
86
    }
87
  }
88

89
  return 0;
3,144,779✔
90
}
91

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

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

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

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

128
  for (int i = 0; i < pWrapper->nCols; i++) {
62,441✔
129
    SColRef *p = &pWrapper->pColRef[i];
58,363✔
130
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
116,686!
131
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
116,659!
132
    if (p->hasRef) {
58,336✔
133
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
30,990!
134
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
31,045!
135
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
31,019!
136
    }
137
  }
138
  return 0;
4,078✔
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) {
782✔
158
  if (pSrc->nCols > 0) {
782!
159
    pDst->nCols = pSrc->nCols;
782✔
160
    pDst->version = pSrc->version;
782✔
161
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
782!
162
    if (NULL == pDst->pColRef) {
782!
163
      return terrno;
×
164
    }
165
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
782✔
166
  }
167
  return 0;
782✔
168
}
169

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

176
  for (int32_t i = 0; i < pw->nCols; i++) {
24,555,515✔
177
    SColCmpr *p = &pw->pColCmpr[i];
24,037,608✔
178
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,075,216!
179
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,075,216!
180
  }
181
  return 0;
517,907✔
182
}
183
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
3,732,399✔
184
  SColCmprWrapper *pWrapper = &pME->colCmpr;
3,732,399✔
185
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
7,465,682!
186
  if (pWrapper->nCols == 0) {
3,733,283✔
187
    return 0;
422✔
188
  }
189

190
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
7,466,339!
191
  uDebug("dencode cols:%d", pWrapper->nCols);
3,733,478✔
192
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
3,733,558✔
193
  if (pWrapper->pColCmpr == NULL) {
3,736,004!
194
    return terrno;
×
195
  }
196

197
  for (int i = 0; i < pWrapper->nCols; i++) {
89,992,533✔
198
    SColCmpr *p = &pWrapper->pColCmpr[i];
86,261,432✔
199
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
172,517,598!
200
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
172,512,695!
201
  }
202
  return 0;
3,731,101✔
203
}
204
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
205
                                                            SSchemaWrapper *pSchema) {
UNCOV
206
  pCmpr->nCols = pSchema->nCols;
×
207
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
422!
208
    return terrno;
×
209
  }
210

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

220
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
485,753✔
221
  if (pSrc->nCols > 0) {
485,753✔
222
    pDst->nCols = pSrc->nCols;
442,141✔
223
    pDst->version = pSrc->version;
442,141✔
224
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
442,141!
225
    if (NULL == pDst->pColCmpr) {
442,285!
226
      return terrno;
×
227
    }
228
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
442,285✔
229
  }
230
  return 0;
485,897✔
231
}
232

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

239
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
486,582✔
240
  if (pCmpr) {
486,582!
241
    taosMemoryFreeClear(pCmpr->pColCmpr);
486,623!
242
  }
243
}
486,625✔
244

245
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
555,662✔
246
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
555,662✔
247
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,113,398!
248
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,113,398!
249
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,113,398!
250

251
  if (pME->type > 0) {
556,699✔
252
    if (pME->name == NULL) {
519,450!
253
      return TSDB_CODE_INVALID_PARA;
×
254
    }
255

256
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,038,900!
257

258
    if (pME->type == TSDB_SUPER_TABLE) {
519,450✔
259
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
177,078!
260
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
177,078!
261
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
177,078!
262
      if (TABLE_IS_ROLLUP(pME->flags)) {
88,539✔
263
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
8!
264
      }
265
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
430,911✔
266
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
777,182!
267
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
777,182!
268
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
777,182!
269
      if (pME->ctbEntry.commentLen > 0) {
388,591✔
270
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
271
      }
272
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
777,182!
273
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
388,591!
274
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
42,320!
275
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
84,640!
276
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
84,640!
277
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
84,640!
278
      if (pME->ntbEntry.commentLen > 0) {
42,320✔
279
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
76!
280
      }
281
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
84,640!
282
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
84,640!
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) {
519,376!
290
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,380!
291
    } else {
292
      TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
517,996!
293
    }
294
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
519,314!
295
  }
296
  if (pME->type == TSDB_SUPER_TABLE) {
556,265✔
297
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
176,366!
298
  }
299

300
  tEndEncode(pCoder);
556,265✔
301
  return 0;
556,217✔
302
}
303

304
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
6,329,780✔
305
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,329,780!
306
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
12,669,768!
307
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
12,666,002!
308
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
12,661,390!
309

310
  if (headerOnly) {
6,328,974✔
311
    tEndDecode(pCoder);
1,230✔
312
    return 0;
1,230✔
313
  }
314

315
  if (pME->type > 0) {
6,327,744✔
316
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
12,653,671!
317

318
    if (pME->type == TSDB_SUPER_TABLE) {
6,327,292✔
319
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
6,277,586!
320
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
6,269,316!
321
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
6,261,206!
322
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,130,591✔
323
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
36!
324
      }
325
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
3,188,407✔
326
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
5,185,521!
327
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
5,184,924!
328
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
5,183,513!
329
      if (pME->ctbEntry.commentLen > 0) {
2,591,276✔
330
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
331
      }
332
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
5,182,772!
333
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,591,496✔
334
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
595,573!
335
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,191,052!
336
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,190,863!
337
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,190,612!
338
      if (pME->ntbEntry.commentLen > 0) {
595,228✔
339
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
218!
340
      }
341
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,190,218!
342
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,189,988!
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) {
6,325,395✔
354
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,138,855!
355
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,139,274!
356

357
        if (pME->colCmpr.nCols == 0) {
3,140,252!
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) {
3,186,540✔
365
      if (!tDecodeIsEnd(pCoder)) {
593,855!
366
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
593,881✔
367
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
593,881✔
368
        if (pME->colCmpr.nCols == 0) {
593,535✔
369
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
844!
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);
593,535✔
376
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,592,685✔
377
      if (!tDecodeIsEnd(pCoder)) {
4,088!
378
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,088!
379
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,088!
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)) {
6,324,339✔
388
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
5,731,081!
389
    }
390
  }
391
  if (pME->type == TSDB_SUPER_TABLE) {
6,326,704✔
392
    if (!tDecodeIsEnd(pCoder)) {
3,141,438!
393
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
6,282,570!
394
    }
395
  }
396

397

398
  tEndDecode(pCoder);
6,326,282✔
399
  return 0;
6,325,263✔
400
}
401

402
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
6,329,448✔
403

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

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

419
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
870,817✔
420
  if (pSchema) {
870,817!
421
    taosMemoryFreeClear(pSchema->pSchema);
870,842!
422
  }
423
}
870,957✔
424

425
void metaCloneEntryFree(SMetaEntry **ppEntry) {
486,674✔
426
  if (ppEntry == NULL || *ppEntry == NULL) {
486,674!
427
    return;
61✔
428
  }
429

430
  taosMemoryFreeClear((*ppEntry)->name);
486,613!
431

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

437
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
486,624✔
438
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
428,050✔
439
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
428,145✔
440
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
58,574✔
441
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
43,739!
442
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
43,739!
443
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,835!
444
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,835✔
445
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,835!
446
  } else {
447
    return;
×
448
  }
449
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
486,726✔
450
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
486,642!
451
  metaCloneColRefFree(&(*ppEntry)->colRef);
486,646✔
452

453
  taosMemoryFreeClear(*ppEntry);
486,655!
454
  return;
486,723✔
455
}
456

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

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

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

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

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

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

486
  if (pEntry->type == TSDB_SUPER_TABLE) {
486,633✔
487
    (*ppEntry)->flags = pEntry->flags;
428,086✔
488

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

495
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
428,063✔
496
    if (code) {
428,011✔
497
      metaCloneEntryFree(ppEntry);
8✔
498
      return code;
×
499
    }
500
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
428,003✔
501
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
58,547✔
502
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
43,712✔
503
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
43,712✔
504
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
43,712✔
505

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

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

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

539
    // comment
540
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,835✔
541
    if (pEntry->ntbEntry.commentLen > 0) {
14,835✔
542
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
25!
543
      if (NULL == (*ppEntry)->ntbEntry.comment) {
25!
544
        code = terrno;
×
545
        metaCloneEntryFree(ppEntry);
×
546
        return code;
×
547
      }
548
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
25✔
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) {
486,550✔
555
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
794✔
556
    if (code) {
782!
557
      metaCloneEntryFree(ppEntry);
×
558
      return code;
×
559
    }
560
  } else {
561
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
485,756✔
562
    if (code) {
485,921✔
563
      metaCloneEntryFree(ppEntry);
51✔
564
      return code;
×
565
    }
566
  }
567
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
486,652✔
568
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,389!
569
    if (!(*ppEntry)->pExtSchemas) {
23,389!
570
      code = terrno;
×
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,389✔
575
  }
576

577
  return code;
486,652✔
578
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc