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

taosdata / TDengine / #4998

21 Mar 2026 01:22PM UTC coverage: 72.335% (+0.6%) from 71.739%
#4998

push

travis-ci

web-flow
enh:register add secondEp (#34867)

61 of 69 new or added lines in 1 file covered. (88.41%)

8670 existing lines in 142 files now uncovered.

253516 of 350475 relevant lines covered (72.33%)

133451446.75 hits per line

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

78.71
/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) {
1,324,074,329✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
162,372,442✔
26
    }
27
  }
28
  return false;
1,160,182,188✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
206,279,177✔
32
  if (pME->pExtSchemas) {
206,279,177✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
12,866,781✔
34
    bool                  hasTypeMods = false;
12,866,781✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
12,866,781✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
12,762,963✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
97,584✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
97,584✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,861,700✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,439,049,560✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
206,325,588✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
462,812,073✔
58
    SColRef *p = &pw->pColRef[i];
460,898,386✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
921,797,387✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
921,796,772✔
61
    if (p->hasRef) {
460,898,386✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
611,005,101✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
611,004,486✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
611,003,871✔
65
    }
66
  }
67

68
  // Encode tag references
69
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nTagRefs));
3,826,759✔
70
  for (int32_t i = 0; i < pw->nTagRefs; i++) {
1,913,687✔
UNCOV
71
    SColRef *p = &pw->pTagRef[i];
×
UNCOV
72
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
×
UNCOV
73
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
×
UNCOV
74
    if (p->hasRef) {
×
UNCOV
75
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
×
UNCOV
76
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
×
UNCOV
77
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
×
78
    }
79
  }
80

81
  return 0;
1,914,302✔
82
}
83

84
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,265,286,632✔
85
  bool hasExtSchema = false;
1,265,286,632✔
86
  SSchemaWrapper* pSchWrapper = NULL;
1,265,286,632✔
87
  if (pME->type == TSDB_SUPER_TABLE) {
1,265,286,632✔
88
    pSchWrapper = &pME->stbEntry.schemaRow;
959,937,221✔
89
  } else if (pME->type == TSDB_NORMAL_TABLE) {
305,489,991✔
90
    pSchWrapper = &pME->ntbEntry.schemaRow;
305,647,858✔
91
  } else {
UNCOV
92
    return 0;
×
93
  }
94

95
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,265,421,364✔
96
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,265,966,220✔
97
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
305,180,887✔
98
    if (pME->pExtSchemas == NULL) {
152,578,811✔
UNCOV
99
      return terrno;
×
100
    }
101

102
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
2,147,483,647✔
103
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
104
    }
105
  } else {
106
    pME->pExtSchemas = NULL;
1,113,368,970✔
107
  }
108

109
  return 0;
1,266,191,100✔
110
}
111

112
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
46,117,060✔
113
  const SSchemaWrapper *pSchWrapper = NULL;
46,117,060✔
114
  bool                  hasTypeMods = false;
46,117,060✔
115
  if (pME->type == TSDB_SUPER_TABLE) {
46,117,060✔
116
    pSchWrapper = &pME->stbEntry.schemaRow;
33,753,817✔
117
  } else if (pME->type == TSDB_NORMAL_TABLE) {
12,390,702✔
118
    pSchWrapper = &pME->ntbEntry.schemaRow;
12,407,478✔
119
  } else {
UNCOV
120
    return NULL;
×
121
  }
122
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
46,165,927✔
123

124
  if (hasTypeMods) {
46,120,603✔
125
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
28,261✔
126
    if (ret != NULL) {
28,261✔
127
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
28,261✔
128
    }
129
    return ret;
28,261✔
130
  }
131
  return NULL;
46,092,342✔
132
}
133

134
int32_t metaGetRsmaSchema(const SMetaEntry *pME, SSchemaRsma **rsmaSchema) {
28,194✔
135
  if (!rsmaSchema) return 0;
28,194✔
136
  if ((pME->type != TSDB_SUPER_TABLE) || !TABLE_IS_ROLLUP(pME->flags)) {  // only support super table
28,194✔
UNCOV
137
    *rsmaSchema = NULL;
×
138
    return 0;
×
139
  }
140

141
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
28,194✔
142
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
28,194✔
143
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
28,194✔
144

145
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
28,194✔
146
  if (*rsmaSchema == NULL) {
28,194✔
UNCOV
147
    return terrno;
×
148
  }
149

150
  (*rsmaSchema)->funcIds = taosMemoryMalloc(sizeof(func_id_t) * nCols);
28,194✔
151
  if ((*rsmaSchema)->funcIds == NULL) {
28,194✔
UNCOV
152
    taosMemoryFree(*rsmaSchema);
×
UNCOV
153
    *rsmaSchema = NULL;
×
UNCOV
154
    return terrno;
×
155
  }
156

157
  (void)snprintf((*rsmaSchema)->tbName, TSDB_TABLE_NAME_LEN, "%s", pME->name);
28,194✔
158
  (*rsmaSchema)->tbUid = pME->uid;
28,194✔
159
  (*rsmaSchema)->tbType = pME->type;
28,194✔
160
  (*rsmaSchema)->interval[0] = pParam->interval[0];
28,194✔
161
  (*rsmaSchema)->interval[1] = pParam->interval[1];
28,194✔
162
  (*rsmaSchema)->nFuncs = nCols;
28,194✔
163

164
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
28,194✔
165
  int32_t    i = 0, j = 0;
28,194✔
166
  for (i = 0; i < nCols; ++i) {
213,360✔
167
    while (j < pParam->nFuncs) {
336,804✔
168
      if (pParam->funcColIds[j] == pSchema[i].colId) {
323,088✔
169
        pFuncIds[i] = pParam->funcIds[j];
150,876✔
170
        break;
150,876✔
171
      }
172
      if (pParam->funcColIds[j] > pSchema[i].colId) {
172,212✔
173
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
34,290✔
174
        break;
34,290✔
175
      }
176
      ++j;
137,922✔
177
    }
178
    if (j >= pParam->nFuncs) {
198,882✔
179
      for (; i < nCols; ++i) {
27,432✔
180
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
13,716✔
181
      }
182
      break;
13,716✔
183
    }
184
  }
185
  pFuncIds[0] = 0;  // Primary TS column has no function
28,194✔
186

187
  return 0;
28,194✔
188
}
189

190
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
62,374,813✔
191
  SColRefWrapper *pWrapper = &pME->colRef;
62,374,813✔
192
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
124,774,098✔
193
  if (pWrapper->nCols == 0) {
62,382,261✔
UNCOV
194
    return 0;
×
195
  }
196

197
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
124,757,359✔
198
  uDebug("decode cols:%d", pWrapper->nCols);
62,385,562✔
199
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
124,755,500✔
200
  if (pWrapper->pColRef == NULL) {
62,370,919✔
UNCOV
201
    return terrno;
×
202
  }
203

204
  for (int i = 0; i < pWrapper->nCols; i++) {
1,069,798,704✔
205
    SColRef *p = &pWrapper->pColRef[i];
1,007,477,863✔
206
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
2,014,976,304✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,015,016,873✔
208
    if (p->hasRef) {
1,007,520,818✔
209
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
547,801,984✔
210
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
547,815,354✔
211
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
547,818,865✔
212
    }
213
  }
214

215
  // Decode tag references (backward compatible)
216
  pWrapper->nTagRefs = 0;
62,255,863✔
217
  pWrapper->pTagRef = NULL;
62,402,237✔
218
  if (!tDecodeIsEnd(pDecoder)) {
62,401,673✔
219
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
124,789,056✔
220
    if (pWrapper->nTagRefs > 0) {
62,386,260✔
UNCOV
221
      pWrapper->pTagRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nTagRefs * sizeof(SColRef));
×
UNCOV
222
      if (pWrapper->pTagRef == NULL) {
×
UNCOV
223
        return terrno;
×
224
      }
225

UNCOV
226
      for (int i = 0; i < pWrapper->nTagRefs; i++) {
×
UNCOV
227
        SColRef *p = &pWrapper->pTagRef[i];
×
UNCOV
228
        TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
×
UNCOV
229
        TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
×
UNCOV
230
        if (p->hasRef) {
×
UNCOV
231
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
×
UNCOV
232
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
×
UNCOV
233
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
×
234
        }
235
      }
236
    }
237
  }
238

239
  return 0;
62,372,812✔
240
}
241

242
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
243
                                                            SSchemaWrapper *pSchema) {
UNCOV
244
  pRef->nCols = pSchema->nCols;
×
UNCOV
245
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
UNCOV
246
    return terrno;
×
247
  }
248

UNCOV
249
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
UNCOV
250
    SColRef  *pColRef = &pRef->pColRef[i];
×
UNCOV
251
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
UNCOV
252
    pColRef->id = pColSchema->colId;
×
253
    pColRef->hasRef = false;
×
254
  }
UNCOV
255
  return 0;
×
256
}
257

258
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
1,256,714✔
259
  if (pSrc->nCols > 0) {
1,256,714✔
260
    pDst->nCols = pSrc->nCols;
1,256,714✔
261
    pDst->version = pSrc->version;
1,256,099✔
262
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,256,099✔
263
    if (NULL == pDst->pColRef) {
1,256,714✔
UNCOV
264
      return terrno;
×
265
    }
266
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,256,714✔
267
  }
268
  return 0;
1,256,099✔
269
}
270

271
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
48,068,361✔
272
  int32_t code = 0;
48,068,361✔
273
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
96,245,654✔
274
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
96,409,229✔
275
  uTrace("encode cols:%d", pw->nCols);
48,231,936✔
276

277
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
278
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
279
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
280
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
281
  }
282
  return code;
48,331,988✔
283
}
284
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
48,061,658✔
285
  const SColCmprWrapper *pw = &pME->colCmpr;
48,061,658✔
286
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
48,083,057✔
287
}
288
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,265,427,680✔
289
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,265,427,680✔
290
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
291
  if (pWrapper->nCols == 0) {
1,265,559,927✔
UNCOV
292
    return 0;
×
293
  }
294

295
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
2,147,483,647✔
296
  uDebug("dencode cols:%d", pWrapper->nCols);
1,265,221,125✔
297
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
298
  if (pWrapper->pColCmpr == NULL) {
1,265,248,281✔
299
    return terrno;
×
300
  }
301

302
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
303
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
304
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
305
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647✔
306
  }
307
  return 0;
1,266,992,859✔
308
}
309
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
310
                                                            SSchemaWrapper *pSchema) {
311
  pCmpr->nCols = pSchema->nCols;
240,780✔
312

313
  if (pDecoder == NULL) {
240,780✔
314
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
240,780✔
315
  } else {
UNCOV
316
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
317
  }
318

319
  if (pCmpr->pColCmpr == NULL) {
240,780✔
UNCOV
320
    return terrno;
×
321
  }
322

323
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,200,694✔
324
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
959,914✔
325
    SSchema  *pColSchema = &pSchema->pSchema[i];
959,914✔
326
    pColCmpr->id = pColSchema->colId;
959,914✔
327
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
959,914✔
328
  }
329
  return 0;
240,780✔
330
}
331

332
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
200,091,867✔
333
  if (pSrc->nCols > 0) {
200,091,867✔
334
    pDst->nCols = pSrc->nCols;
176,252,751✔
335
    pDst->version = pSrc->version;
176,261,472✔
336
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
176,207,422✔
337
    if (NULL == pDst->pColCmpr) {
176,221,255✔
UNCOV
338
      return terrno;
×
339
    }
340
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
176,235,483✔
341
  }
342
  return 0;
200,099,165✔
343
}
344

345
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
201,272,750✔
346
  if (pColRef) {
201,272,750✔
347
    taosMemoryFreeClear(pColRef->pColRef);
201,294,965✔
348
  }
349
}
201,308,514✔
350

351
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
201,303,660✔
352
  if (pCmpr) {
201,303,660✔
353
    taosMemoryFreeClear(pCmpr->pColCmpr);
201,322,497✔
354
  }
355
}
201,337,242✔
356

357
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
211,722,493✔
358
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
211,722,493✔
359
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
423,553,539✔
360
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
423,451,241✔
361
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
423,436,149✔
362

363
  if (pME->type > 0) {
211,739,343✔
364
    if (pME->name == NULL) {
206,281,962✔
UNCOV
365
      return TSDB_CODE_INVALID_PARA;
×
366
    }
367

368
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
412,606,262✔
369

370
    if (pME->type == TSDB_SUPER_TABLE) {
206,326,539✔
371
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
52,898,646✔
372
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
53,016,099✔
373
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
53,009,448✔
374
      if (TABLE_IS_ROLLUP(pME->flags)) {
26,440,348✔
375
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
114,222✔
376
      }
377
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
179,802,883✔
378
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
314,465,657✔
379
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
314,501,418✔
380
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
314,507,506✔
381
      if (pME->ctbEntry.commentLen > 0) {
157,250,696✔
382
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
29,548✔
383
      }
384
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
314,449,695✔
385
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
157,224,343✔
386
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
22,593,874✔
387
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
45,187,748✔
388
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
45,187,748✔
389
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
45,187,748✔
390
      if (pME->ntbEntry.commentLen > 0) {
22,593,874✔
391
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
18,780✔
392
      }
393
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
45,187,541✔
394
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
45,187,748✔
UNCOV
395
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
UNCOV
396
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
397
    } else {
UNCOV
398
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
UNCOV
399
      return TSDB_CODE_INVALID_PARA;
×
400
    }
401
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
206,227,127✔
402
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,036,517✔
403
    } else {
404
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
204,306,156✔
405
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
26,473,371✔
406
      } else if (pME->type == TSDB_NORMAL_TABLE) {
177,927,099✔
407
        if (pME->colCmpr.nCols != 0) {
21,807,709✔
408
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
21,567,136✔
409
        } else {
410
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
240,573✔
411
          SColCmprWrapper colCmprs = {0};
240,780✔
412
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
240,780✔
413
          if (code != 0) {
240,780✔
UNCOV
414
            taosMemoryFree(colCmprs.pColCmpr);
×
UNCOV
415
            TAOS_CHECK_RETURN(code);
×
416
          }
417
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
240,780✔
418
          taosMemoryFree(colCmprs.pColCmpr);
240,780✔
419
          TAOS_CHECK_RETURN(code);
240,780✔
420
        }
421
      }
422
    }
423
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
206,348,513✔
424
  }
425
  if (pME->type == TSDB_SUPER_TABLE) {
211,708,976✔
426
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
52,916,663✔
427
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
52,844,385✔
428
  } else if (pME->type == TSDB_NORMAL_TABLE) {
185,212,908✔
429
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
43,615,832✔
430
  }
431

432
  tEndEncode(pCoder);
211,658,761✔
433
  return 0;
211,555,608✔
434
}
435

436
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,136,561,383✔
437
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,136,561,383✔
438
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
439
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
440
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
441

442
  if (headerOnly) {
2,138,855,849✔
443
    tEndDecode(pCoder);
321,602✔
444
    return 0;
321,602✔
445
  }
446

447
  if (pME->type > 0) {
2,138,534,247✔
448
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
449

450
    if (pME->type == TSDB_SUPER_TABLE) {
2,137,832,510✔
451
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,920,597,879✔
452
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,921,537,017✔
453
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,921,025,646✔
454
      if (TABLE_IS_ROLLUP(pME->flags)) {
960,247,657✔
455
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
349,128✔
456
      }
457
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,176,277,068✔
458
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,722,435,413✔
459
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,722,980,890✔
460
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,722,328,375✔
461
      if (pME->ctbEntry.commentLen > 0) {
860,859,722✔
462
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
51,076✔
463
      }
464
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,722,201,447✔
465
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
861,456,707✔
466
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
315,786,781✔
467
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
632,189,841✔
468
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
632,449,611✔
469
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
632,109,838✔
470
      if (pME->ntbEntry.commentLen > 0) {
315,882,794✔
471
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
38,962✔
472
      }
473
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
631,826,964✔
474
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
632,224,383✔
475
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
476
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
UNCOV
477
      if (!pME->smaEntry.tsma) {
×
UNCOV
478
        return terrno;
×
479
      }
UNCOV
480
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
481
    } else {
UNCOV
482
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
UNCOV
483
      return TSDB_CODE_INVALID_PARA;
×
484
    }
485
    if (pME->type == TSDB_SUPER_TABLE) {
2,136,786,400✔
486
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
960,662,367✔
487
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
960,536,679✔
488

489
        if (pME->colCmpr.nCols == 0) {
960,816,959✔
UNCOV
490
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
491
        }
492
      } else {
UNCOV
493
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
UNCOV
494
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
495
      }
496
    } else if (pME->type == TSDB_NORMAL_TABLE) {
1,176,167,207✔
497
      if (!tDecodeIsEnd(pCoder)) {
305,798,995✔
498
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
305,851,898✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
305,852,332✔
500
        if (pME->colCmpr.nCols == 0) {
305,846,380✔
UNCOV
501
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
502
        }
503
      } else {
UNCOV
504
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
505
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
506
      }
507
      TABLE_SET_COL_COMPRESSED(pME->flags);
305,780,939✔
508
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
870,604,877✔
509
      if (!tDecodeIsEnd(pCoder)) {
62,397,182✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
62,395,077✔
511
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
62,395,818✔
512
      } else {
513
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
2,246✔
514
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,264✔
515
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
516
        }
517
      }
518
    }
519
    if (!tDecodeIsEnd(pCoder)) {
2,137,386,110✔
520
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,266,305,756✔
521
    } else {
522
      pME->pExtSchemas = NULL;
871,080,354✔
523
    }
524
  }
525
  if (pME->type == TSDB_SUPER_TABLE) {
2,136,092,440✔
526
    if (!tDecodeIsEnd(pCoder)) {
959,816,178✔
527
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,920,458,184✔
528
    }
529
    if (!tDecodeIsEnd(pCoder)) {
958,845,444✔
530
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,919,817,991✔
531
    }
532
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,175,791,825✔
533
    if (!tDecodeIsEnd(pCoder)) {
305,591,761✔
534
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
611,574,966✔
535
    }
536
  }
537

538

539
  tEndDecode(pCoder);
2,135,588,673✔
540
  return 0;
2,136,447,901✔
541
}
542

543
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,136,554,326✔
544

545
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
344,405,745✔
546
  if (pSrc == NULL || pDst == NULL) {
344,405,745✔
UNCOV
547
    return TSDB_CODE_INVALID_PARA;
×
548
  }
549

550
  pDst->nCols = pSrc->nCols;
344,468,047✔
551
  pDst->version = pSrc->version;
344,469,152✔
552
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
344,410,441✔
553
  if (pDst->pSchema == NULL) {
344,289,832✔
UNCOV
554
    return terrno;
×
555
  }
556
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
344,331,089✔
557
  return TSDB_CODE_SUCCESS;
344,497,585✔
558
}
559

560
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
77,094✔
561
  if (pSrc == NULL || pDst == NULL) {
77,094✔
UNCOV
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
77,094✔
565
  pDst->name = tstrdup(pSrc->name);
77,094✔
566
  if (pDst->name == NULL) {
77,094✔
UNCOV
567
    return terrno;
×
568
  }
569
  if (pSrc->nFuncs > 0) {
77,094✔
570
    pDst->nFuncs = pSrc->nFuncs;
77,094✔
571
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
77,094✔
572
    if (pDst->funcColIds == NULL) {
77,094✔
UNCOV
573
      return terrno;
×
574
    }
575
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
77,094✔
576

577
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
77,094✔
578
    if (pDst->funcIds == NULL) {
77,094✔
579
      return terrno;
×
580
    }
581
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
77,094✔
582
  } else {
UNCOV
583
    pDst->nFuncs = 0;
×
UNCOV
584
    pDst->funcColIds = NULL;
×
UNCOV
585
    pDst->funcIds = NULL;
×
586
  }
587

588
  return TSDB_CODE_SUCCESS;
77,094✔
589
}
590

591
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
344,394,788✔
592
  if (pSchema) {
344,394,788✔
593
    taosMemoryFreeClear(pSchema->pSchema);
344,413,927✔
594
  }
595
}
344,452,430✔
596

597
/**
598
 * @param type 0x01 free name
599
 */
600
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
117,546✔
601
  if (pParam) {
117,546✔
602
    if ((type & 0x01)) {
117,546✔
603
      taosMemoryFreeClear(pParam->name);
117,546✔
604
    }
605
    taosMemoryFreeClear(pParam->funcColIds);
116,784✔
606
    taosMemoryFreeClear(pParam->funcIds);
117,546✔
607
  }
608
}
117,546✔
609

610
void metaCloneEntryFree(SMetaEntry **ppEntry) {
201,414,170✔
611
  if (ppEntry == NULL || *ppEntry == NULL) {
201,414,170✔
612
    return;
78,364✔
613
  }
614

615
  taosMemoryFreeClear((*ppEntry)->name);
201,351,592✔
616

617
  if ((*ppEntry)->type < 0) {
201,368,099✔
UNCOV
618
    taosMemoryFreeClear(*ppEntry);
×
UNCOV
619
    return;
×
620
  }
621

622
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
201,283,873✔
623
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
167,708,417✔
624
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
167,704,834✔
625
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
167,719,705✔
626
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
117,546✔
627
    }
628
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
33,616,421✔
629
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
24,632,142✔
630
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
24,631,965✔
631
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,987,397✔
632
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,987,397✔
633
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,987,397✔
634
  } else {
UNCOV
635
    return;
×
636
  }
637
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
201,347,805✔
638
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
201,320,914✔
639
  metaCloneColRefFree(&(*ppEntry)->colRef);
201,324,225✔
640

641
  taosMemoryFreeClear(*ppEntry);
201,252,280✔
642
  return;
201,302,826✔
643
}
644

645
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
201,309,760✔
646
  int32_t code = TSDB_CODE_SUCCESS;
201,309,760✔
647

648
  if (NULL == pEntry || NULL == ppEntry) {
201,309,760✔
UNCOV
649
    return TSDB_CODE_INVALID_PARA;
×
650
  }
651

652
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
201,368,338✔
653
  if (NULL == *ppEntry) {
201,249,459✔
UNCOV
654
    return terrno;
×
655
  }
656

657
  (*ppEntry)->version = pEntry->version;
201,289,125✔
658
  (*ppEntry)->type = pEntry->type;
201,311,167✔
659
  (*ppEntry)->uid = pEntry->uid;
201,297,102✔
660

661
  if (pEntry->type < 0) {
201,327,827✔
UNCOV
662
    return TSDB_CODE_SUCCESS;
×
663
  }
664

665
  if (pEntry->name) {
201,319,350✔
666
    (*ppEntry)->name = tstrdup(pEntry->name);
201,320,452✔
667
    if (NULL == (*ppEntry)->name) {
201,348,695✔
668
      code = terrno;
×
669
      metaCloneEntryFree(ppEntry);
×
670
      return code;
×
671
    }
672
  }
673

674
  if (pEntry->type == TSDB_SUPER_TABLE) {
201,343,965✔
675
    (*ppEntry)->flags = pEntry->flags;
167,695,778✔
676

677
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
167,664,285✔
678
    if (code) {
167,745,570✔
679
      metaCloneEntryFree(ppEntry);
×
680
      return code;
×
681
    }
682

683
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
167,745,570✔
684
    if (code) {
167,777,506✔
UNCOV
685
      metaCloneEntryFree(ppEntry);
×
UNCOV
686
      return code;
×
687
    }
688
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
167,777,506✔
689
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
77,094✔
690
      if (code) {
77,094✔
UNCOV
691
        metaCloneEntryFree(ppEntry);
×
UNCOV
692
        return code;
×
693
      }
694
    }
695
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
167,773,710✔
696
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
167,745,465✔
697
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
33,625,268✔
698
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
24,635,576✔
699
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
24,638,322✔
700
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
24,639,178✔
701

702
    // comment
703
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
24,638,937✔
704
    if (pEntry->ctbEntry.commentLen > 0) {
24,637,943✔
705
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
8,729✔
706
      if (NULL == (*ppEntry)->ctbEntry.comment) {
8,729✔
UNCOV
707
        code = terrno;
×
UNCOV
708
        metaCloneEntryFree(ppEntry);
×
709
        return code;
×
710
      }
711
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
8,729✔
712
    }
713

714
    // tags
715
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
24,638,624✔
716
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
24,634,103✔
717
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
24,639,350✔
UNCOV
718
      code = terrno;
×
UNCOV
719
      metaCloneEntryFree(ppEntry);
×
UNCOV
720
      return code;
×
721
    }
722
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
24,638,250✔
723
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,987,397✔
724
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,987,397✔
725
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,987,397✔
726
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,987,397✔
727
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
8,987,397✔
728

729
    // schema
730
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
8,987,397✔
731
    if (code) {
8,987,397✔
UNCOV
732
      metaCloneEntryFree(ppEntry);
×
UNCOV
733
      return code;
×
734
    }
735

736
    // comment
737
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,987,397✔
738
    if (pEntry->ntbEntry.commentLen > 0) {
8,987,397✔
739
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
6,037✔
740
      if (NULL == (*ppEntry)->ntbEntry.comment) {
6,037✔
UNCOV
741
        code = terrno;
×
UNCOV
742
        metaCloneEntryFree(ppEntry);
×
UNCOV
743
        return code;
×
744
      }
745
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
6,037✔
746
    }
747
  } else {
UNCOV
748
    return TSDB_CODE_INVALID_PARA;
×
749
  }
750

751
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
201,388,840✔
752
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,310,014✔
753
    if (code) {
1,256,099✔
UNCOV
754
      metaCloneEntryFree(ppEntry);
×
UNCOV
755
      return code;
×
756
    }
757
  } else {
758
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
200,083,771✔
759
    if (code) {
200,081,157✔
UNCOV
760
      metaCloneEntryFree(ppEntry);
×
UNCOV
761
      return code;
×
762
    }
763
  }
764
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
201,337,274✔
765
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
10,215,058✔
766
    if (!(*ppEntry)->pExtSchemas) {
10,209,966✔
UNCOV
767
      code = terrno;
×
UNCOV
768
      metaCloneEntryFree(ppEntry);
×
UNCOV
769
      return code;
×
770
    }
771
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
10,212,846✔
772
  }
773

774
  return code;
201,327,941✔
775
}
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